:root {
  --ink: #191814;
  --muted: #706d62;
  --paper: rgba(255, 255, 255, 0.9);
  --line: rgba(31, 28, 18, 0.1);
  --yellow: #ffd100;
  --yellow-deep: #dba800;
  --green: #18865a;
  --red: #c8443e;
  --shadow: 0 18px 60px rgba(63, 50, 0, 0.1);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f7f4e9;
  overflow-x: hidden;
}

button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid rgba(219, 168, 0, 0.35);
  outline-offset: 3px;
}

.ambient {
  position: fixed;
  z-index: -1;
  border-radius: 999px;
  pointer-events: none;
}

.ambient-one {
  width: 460px;
  height: 460px;
  top: -250px;
  right: -90px;
  background: radial-gradient(circle, rgba(255, 209, 0, 0.7), rgba(255, 209, 0, 0));
}

.ambient-two {
  width: 420px;
  height: 420px;
  bottom: -270px;
  left: -140px;
  background: radial-gradient(circle, rgba(76, 184, 135, 0.2), rgba(76, 184, 135, 0));
}

.shell {
  width: min(1180px, calc(100% - 32px));
  min-height: 100dvh;
  margin: 0 auto;
  padding: 16px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 58px;
  margin-bottom: 14px;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border-radius: 15px;
  background: var(--yellow);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.06), 0 10px 24px rgba(194, 151, 0, 0.2);
  font-size: 23px;
  font-weight: 900;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 3px; font-size: 21px; line-height: 1.15; letter-spacing: -0.025em; }
h2 { margin-bottom: 6px; font-size: 19px; line-height: 1.2; letter-spacing: -0.02em; }
.brand p { margin: 0; color: var(--muted); font-size: 12px; }

.session-actions { display: flex; align-items: center; gap: 8px; }
.info-chip {
  display: flex;
  align-items: baseline;
  gap: 7px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 11px;
  background: rgba(255, 255, 255, 0.65);
  color: var(--muted);
  font-size: 11px;
}
.info-chip strong { color: var(--ink); font-size: 13px; }

.panel {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--paper);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.eyebrow {
  margin: 0 0 5px;
  color: #8a6e00;
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.14em;
}

