:root {
  color-scheme: light;
  --paper: #f3ede2;
  --paper-deep: #e5dac9;
  --ink: #171713;
  --muted: #6e685e;
  --line: #bdb2a2;
  --tomato: #e34c31;
  --tomato-dark: #bd321e;
  --forest: #214f43;
  --cream: #fffaf1;
  --focus: #0c6fbd;
  font-family: "Avenir Next", "Noto Sans TC", "PingFang TC", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 15%, rgb(255 255 255 / 42%), transparent 24rem),
    linear-gradient(90deg, rgb(23 23 19 / 3%) 1px, transparent 1px),
    var(--paper);
  background-size: auto, 22px 22px, auto;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

button:focus-visible, a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 4px;
}

.site-header {
  min-height: 72px;
  padding: 0 4vw;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--ink);
}

.brand {
  min-height: 44px;
  color: inherit;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .13em;
  text-decoration: none;
}

.brand-mark { color: var(--tomato); font-size: 20px; line-height: 0; }
.rule { color: var(--muted); margin: 0; font-size: 13px; letter-spacing: .08em; }

main {
  width: min(1520px, 100%);
  margin: 0 auto;
  min-height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
}

.wheel-workspace {
  min-width: 0;
  padding: clamp(30px, 4vw, 64px);
  display: grid;
  grid-template-columns: minmax(220px, .72fr) minmax(360px, 1.4fr);
  grid-template-rows: 1fr auto;
  align-items: center;
  gap: 24px clamp(24px, 4vw, 68px);
  overflow: hidden;
}

.intro { align-self: center; position: relative; z-index: 1; }
.eyebrow {
  margin: 0 0 14px;
  color: var(--tomato-dark);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .19em;
}

h1, h2 { margin: 0; font-family: "Iowan Old Style", "Noto Serif TC", "Songti TC", serif; }

h1 {
  font-size: clamp(54px, 6vw, 96px);
  line-height: .9;
  letter-spacing: -.06em;
  text-wrap: balance;
}

h1 em { color: var(--tomato); font-weight: 700; }

.intro-copy {
  max-width: 31em;
  margin: 28px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.85;
}

.wheel-stage {
  position: relative;
  width: min(100%, 700px);
  aspect-ratio: 1;
  justify-self: center;
  filter: drop-shadow(0 24px 24px rgb(44 35 21 / 16%));
}

#wheel { width: 100%; height: 100%; display: block; }

.pointer {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: -8px;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-left: 18px solid transparent;
  border-right: 18px solid transparent;
  border-top: 40px solid var(--ink);
  filter: drop-shadow(0 3px 0 var(--paper));
}

.wheel-center {
  position: absolute;
  inset: 50% auto auto 50%;
  width: 92px;
  aspect-ratio: 1;
  transform: translate(-50%, -50%) rotate(-7deg);
  border: 7px solid var(--paper);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--cream);
  background: var(--tomato);
  box-shadow: 0 0 0 3px var(--ink), 0 7px 0 var(--ink);
  font-family: "Iowan Old Style", serif;
  font-size: 30px;
  font-weight: 900;
}

.action-panel {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto minmax(220px, 430px) 1fr;
  align-items: center;
  gap: 22px;
  padding-top: 22px;
  border-top: 1px solid var(--ink);
}

