:root {
  color-scheme: light;
  --ink: #18201b;
  --muted: #68716b;
  --paper: #f4f3ed;
  --surface: #ffffff;
  --line: #d8dcd7;
  --green: #173d2a;
  --green-2: #285c3f;
  --green-soft: #e4eee7;
  --red: #a53e34;
  --red-soft: #f6e8e5;
  --gold: #cf9a35;
  --shadow: 0 18px 55px rgba(24, 32, 27, 0.12);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--paper); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(rgba(23, 61, 42, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 61, 42, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 24px 24px;
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  letter-spacing: 0;
}

button, input, select { font: inherit; letter-spacing: 0; }
button, select { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.58; }

.app-shell {
  width: min(100% - 32px, 560px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 0 max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.brand-header.centered { justify-content: center; text-align: left; }

.brand-mark {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--red);
  border-radius: 4px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.35);
  font-family: SimSun, serif;
  font-size: 25px;
  font-weight: 700;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 28px; line-height: 1.2; }
h2 { margin-bottom: 18px; font-size: 21px; line-height: 1.35; }

.draw-stage,
.login-box,
.qr-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.draw-stage {
  min-height: 540px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.remaining-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 14px;
}
.remaining-line strong { color: var(--green); font-size: 22px; }

.progress-track { height: 6px; margin-bottom: 42px; overflow: hidden; background: #e8ebe8; border-radius: 99px; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--green-2); transition: width .35s ease; }
.progress-track span[data-drawn="1"] { width: 16.6667%; }
.progress-track span[data-drawn="2"] { width: 33.3333%; }
.progress-track span[data-drawn="3"] { width: 50%; }
.progress-track span[data-drawn="4"] { width: 66.6667%; }
.progress-track span[data-drawn="5"] { width: 83.3333%; }
.progress-track span[data-drawn="6"] { width: 100%; }

label { display: block; margin: 0 0 8px; font-size: 14px; font-weight: 700; }
input, .url-select {
  width: 100%;
  min-height: 50px;
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #bfc6c0;
  border-radius: 6px;
  outline: none;
}
input:focus, .url-select:focus { border-color: var(--green-2); box-shadow: 0 0 0 3px rgba(40, 92, 63, .16); }

.primary-button,
.secondary-button,
.danger-button,
.text-button,
.icon-button {
  min-height: 48px;
  border-radius: 6px;
  border: 0;
  font-weight: 700;
}
.primary-button { width: 100%; margin-top: 18px; color: #fff; background: var(--green); }
.primary-button:hover { background: #102e1f; }
.secondary-button { padding: 0 18px; color: var(--green); background: var(--green-soft); }
.secondary-button:hover { background: #d6e6db; }
.danger-button { padding: 0 18px; color: var(--red); background: var(--red-soft); }
.danger-button:hover { background: #efd6d1; }
.text-button { min-height: 40px; padding: 0 8px; color: var(--green); background: transparent; }
.icon-button { width: 44px; padding: 0; color: var(--muted); background: transparent; font-size: 28px; }
.compact { min-height: 40px; white-space: nowrap; }
.button-link { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

.form-message { margin: 10px 0 0; font-size: 14px; }
.error { color: var(--red); }
.field-hint { margin: -2px 0 12px; color: var(--muted); font-size: 13px; }

.drawing-panel, .result-panel, .complete-panel { text-align: center; }
.drawing-panel p, .result-label { margin-bottom: 12px; color: var(--muted); }
.rolling-number, .result-number {
  width: min(220px, 65vw);
  aspect-ratio: 1;
  margin: 0 auto;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 118px;
  line-height: 1;
  font-weight: 700;
}
.rolling-number { color: var(--green); background: var(--green-soft); }
.result-number { color: #fff; background: var(--red); box-shadow: 10px 10px 0 var(--gold); }
.result-name { margin-bottom: 8px; font-size: 22px; font-weight: 700; }
.result-note { margin: 28px 0 0; color: var(--muted); font-size: 14px; }

.complete-kicker { margin-bottom: 6px; color: var(--red); font-weight: 700; }
.final-order { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); text-align: left; }
.final-order li { min-height: 52px; display: flex; align-items: center; gap: 14px; border-bottom: 1px solid var(--line); }
.final-order span { width: 32px; color: var(--red); font-family: Georgia, serif; font-size: 24px; font-weight: 700; text-align: center; }
.final-order strong { font-size: 17px; }

.app-shell footer { margin-top: auto; padding-top: 18px; color: var(--muted); font-size: 12px; text-align: center; }

.card-shell { width: min(100% - 32px, 620px); min-height: 100vh; margin: 0 auto; padding: 26px 0; display: grid; place-items: center; }
.qr-card { width: 100%; padding: 30px; text-align: center; }
.qr-frame { position: relative; width: min(360px, 78vw); aspect-ratio: 1; margin: 18px auto; background: #fff; }
.qr-frame img { display: block; width: 100%; height: 100%; object-fit: contain; }
.qr-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); background: #fff; }
.scan-caption { margin-bottom: 18px; font-size: 18px; font-weight: 700; }
.url-label { color: var(--muted); font-size: 12px; text-align: left; }
.card-actions { margin-top: 18px; display: flex; justify-content: center; }

.admin-shell { width: min(100% - 36px, 1040px); margin: 0 auto; padding: 30px 0 70px; }
.login-view { min-height: calc(100vh - 100px); display: grid; place-items: center; }
.login-box { width: min(100%, 420px); padding: 30px; }
.login-box .brand-mark { margin-bottom: 20px; }
.login-box h1 { margin-bottom: 26px; }

.admin-header, .section-heading, .danger-section, .admin-actions, .admin-qr-layout {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.admin-header { margin-bottom: 28px; }
.status-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--green);
  color: #fff;
  border-radius: 8px;
  overflow: hidden;
}
.status-strip div { min-height: 112px; padding: 22px; display: flex; flex-direction: column; justify-content: space-between; border-right: 1px solid rgba(255,255,255,.2); }
.status-strip div:last-child { border-right: 0; }
.status-strip span { color: rgba(255,255,255,.72); font-size: 13px; }
.status-strip strong { font-size: 32px; }

.admin-section { padding: 34px 0; border-bottom: 1px solid var(--line); }
.admin-section h2 { margin-bottom: 0; }
.section-heading { margin-bottom: 20px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: rgba(255,255,255,.58); }
th, td { padding: 15px 12px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-size: 13px; }
td { font-size: 15px; }
.position-cell { color: var(--red); font-family: Georgia, serif; font-size: 23px; font-weight: 700; }
.status-pill { display: inline-block; padding: 5px 9px; border-radius: 99px; color: var(--green); background: var(--green-soft); font-size: 12px; font-weight: 700; }
.status-pill.pending { color: var(--muted); background: #e8e9e6; }

.admin-qr-layout { justify-content: flex-start; }
.admin-qr { width: 180px; height: 180px; padding: 8px; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
.network-address { flex: 1; max-width: 520px; }
.network-address p { margin: 10px 0 0; color: var(--muted); font-size: 13px; }
.danger-section { align-items: flex-end; border-bottom: 0; }
.admin-actions { flex-wrap: wrap; justify-content: flex-end; }

dialog { width: min(100% - 32px, 460px); padding: 26px; color: var(--ink); background: #fff; border: 0; border-radius: 8px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(12, 20, 15, .55); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.dialog-heading h2 { margin: 0; }
dialog label:not(:first-of-type) { margin-top: 16px; }

[hidden] { display: none !important; }

@media (max-width: 680px) {
  .app-shell { width: min(100% - 24px, 560px); padding-top: 18px; }
  .draw-stage { min-height: 510px; padding: 20px; }
  .progress-track { margin-bottom: 32px; }
  .rolling-number, .result-number { font-size: 96px; }
  .qr-card { padding: 22px; }
  .admin-shell { width: min(100% - 24px, 1040px); padding-top: 20px; }
  .status-strip div { min-height: 92px; padding: 16px; }
  .status-strip strong { font-size: 25px; }
  .section-heading, .danger-section, .admin-qr-layout { align-items: stretch; flex-direction: column; }
  .section-heading .compact { align-self: flex-start; }
  .admin-qr { width: min(240px, 75vw); height: auto; align-self: center; }
  .admin-actions { width: 100%; justify-content: stretch; }
  .admin-actions button { flex: 1 1 180px; }
  th, td { padding: 12px 9px; white-space: nowrap; }
}

@media print {
  body { background: #fff; }
  .card-shell { width: 100%; min-height: auto; padding: 0; }
  .qr-card { border: 0; box-shadow: none; }
  .no-print { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