.button, .text-button, .claim-button {
  border: 0;
  cursor: pointer;
}
.button { min-height: 42px; border-radius: 13px; padding: 0 17px; font-weight: 800; }
.button-dark { background: var(--ink); color: #fff; }
.button-quiet { border: 1px solid var(--line); background: #fff; color: var(--red); }
.full-button { width: 100%; }
.button:disabled, .claim-button:disabled, .text-button:disabled { cursor: wait; opacity: 0.58; }
.text-button { border-radius: 8px; padding: 7px 8px; background: transparent; color: #765e00; font-size: 12px; font-weight: 800; }
.text-button:hover { background: rgba(255, 209, 0, 0.14); }

.login-panel {
  width: min(500px, 100%);
  margin: clamp(70px, 14vh, 145px) auto 0;
  padding: 30px;
}
.login-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin-bottom: 20px;
  border-radius: 15px;
  background: #fff5bd;
  font-weight: 900;
}
.login-panel > p:not(.eyebrow) { margin-bottom: 22px; color: var(--muted); line-height: 1.6; font-size: 14px; }
.login-form label { display: block; margin-bottom: 7px; font-size: 12px; font-weight: 800; }
.field-row { display: flex; gap: 9px; }
input {
  min-width: 0;
  flex: 1;
  border: 1px solid rgba(0, 0, 0, 0.13);
  border-radius: 13px;
  padding: 11px 13px;
  background: #fff;
  color: var(--ink);
  outline: none;
}
input:focus { border-color: var(--yellow-deep); box-shadow: 0 0 0 3px rgba(255, 209, 0, 0.16); }
.message { min-height: 20px; margin: 9px 0 0; color: var(--red); font-size: 12px; }

.dashboard { height: calc(100dvh - 104px); min-height: 560px; }
.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 0.78fr) minmax(480px, 1.4fr);
  gap: 14px;
  height: 100%;
  min-height: 0;
}
.control-column {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 14px;
  min-height: 0;
}
.connection-card, .claim-card, .result-panel { padding: 20px; }
.connection-card { min-height: 0; overflow: auto; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.compact-heading { margin-bottom: 14px; }
.status-badge, .count-badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 6px 10px;
  background: #f0ede2;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}
.status-badge.connected { background: #e7f6ee; color: var(--green); }

.connected-summary {
  min-height: 210px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-content: center;
  align-items: center;
  gap: 12px;
  border: 1px solid rgba(24, 134, 90, 0.16);
  border-radius: 18px;
  padding: 22px;
  background: #f0faf5;
}
.connected-summary p { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.connected-summary .button { grid-column: 1 / -1; margin-top: 6px; }
.success-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: 22px;
  font-weight: 900;
}

.login-flow { display: grid; gap: 12px; }
.qr-stage {
  display: grid;
  grid-template-columns: 150px 1fr;
  align-items: center;
  gap: 15px;
  min-height: 172px;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px;
  background: #fff;
}
.qr-visual {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 12px;
  background: #f5f2e7;
}
.qr-visual canvas { display: block; width: 100%; height: 100%; padding: 5px; background: #fff; }
.qr-placeholder { display: grid; place-items: center; color: #9b978a; font-size: 13px; font-weight: 800; }
.state-spinner {
  display: none;
  width: 30px;
  height: 30px;
  margin-bottom: 9px;
  border: 3px solid rgba(25, 24, 20, 0.12);
  border-top-color: var(--yellow-deep);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.qr-stage[data-state="generating"] .state-spinner,
.qr-stage[data-state="finalizing"] .state-spinner { display: block; }
.qr-stage[data-state="generating"] .placeholder-mark,
.qr-stage[data-state="finalizing"] .placeholder-mark { display: none; }
.qr-stage[data-state="expired"] canvas, .qr-stage[data-state="error"] canvas { opacity: 0.3; filter: grayscale(1); }
.qr-copy strong { display: block; margin-bottom: 7px; font-size: 15px; }
.qr-copy p { margin-bottom: 9px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.qr-copy p.busy::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 7px;
  border: 2px solid rgba(219, 168, 0, 0.22);
  border-top-color: var(--yellow-deep);
  border-radius: 50%;
  vertical-align: -1px;
  animation: spin 0.8s linear infinite;
}
.login-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: 11px;
  padding: 8px 13px;
  background: var(--yellow);
  color: var(--ink);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.06);
  font-size: 12px;
  font-weight: 850;
  text-decoration: none;
}
.login-link:hover { background: #f5c900; text-decoration: none; }

.claim-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.claim-card p:last-child { max-width: 215px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.claim-button {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 168px;
  border-radius: 16px;
  padding: 12px 14px;
  background: var(--ink);
  color: #fff;
  text-align: left;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.16);
}
.claim-button:not(:disabled):hover { transform: translateY(-1px); }
.claim-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: 11px;
  background: var(--yellow);
  color: var(--ink);
  font-size: 19px;
  font-weight: 900;
}
.claim-icon.loading { animation: pulse 0.9s ease-in-out infinite alternate; }
.claim-button strong, .claim-button small { display: block; }
.claim-button strong { font-size: 14px; }
.claim-button small { margin-top: 2px; color: rgba(255, 255, 255, 0.62); font-size: 10px; }

.result-panel { display: flex; min-height: 0; flex-direction: column; overflow: hidden; }
.result-heading { flex: 0 0 auto; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.result-actions { display: flex; align-items: center; gap: 5px; }
.count-badge { background: #fff4aa; color: #755d00; }
.empty-result {
  display: grid;
  place-items: center;
  align-content: center;
  flex: 1;
  min-height: 240px;
  color: var(--muted);
  text-align: center;
}
.empty-result strong { color: var(--ink); font-size: 15px; }
.empty-result p { max-width: 320px; margin: 7px 0 0; font-size: 12px; line-height: 1.5; }
.empty-icon {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  margin-bottom: 13px;
  border-radius: 16px;
  background: #f3efe0;
  color: #8b710d;
  font-weight: 900;
}
.result-content { display: flex; min-height: 0; flex: 1; flex-direction: column; }
.result-banner {
  flex: 0 0 auto;
  margin-top: 14px;
  border-radius: 14px;
  padding: 12px 14px;
  background: #eaf8f1;
  color: #176f4b;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.45;
}
.result-banner.error { background: #fff0ef; color: #a23832; }
.result-meta { flex: 0 0 auto; margin: 10px 2px 7px; color: var(--muted); font-size: 11px; }
.coupon-list {
  min-height: 0;
  margin: 0;
  padding: 0 3px 0 0;
  overflow-y: auto;
  list-style: none;
}
.coupon-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px 13px;
  background: rgba(255, 255, 255, 0.72);
}
.coupon-main { min-width: 0; }
.coupon-name { display: block; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.coupon-discount { display: block; margin-top: 4px; color: #8a6b00; font-size: 11px; font-weight: 800; }
.coupon-period { color: var(--muted); font-size: 11px; text-align: right; white-space: nowrap; }
.no-coupons { margin: 8px 0 0; border: 1px dashed var(--line); border-radius: 14px; padding: 18px; color: var(--muted); font-size: 12px; text-align: center; }

.toast {
  position: fixed;
  z-index: 10;
  right: 20px;
  bottom: 20px;
  max-width: min(400px, calc(100% - 40px));
  transform: translateY(90px);
  opacity: 0;
  border-radius: 13px;
  padding: 12px 15px;
  background: var(--ink);
  color: #fff;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.24);
  font-size: 12px;
  transition: transform 0.22s ease, opacity 0.22s ease;
}
.toast.visible { transform: translateY(0); opacity: 1; }

[hidden] { display: none !important; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { to { transform: scale(0.9); opacity: 0.65; } }

@media (min-width: 821px) {
  body { overflow: hidden; }
}

@media (max-width: 820px) {
  .shell { width: min(680px, calc(100% - 24px)); padding: 12px 0 24px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .session-actions { width: 100%; flex-wrap: wrap; }
  .info-chip { flex: 1; }
  .dashboard { height: auto; min-height: 0; }
  .workspace { grid-template-columns: 1fr; height: auto; }
  .control-column { grid-template-rows: auto; }
  .connection-card { overflow: visible; }
  .result-panel { min-height: 460px; overflow: visible; }
  .coupon-list { overflow: visible; }
}

@media (max-width: 520px) {
  .login-panel, .connection-card, .claim-card, .result-panel { padding: 17px; }
  .field-row, .claim-card { align-items: stretch; flex-direction: column; }
  .field-row .button, .claim-button { width: 100%; }
  .qr-stage { grid-template-columns: 1fr; }
  .qr-visual { width: min(220px, 100%); justify-self: center; }
  .login-link { width: 100%; min-height: 44px; }
  .coupon-item { grid-template-columns: 1fr; gap: 7px; }
  .coupon-period { text-align: left; white-space: normal; }
  .session-actions .text-button { margin-left: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
