:root {
  color-scheme: dark;
  --bg: #101216;
  --panel: #191d23;
  --panel-raised: #20252d;
  --panel-input: #13171d;
  --line: #2b323b;
  --line-strong: #3a4552;
  --text: #f1f3f6;
  --muted: #9ba5b2;
  --subtle: #737e8b;
  --ice: #cadcf5;
  --ice-strong: #a8c9f5;
  --mint: #9dd6b8;
  --coral: #e98d7c;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; min-width: 320px; min-height: 100%; }
body {
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}
button, input { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, canvas:focus-visible {
  outline: 2px solid var(--ice-strong);
  outline-offset: 2px;
}

.page-shell {
  display: flex;
  flex-direction: column;
  width: min(calc(100vw - 32px), 480px);
  max-width: calc(100vw - 32px);
  min-width: 0;
  height: 100dvh;
  min-height: 0;
  margin: 0 auto;
  padding: 14px 0 max(9px, env(safe-area-inset-bottom));
}
.topbar, .brand, .activity-state, .panel-heading, .input-row, .status-line,
.balance-row, .play-button, .dialog-actions, footer {
  display: flex;
  align-items: center;
}
.topbar, .panel-heading, .balance-row, footer { justify-content: space-between; }
.topbar { flex: none; min-height: 40px; }
.brand { gap: 9px; color: var(--text); text-decoration: none; }
.brand-mark { display: block; width: 40px; height: 40px; object-fit: contain; }
.brand-name { font-size: 16px; font-weight: 700; }
.activity-state {
  gap: 7px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}
.activity-state > span:first-child { width: 6px; height: 6px; flex: none; border-radius: 50%; background: var(--mint); }

.intro { flex: none; padding: 18px 2px 13px; }
.overline, .section-label, .result-label {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
}
.overline { display: flex; align-items: center; gap: 8px; }
.overline span { color: var(--subtle); }
.intro h1 { margin: 7px 0 4px; font-size: 28px; font-weight: 720; line-height: 1.2; }
.intro > p:last-child { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }

.event-panel {
  flex: none;
  width: 100%;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 18px 42px #0000002e;
}
.panel-heading { gap: 12px; padding-bottom: 11px; border-bottom: 1px solid var(--line); }
.panel-heading strong { display: block; margin-top: 3px; font-size: 14px; font-weight: 670; }
/* The public mode is loaded from the server. Keep the default HTML label and
   tabs invisible until that value is known, avoiding a scratch→draw flash. */
.event-panel.is-loading .panel-heading strong,
.event-panel.is-loading .mode-switch { visibility: hidden; }
.mode-chip {
  padding: 6px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--ice);
  font-size: 9px;
  font-weight: 650;
  white-space: nowrap;
}
.mode-chip span { margin-right: 4px; color: var(--mint); font-variant-numeric: tabular-nums; }
form label { display: block; margin: 12px 0 6px; font-size: 11px; font-weight: 650; }
.input-row { gap: 7px; }
.input-row input {
  width: 0;
  min-width: 0;
  height: 42px;
  flex: 1;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  outline: none;
  background: var(--panel-input);
  color: var(--text);
  font-size: 12px;
}
.input-row input::placeholder { color: var(--subtle); }
.input-row input:focus { border-color: #839fbe; }
.helper { margin: 6px 0 0; color: var(--muted); font-size: 9px; line-height: 1.4; }
.button {
  min-height: 42px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}
.button-secondary { border-color: var(--line-strong); background: #222830; color: var(--text); }
.button-secondary:hover { border-color: #657487; background: #29313b; }
.status-line {
  gap: 8px;
  min-height: 32px;
  margin-top: 10px;
  padding: 7px 9px;
  border-radius: 6px;
  background: #151a20;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.4;
}
.status-dot { width: 6px; height: 6px; flex: none; border-radius: 50%; background: #7e8998; }
.status-line.success { color: var(--mint); }
.status-line.success .status-dot { background: var(--mint); }
.status-line.error { color: var(--coral); }
.status-line.error .status-dot { background: var(--coral); }

.play-area { margin-top: 11px; padding-top: 11px; border-top: 1px solid var(--line); }
.balance-row { gap: 10px; }
.balance strong { display: block; margin-top: 2px; color: var(--text); font-size: 25px; line-height: 1; font-variant-numeric: tabular-nums; }
.balance strong small { margin-left: 4px; color: var(--muted); font-size: 10px; font-weight: 500; }
.expiry { color: var(--muted); font-size: 9px; text-align: right; }
.play-button {
  width: 100%;
  min-height: 46px;
  justify-content: space-between;
  margin-top: 11px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(105deg, #eef0f3 0%, #c2c8d1 100%);
  color: #171a20;
  font-size: 12px;
  font-weight: 750;
}
.play-button:hover { background: linear-gradient(105deg, #fff 0%, #d0d7e0 100%); }
.play-button:disabled { cursor: not-allowed; opacity: .5; }
.play-arrow { color: #4e5967; font-size: 18px; font-weight: 400; }

.scratch-result {
  position: relative;
  height: 146px;
  margin-top: 10px;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid #64707c;
  border-radius: 9px;
  background: #151b21;
  box-shadow: inset 0 0 0 3px #0d1116, 0 7px 18px #00000025;
}
.prize-reveal {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 13px 15px;
  overflow: hidden;
  background: linear-gradient(118deg, #252d34 0%, #192128 51%, #293139 100%);
  text-align: left;
}
.prize-reveal::before {
  position: absolute;
  inset: 0;
  border: 1px solid #d9e0e720;
  background: repeating-linear-gradient(132deg, transparent 0 26px, #d9e0e708 27px 28px);
  content: "";
  pointer-events: none;
}
.ticket-heading, .ticket-foot { position: relative; z-index: 1; display: flex; align-items: center; }
.ticket-heading { justify-content: space-between; gap: 10px; }
.ticket-number { color: #9ba8b4; font-size: 8px; font-weight: 700; }
.prize-name { position: relative; z-index: 1; color: #edf1f4; font-size: 24px; line-height: 1.1; font-weight: 730; }
.ticket-foot { gap: 7px; }
.ticket-spark { color: var(--mint); font-size: 12px; }
.prize-caption { color: #b7c1ca; font-size: 9px; }
.ticket-brand { margin-left: auto; color: #8996a2; font-size: 8px; font-weight: 750; }
.scratch-surface { position: absolute; z-index: 2; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; transition: opacity .5s ease; }
.scratch-surface:active { cursor: grabbing; }
.scratch-prompt {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: #252c33;
  pointer-events: none;
  text-align: center;
  transition: opacity .22s ease, transform .22s ease;
}
.scratch-result.is-touching .scratch-prompt { opacity: 0; transform: translateY(-4px); }
.scratch-prompt strong { font-size: 12px; font-weight: 760; }
.scratch-prompt small { color: #48535e; font-size: 9px; }
.scratch-star { color: #3d614d; font-size: 16px; line-height: 1; }
.scratch-result.is-revealing .scratch-surface { animation: cover-recede 1.35s cubic-bezier(.2,.65,.25,1) .3s forwards; }
.scratch-result.is-revealing .scratch-prompt { animation: prompt-recede .25s ease forwards; }
.scratch-result.is-revealing .ticket-heading { animation: ticket-rise .45s ease .45s both; }
.scratch-result.is-revealing .prize-name { animation: ticket-rise .56s cubic-bezier(.2,.8,.2,1) .9s both; }
.scratch-result.is-revealing .ticket-foot { animation: ticket-rise .5s ease 1.45s both; }
.scratch-result.revealed { border-color: #a7b7c2; box-shadow: inset 0 0 0 3px #0d1116, 0 0 0 1px #a7b7c233, 0 9px 23px #0000003d; }
.scratch-result.revealed .prize-reveal { animation: ticket-settle .45s ease both; }
@keyframes cover-recede { to { opacity: 0; visibility: hidden; transform: scale(1.025); } }
@keyframes prompt-recede { to { opacity: 0; transform: translateY(-4px); } }
@keyframes ticket-rise { from { opacity: .62; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
@keyframes ticket-settle { from { filter: brightness(.92); } to { filter: brightness(1); } }
.again-button { margin-top: 7px; padding: 4px 0 0; border: 0; background: transparent; color: var(--ice); font-size: 9px; }
.notice { margin: 9px 0 0; padding: 8px 9px; border-left: 2px solid var(--coral); background: #211a1b; color: #e9b5ab; font-size: 9px; line-height: 1.5; }
footer { gap: 10px; margin-top: auto; padding: 10px 2px 0; color: var(--subtle); font-size: 8px; }
footer i { padding: 0 3px; color: var(--ice-strong); font-style: normal; }

.confirm-dialog {
  width: min(calc(100% - 28px), 360px);
  max-height: calc(100dvh - 24px);
  margin: auto;
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 24px 70px #0009;
}
.confirm-dialog::backdrop { background: #05070acc; }
.confirm-dialog form { padding: 18px; }
.dialog-mark {
  display: grid;
  width: 30px;
  height: 30px;
  margin-bottom: 12px;
  place-items: center;
  border: 1px solid #3a414b;
  border-radius: 8px;
  background: #11151b;
  color: #d4d6dc;
  font-size: 18px;
  font-weight: 700;
}
.confirm-dialog h2 { margin: 6px 0 7px; font-size: 17px; }
.dialog-copy { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.65; }
.dialog-actions { justify-content: flex-end; gap: 7px; margin-top: 16px; }
.button-primary { background: linear-gradient(105deg, #eef0f3 0%, #c2c8d1 100%); color: #171a20; }
.button-primary:hover { background: linear-gradient(105deg, #fff 0%, #d0d7e0 100%); }

@media (max-height: 700px) {
  .page-shell { padding-top: 8px; }
  .intro { padding-top: 11px; padding-bottom: 9px; }
  .intro h1 { margin-top: 4px; font-size: 25px; }
  .event-panel { padding: 12px; }
  .helper { font-size: 8px; }
  .status-line { min-height: 29px; margin-top: 8px; }
  .play-area { margin-top: 8px; padding-top: 8px; }
  .scratch-result { height: 120px; }
  footer { padding-top: 7px; }
}
@media (min-width: 700px) {
  .page-shell { padding-top: 20px; }
  .intro { padding-top: 25px; padding-bottom: 16px; }
  .event-panel { padding: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}

.mode-switch {
  display: flex;
  flex: none;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--panel-input);
}
.mode-button {
  min-height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 9px;
  font-weight: 650;
}
.mode-button.active {
  background: linear-gradient(105deg, #eef0f3 0%, #c2c8d1 100%);
  color: #171a20;
}
.history-entry { display: flex; justify-content: flex-end; margin-top: 6px; }
.public-tools { gap: 14px; }
.history-link {
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: var(--ice);
  font-size: 9px;
  font-weight: 650;
}
.history-link:hover { color: #fff; }
.result-extra { margin-top: 7px; }
.result-message { margin: 0; color: var(--mint); font-size: 10px; line-height: 1.45; }
.reward-card-code {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 7px;
  padding: 7px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel-input);
}
.reward-card-code code { min-width: 0; flex: 1; overflow-wrap: anywhere; color: var(--text); font-size: 10px; }
.copy-reward-card { min-height: 30px; padding: 0 8px; font-size: 9px; }
.history-dialog {
  width: min(calc(100% - 28px), 420px);
  max-height: min(calc(100dvh - 24px), 640px);
  margin: auto;
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 24px 70px #0009;
}
.history-dialog::backdrop { background: #05070acc; }
.history-dialog form { position: relative; padding: 19px; }
.history-dialog h2 { margin: 7px 32px 5px 0; font-size: 19px; }
.history-hint { margin: 0 0 12px; color: var(--muted); font-size: 10px; line-height: 1.5; }
.dialog-close {
  position: absolute;
  top: 12px;
  right: 13px;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #222830;
  color: var(--text);
  font-size: 20px;
}
.history-results { display: grid; gap: 8px; margin-top: 12px; }
.history-item { padding: 10px; border: 1px solid var(--line); border-radius: 7px; background: #151a20; }
.history-item-heading { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.history-item-heading strong { font-size: 11px; }
.history-item time { flex: none; color: var(--subtle); font-size: 8px; }
.history-item > p { margin: 6px 0 0; color: var(--muted); font-size: 9px; line-height: 1.45; }
.history-item .reward-card-code { flex-wrap: wrap; }
.history-empty, .history-error, .history-count { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.history-error { color: var(--coral); }
.history-count { color: var(--ice); }
.showcase-dialog:not([open]) { display: none; }
.showcase-dialog {
  width: min(calc(100% - 28px), 440px);
  max-width: calc(100% - 28px);
  max-height: min(calc(100dvh - 32px), 680px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid #46505d;
  border-radius: 20px;
  background: #161a20;
  color: var(--text);
  box-shadow: 0 28px 90px #0009, inset 0 1px #ffffff0d;
}
.showcase-dialog::backdrop { background: #05070bbd; backdrop-filter: blur(5px); }
.showcase-shell { display: flex; flex-direction: column; max-height: min(calc(100dvh - 34px), 678px); }
.showcase-header { position: relative; flex: none; padding: 22px 20px 14px; background: radial-gradient(ellipse at 0 0, #34404d75, transparent 75%); }
.showcase-identity { display: flex; gap: 12px; align-items: center; padding-right: 42px; }
.showcase-identity img { display: block; flex: none; object-fit: contain; }
.showcase-eyebrow { margin: 0 0 5px; color: #9eabba; font: 600 9px/1.3 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .12em; }
.showcase-header h2 { margin: 0; color: #f2f4f7; font-size: 23px; line-height: 1.25; letter-spacing: .03em; }
.showcase-close { position: absolute; right: 12px; top: 15px; display: grid; place-items: center; width: 44px; height: 44px; padding: 11px; border: 0; border-radius: 12px; color: #a9b4c2; background: transparent; }
.showcase-close:hover { color: #fff; background: #ffffff0b; }
.showcase-close svg, .showcase-icon svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.showcase-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; padding-top: 12px; border-top: 1px solid #ffffff0b; color: #8491a1; font-size: 10px; line-height: 1.4; }
.showcase-meta > span:first-child { display: flex; gap: 6px; align-items: center; }
.showcase-meta i { width: 5px; height: 5px; border-radius: 50%; background: var(--mint); }
.showcase-list { display: grid; flex: 0 1 auto; min-height: 0; gap: 10px; margin: 0; padding: 2px 20px 14px; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #465260 transparent; }
.showcase-list:focus-visible { outline: 1px solid var(--ice-strong); outline-offset: -3px; }
.showcase-item { display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 13px; align-items: start; padding: 16px 14px; border: 1px solid #343d48; border-radius: 13px; background: linear-gradient(125deg, #252c35, #1b2129 70%); box-shadow: inset 0 1px #ffffff06; }
.showcase-icon { display: grid; place-items: center; width: 38px; height: 38px; padding: 9px; border: 1px solid #ffffff14; border-radius: 11px; background: linear-gradient(135deg, #d9e4f21a, #90a5bf08); color: #c6d2df; }
.showcase-number { display: block; margin-bottom: 5px; color: #8392a3; font: 500 9px/1.3 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .08em; }
.showcase-item strong { display: block; color: #edf1f5; font-size: 16px; font-weight: 650; line-height: 1.5; overflow-wrap: anywhere; }
.showcase-item p { margin: 6px 0 0; color: #a4afbc; font-size: 12px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.showcase-footer { display: block; flex: none; margin: 0; padding: 12px 20px 20px; border-top: 1px solid #ffffff09; background: #14181e; }
.showcase-footer p { display: flex; align-items: flex-start; gap: 7px; margin: 0 0 13px; color: #8794a4; font-size: 10px; line-height: 1.65; }
.showcase-footer p span { flex: none; display: grid; place-items: center; width: 13px; height: 13px; margin-top: 2px; border: 1px solid #667385; border-radius: 50%; font: 10px/1 Georgia, serif; }
.showcase-footer button { width: 100%; min-height: 44px; border-radius: 10px; font-size: 13px; }
.showcase-empty { margin: 0; padding: 26px 14px; border: 1px dashed #3b4653; border-radius: 13px; color: var(--muted); text-align: center; font-size: 12px; }
.showcase-empty strong { display: block; color: #d0d8e2; font-size: 14px; font-weight: 600; }
.showcase-empty p { margin: 8px 0 0; line-height: 1.6; }
@media (max-width: 360px), (max-height: 600px) {
  .showcase-header { padding: 16px 16px 12px; }
  .showcase-meta { margin-top: 14px; }
  .showcase-list { padding: 2px 16px 12px; }
  .showcase-footer { padding: 10px 16px 14px; }
  .showcase-item { padding: 13px 11px; gap: 10px; }
}
.activity-state.closed > span:first-child { background: var(--coral); }

@media (max-width: 390px) {
  .page-shell { width: min(calc(100vw - 22px), 480px); max-width: calc(100vw - 22px); }
  .event-panel { padding: 12px; }
  .panel-heading { gap: 7px; }
  .mode-button { padding: 0 7px; }
  .history-dialog form { padding: 15px; }
}

@media (max-width: 700px) {
  /* Avoid mobile Safari's automatic page zoom when the history key field receives focus. */
  #history-kami, #kami { font-size: 16px; }
}

/* Compact the decoration, not the interactive controls, on short phones. */
@media (max-height: 600px) and (max-width: 700px) {
  .page-shell { padding-top: 6px; }
  .topbar { min-height: 32px; }
  .brand-mark { width: 32px; height: 32px; }
  .intro { padding: 7px 2px 8px; }
  .intro .overline, .intro > p:last-child { display: none; }
  .intro h1 { margin: 0; font-size: 22px; }
  .panel-heading { padding-bottom: 7px; }
  form label { margin-top: 8px; }
  .event-panel:has(.play-area:not([hidden])) .helper { display: none; }
  .status-line { min-height: 26px; margin-top: 6px; padding: 5px 8px; }
  .balance strong { font-size: 22px; }
  .scratch-result { height: 104px; margin-top: 7px; }
  .prize-reveal { padding: 10px 12px; }
  .prize-name { font-size: 21px; }
  .result-extra > .result-message { display: none; }
}

/* A software keyboard / landscape viewport must never make controls unreachable. */
@media (max-height: 450px) {
  body { overflow-y: auto; }
  .page-shell { height: auto; min-height: 100dvh; }
}
