:root {
  color-scheme: light;
  --ink: #1c1915;
  --paper: #f3eee6;
  --card: #fffcf8;
  --line: #e3d9cc;
  --muted: #6e655c;
  --accent: #c4472a;
  --accent-ink: #fff8f4;
  --good: #1f6b43;
  --good-bg: #e5f4eb;
  --warn: #8a5a12;
  --warn-bg: #f8efd8;
  --bad: #8d2f2f;
  --bad-bg: #f8e4e1;
  --shadow: 0 16px 40px rgba(40, 28, 16, 0.08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
html { overflow-x: clip; }
body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 0 0, rgba(196, 71, 42, 0.08), transparent 32%),
    var(--paper);
  color: var(--ink);
  font-family: "Noto Sans CJK SC", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.55;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: 0.02em; }
h2 { font-size: 18px; }
h3 { font-size: 18px; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login-card, .card, dialog form {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 8px;
  padding: 28px 24px 24px;
}
.login-card h1 { font-size: 28px; }
.mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
.sub, .hint, .empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}
label { display: grid; gap: 6px; font-size: 13px; font-weight: 700; }
input, select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 8px 10px;
  border: 1px solid #ddd2c4;
  border-radius: 10px;
  background: #fff;
  font-size: 16px;
}
textarea { min-height: 120px; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: 0.04em; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(196, 71, 42, 0.35);
  border-color: var(--accent);
}
button {
  min-height: 48px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  touch-action: manipulation;
}
button:hover { filter: brightness(0.96); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
button:disabled { opacity: 0.55; cursor: wait; }
button.ghost, a.text-link {
  background: transparent;
  color: var(--ink);
  border: 1px solid #d9cec0;
}
a.text-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
}
.error {
  margin: 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bad-bg);
  color: var(--bad);
  font-size: 14px;
}

.top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: var(--ink);
  color: #f6f1e8;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand strong { display: block; font-size: 16px; }
.brand small { display: block; color: #cfc4b6; font-size: 12px; }
.tabs { display: flex; gap: 6px; margin-left: auto; }
.tab {
  min-height: 36px;
  background: transparent;
  color: #f6f1e8;
  border: 1px solid transparent;
}
.tab.is-on { background: #f6f1e8; color: var(--ink); }
#logout { background: transparent; color: #f6f1e8; border: 1px solid #5c534b; }

main { width: min(1180px, calc(100% - 28px)); margin: 18px auto 40px; }
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.stats article {
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.stats b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stats span { color: var(--muted); font-size: 12px; }

.panel { display: block; }
.split {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}
.card { padding: 16px; }
.card-head, .row, .pager, .filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.card-head { justify-content: space-between; margin-bottom: 10px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.grid .wide { grid-column: 1 / -1; }
.output { margin-top: 12px; display: grid; gap: 8px; }
.filters { margin-bottom: 10px; }
.filters input, .filters select { min-width: 0; flex: 1 1 140px; }
.filters button { flex: none; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 8px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 12px; font-weight: 700; }
.code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.badge.unused { background: var(--good-bg); color: var(--good); }
.badge.used { background: #eeeae4; color: #5c564f; }
.badge.redeemed { background: var(--warn-bg); color: var(--warn); }
.badge.disabled { background: var(--bad-bg); color: var(--bad); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.actions button { min-height: 44px; padding: 0 12px; font-size: 14px; }
.pager { justify-content: flex-end; margin-top: 10px; }
.pager span { color: var(--muted); font-size: 13px; }

.prize-list { display: grid; gap: 10px; }
.prize {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.swatch { width: 18px; height: 42px; border-radius: 999px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.prize h3 { font-size: 16px; }
.meta { color: var(--muted); font-size: 12px; }
.prize.off { opacity: 0.62; }

dialog {
  width: min(460px, calc(100% - 16px));
  max-height: calc(100dvh - 16px);
  padding: 0;
  border: 0;
  background: transparent;
  overflow: auto;
}
dialog form { display: grid; gap: 10px; padding: 18px; }
dialog::backdrop { background: rgba(28, 25, 21, 0.46); }
.color-row { display: flex; gap: 8px; }
.color-row input[type="color"] { width: 52px; padding: 4px; flex: none; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: auto; min-height: 0; }
#prize-preview { width: 72px; height: 72px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); }

#toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 20;
  transform: translateX(-50%);
  max-width: min(520px, calc(100% - 24px));
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff8f1;
  box-shadow: var(--shadow);
}
#toast.is-error { background: var(--bad); }

@media (max-width: 900px) {
  .split, .stats { grid-template-columns: 1fr 1fr; }
  .split { grid-template-columns: 1fr; }
  .top {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 12px;
  }
  .brand { min-width: 0; }
  .brand small { display: none; }
  .tabs {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
    margin-left: 0;
  }
  .tab, #logout { min-height: 44px; }
  .tab { width: 100%; padding: 0 2px; letter-spacing: 0; font-size: 13px; }
  .verify-card { margin-top: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
  .verify-card h3 { margin-bottom: 6px; }
  a.text-link { min-height: 44px; }
  #logout { grid-column: 2; grid-row: 1; }
  table, thead, tbody, tr, th, td { display: block; }
  thead { display: none; }
  tbody tr {
    margin: 0 0 10px;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
  }
  td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border: 0;
    padding: 6px 0;
  }
  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    flex: none;
  }
  td.actions { justify-content: flex-start; flex-wrap: wrap; }
  .code { overflow-wrap: anywhere; text-align: right; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters input, .filters select, .filters button { width: 100%; flex: none; }
  .prize {
    grid-template-columns: 16px minmax(0, 1fr);
  }
  .prize .actions { grid-column: 1 / -1; }
  .pager { justify-content: space-between; }
  main {
    width: min(100% - 16px, 1180px);
    margin-top: 12px;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }
}
@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .card { padding: 12px; }
}