.remaining-block { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.remaining-number { font: 700 clamp(42px, 4vw, 66px)/1 "Iowan Old Style", serif; color: var(--forest); }
.remaining-label { color: var(--muted); font-size: 13px; }

.spin-button, .primary-button, .map-button {
  min-height: 58px;
  border: 2px solid var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 24px;
  color: var(--cream);
  background: var(--ink);
  box-shadow: 6px 6px 0 var(--tomato);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .06em;
  text-decoration: none;
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.spin-button:hover:not(:disabled), .primary-button:hover, .map-button:hover {
  transform: translate(3px, 3px);
  box-shadow: 3px 3px 0 var(--tomato);
  background: #2c2c25;
}

.spin-button:disabled { cursor: not-allowed; opacity: .45; box-shadow: none; }
.spin-button.is-spinning { background: var(--forest); }
.status-note { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }

.remaining-details {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  color: var(--muted);
}
.remaining-details summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: .35em;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.remaining-list {
  max-height: 260px;
  margin: 0 0 18px;
  padding: 16px 16px 16px 34px;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px 28px;
  border: 1px solid var(--line);
  background: rgb(255 250 241 / 62%);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}
.remaining-list li { padding-left: 2px; overflow-wrap: anywhere; }

.history-panel {
  min-width: 0;
  padding: clamp(30px, 3vw, 46px) clamp(24px, 3vw, 38px);
  border-left: 1px solid var(--ink);
  background: rgb(255 250 241 / 64%);
}

.history-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  padding-bottom: 20px;
  border-bottom: 3px solid var(--ink);
}

.history-heading h2 { font-size: 36px; letter-spacing: -.04em; }
.history-count {
  min-width: 40px;
  height: 40px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.history-list { list-style: none; padding: 0; margin: 0; }
.history-item {
  display: grid;
  grid-template-columns: 35px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 19px 0;
  border-bottom: 1px solid var(--line);
}

.history-index { color: var(--tomato-dark); font: 800 12px/1.7 "Avenir Next", sans-serif; }
.history-name { margin: 0; font: 700 18px/1.35 "Iowan Old Style", "Noto Serif TC", serif; overflow-wrap: anywhere; }
.history-time { display: block; margin-top: 6px; color: var(--muted); font-size: 11px; }
.history-map {
  width: 44px;
  height: 44px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ink);
  text-decoration: none;
  transition: background 150ms, color 150ms;
}
.history-map:hover { color: var(--cream); background: var(--tomato); }

.history-empty { padding: 52px 8px; color: var(--muted); text-align: center; }
.history-empty p { margin: 18px 0 0; font: 600 18px/1.5 "Iowan Old Style", serif; }
.empty-ring { width: 58px; aspect-ratio: 1; border: 1px dashed var(--muted); border-radius: 50%; display: inline-block; }

.modal {
  width: min(520px, calc(100% - 32px));
  padding: 0;
  border: 2px solid var(--ink);
  color: var(--ink);
  background: var(--cream);
  box-shadow: 12px 12px 0 var(--tomato);
}
.modal::backdrop { background: rgb(23 23 19 / 62%); backdrop-filter: blur(2px); }
.modal form, .result-content { position: relative; padding: clamp(32px, 6vw, 54px); }
.modal h2 { max-width: 12em; font-size: clamp(38px, 7vw, 60px); line-height: 1.02; letter-spacing: -.05em; }
.modal p:not(.eyebrow) { color: var(--muted); line-height: 1.75; }
.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border: 0;
  color: var(--ink);
  background: transparent;
  font-size: 30px;
  cursor: pointer;
}
.modal-actions { margin-top: 30px; display: grid; grid-template-columns: 1fr 1.35fr; gap: 12px; }
.primary-button { border: 0; box-shadow: none; justify-content: center; padding: 0 16px; }
.secondary-button { min-height: 58px; border: 1px solid var(--ink); background: transparent; font-weight: 700; cursor: pointer; }
.secondary-button:hover { background: var(--paper-deep); }
.access-label {
  display: block;
  margin: 26px 0 8px;
  font-size: 13px;
  font-weight: 800;
}
.access-input {
  width: 100%;
  min-height: 50px;
  border: 2px solid var(--ink);
  padding: 10px 12px;
  color: var(--ink);
  background: white;
  font: 600 16px/1.4 "Avenir Next", "Noto Sans TC", sans-serif;
}
.access-error {
  min-height: 24px;
  margin: 8px 0 14px !important;
  color: #8f2516 !important;
  font-size: 13px;
  font-weight: 700;
}
.access-submit { width: 100%; }
.result-modal { text-align: left; }
.result-stamp {
  position: absolute;
  right: 48px;
  top: 70px;
  width: 76px;
  aspect-ratio: 1;
  border: 4px double var(--tomato);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--tomato);
  transform: rotate(12deg);
  font-weight: 900;
}
.result-modal h2 { padding-right: 60px; overflow-wrap: anywhere; }
.map-button { margin-top: 28px; box-shadow: 6px 6px 0 var(--forest); }

.error-banner { color: #8f2516; font-weight: 700; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 1080px) {
  main { grid-template-columns: 1fr; }
  .history-panel { border-top: 1px solid var(--ink); border-left: 0; }
  .history-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 30px; }
}

@media (max-width: 760px) {
  .site-header { min-height: 62px; padding: 0 18px; }
  .rule { display: none; }
  main { min-height: calc(100vh - 62px); }
  .wheel-workspace { padding: 28px 18px 32px; grid-template-columns: 1fr; grid-template-rows: auto auto auto; gap: 24px; }
  .intro { text-align: center; }
  h1 { font-size: clamp(54px, 19vw, 78px); }
  .intro-copy { margin: 18px auto 0; max-width: 28em; font-size: 14px; }
  .wheel-stage { width: min(100%, 530px); }
  .wheel-center { width: 70px; border-width: 5px; font-size: 24px; }
  .pointer { top: -4px; border-left-width: 14px; border-right-width: 14px; border-top-width: 32px; }
  .action-panel { grid-column: auto; grid-template-columns: auto 1fr; gap: 16px; padding-top: 18px; }
  .spin-button { min-height: 62px; }
  .status-note { grid-column: 1 / -1; text-align: center; }
  .history-panel { padding: 32px 20px 48px; }
  .history-list { grid-template-columns: 1fr; }
  .remaining-list { grid-template-columns: 1fr; max-height: 320px; }
  .modal-actions { grid-template-columns: 1fr; }
  .result-stamp { right: 28px; top: 58px; width: 64px; }
}

@media (max-width: 410px) {
  .intro-copy { display: none; }
  .wheel-workspace { gap: 18px; }
  .action-panel { grid-template-columns: 1fr; }
  .remaining-block { justify-content: center; }
  .status-note { grid-column: auto; }
  .spin-button { width: 100%; }
  .result-stamp { display: none; }
  .result-modal h2 { padding-right: 0; }
}

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