:root {
  color-scheme: dark;
  --bg: #0d100f;
  --surface: #121715;
  --surface-strong: #171d1a;
  --bar: #101411;
  --line: #2a322e;
  --line-soft: #202723;
  --text: #f2f5f3;
  --muted: #8d9892;
  --green: #49d39a;
  --green-strong: #2ba873;
  --yellow: #e8bc48;
  --red: #df706e;
  --focus: #67e5af;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-width: 320px; background: var(--bg); }
body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input { font: inherit; letter-spacing: 0; }
button { color: inherit; }

.workspace {
  width: min(980px, calc(100% - 40px));
  margin: 0 auto;
  padding: 34px 0 56px;
}

.topbar {
  min-height: 70px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.eyebrow,
.section-index,
.mode-label,
.run-copy span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3,
p { margin: 0; }
h1 { margin-top: 6px; font-size: 22px; line-height: 1.25; }
h2 { margin-top: 4px; font-size: 17px; line-height: 1.3; }
h3 { margin-top: 7px; font-size: 18px; line-height: 1.35; }

.top-state,
.section-state {
  flex: 0 0 auto;
  color: var(--yellow);
  font-size: 12px;
  font-weight: 700;
}
.top-state { margin-top: 8px; }
.top-state[data-tone="ok"],
.section-state[data-tone="ok"] { color: var(--green); }
.top-state[data-tone="error"],
.section-state[data-tone="error"] { color: var(--red); }

.section {
  padding: 30px 0;
  border-bottom: 1px solid var(--line);
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.section-index { color: var(--green); }

.access-form { width: min(100%, 600px); margin-top: 22px; }
.access-form > label,
.code-form label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

input {
  width: 100%;
  min-width: 0;
  height: 44px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 4px;
  outline: none;
  background: var(--surface);
  color: var(--text);
}
input:focus { border-color: var(--focus); box-shadow: 0 0 0 2px #49d39a20; }
input:disabled { color: var(--muted); background: var(--bar); }

button {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  font-weight: 700;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button:disabled { opacity: .42; cursor: default; }
.primary { border-color: var(--green-strong); background: var(--green-strong); color: #07130e; }
.primary:hover:not(:disabled) { border-color: var(--green); background: var(--green); }
.secondary { border-color: var(--green-strong); color: var(--green); }
.danger { color: var(--red); }
.ghost { color: var(--muted); }

.field-message {
  min-height: 18px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.field-message[data-tone="error"] { color: var(--red); }
.field-message[data-tone="ok"] { color: var(--green); }

.segmented {
  width: min(100%, 420px);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 22px;
  border: 1px solid var(--line);
}
.segmented button { border: 0; border-radius: 0; color: var(--muted); }
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button[aria-pressed="true"] { background: var(--surface-strong); color: var(--green); }

.login-stage {
  min-height: 250px;
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 34px;
  align-items: center;
  margin-top: 24px;
  padding: 24px 0;
  border-top: 1px solid var(--line-soft);
}

.qr-frame {
  width: 210px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: #f5f7f5;
}
.qr-frame img { width: 100%; height: 100%; object-fit: contain; }
.qr-placeholder { color: #435049; text-align: center; }
.qr-placeholder span {
  width: 38px;
  height: 38px;
  display: block;
  margin: 0 auto 12px;
  border: 3px solid #bec7c1;
  border-top-color: #3f8f6a;
  border-radius: 50%;
}
.qr-placeholder[data-loading="true"] span { animation: spin 1s linear infinite; }
.qr-placeholder strong { font-size: 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

.login-copy { min-width: 0; }
.mode-label { color: var(--green); }
.login-copy > p {
  min-height: 44px;
  margin: 10px 0 16px;
  color: var(--muted);
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.account-identity {
  margin: 10px 0 14px;
  padding: 10px 0;
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.account-identity span,
.account-identity strong {
  display: block;
}

.account-identity strong {
  margin-top: 3px;
  color: var(--text);
  font-size: 14px;
  overflow-wrap: anywhere;
}
.code-form {
  width: min(100%, 430px);
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line-soft);
}

.board-list { margin-top: 22px; border-top: 1px solid var(--line); }
.board-row {
  min-height: 70px;
  display: grid;
  grid-template-columns: 20px 22px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
}
.board-row:hover { background: var(--surface); }
.board-row[data-disabled="true"] { opacity: .48; cursor: default; }
.board-row input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.check-mark {
  grid-column: 1 / 3;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border: 1px solid #59645e;
  border-radius: 2px;
}
.board-row input:checked + .check-mark { border-color: var(--green-strong); background: var(--green-strong); }
.board-row input:checked + .check-mark::after {
  content: "";
  width: 8px;
  height: 4px;
  border-left: 2px solid #07130e;
  border-bottom: 2px solid #07130e;
  transform: translateY(-1px) rotate(-45deg);
}
.board-row input:focus-visible + .check-mark { outline: 2px solid var(--focus); outline-offset: 2px; }
.board-copy { grid-column: 3; min-width: 0; }
.board-copy strong,
.board-copy small { display: block; overflow-wrap: anywhere; }
.board-copy strong { font-size: 14px; }
.board-copy small { margin-top: 5px; color: var(--muted); font-size: 11px; }
.board-row em { grid-column: 4; color: var(--muted); font-size: 12px; font-style: normal; font-weight: 700; }
.board-row[data-state="done"] em { color: var(--green); }
.board-row[data-state="running"] em { color: var(--yellow); }
.board-row[data-state="error"] em { color: var(--red); }

.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-top: 20px;
}
.run-copy { min-width: 180px; }
.run-copy strong { display: block; margin-top: 6px; line-height: 1.5; overflow-wrap: anywhere; }
.action-buttons { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; }

.result-summary {
  min-height: 74px;
  margin-top: 20px;
  padding: 18px 0;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  line-height: 1.7;
  overflow-wrap: anywhere;
}
.result-summary[data-tone="ok"] { color: var(--text); }
.result-summary[data-tone="error"] { color: var(--red); }

@media (max-width: 700px) {
  .workspace { width: min(100% - 28px, 980px); padding-top: 22px; }
  .topbar { min-height: 62px; gap: 14px; }
  h1 { font-size: 19px; }
  .section { padding: 24px 0; }
  .login-stage { grid-template-columns: 1fr; gap: 22px; }
  .qr-frame { width: min(210px, 70vw); justify-self: center; }
  .login-copy { text-align: center; }
  .login-copy > p { min-height: 0; }
  .code-form { margin-right: auto; margin-left: auto; text-align: left; }
  .action-bar { align-items: stretch; flex-direction: column; }
  .action-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .action-buttons .primary { grid-column: 1 / -1; }
}

@media (max-width: 430px) {
  .inline-form { grid-template-columns: 1fr; }
  .inline-form button { width: 100%; }
  .board-row { grid-template-columns: 20px minmax(0, 1fr) auto; gap: 10px; padding-right: 4px; padding-left: 4px; }
  .check-mark { grid-column: 1; }
  .board-copy { grid-column: 2; }
  .board-row em { grid-column: 3; font-size: 11px; }
  .action-buttons { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .qr-placeholder[data-loading="true"] span { animation: none; }
}

#lottery-rewards { margin-top: 12px; min-width: 0; overflow-wrap: anywhere; }
#lottery-rewards ul { margin: 8px 0 0; padding-left: 20px; }
#lottery-rewards li { padding: 3px 0; }
