:root {
  --paper: #f4efe3;
  --ink: #1c2520;
  --forest: #17483c;
  --mint: #c6dfb9;
  --coral: #e85e43;
  --cream: #fffbed;
  --line: rgba(28, 37, 32, 0.22);
  --muted: #687168;
  --shadow: 9px 9px 0 var(--ink);
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background-color: var(--paper);
  background-image: radial-gradient(rgba(28, 37, 32, 0.11) 0.7px, transparent 0.7px);
  background-size: 7px 7px;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

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

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

.page-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; }

.masthead {
  min-height: 86px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1.5px solid var(--ink);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-family: "STKaiti", "KaiTi", serif;
  font-size: 23px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.wordmark-mark {
  display: grid;
  width: 31px;
  height: 31px;
  place-items: center;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  background: var(--coral);
  color: var(--cream);
  font-family: Georgia, serif;
  font-size: 21px;
  line-height: 1;
}

.masthead > p, .field-hint, .history-footnote, .machine-subtitle, .draw-status {
  color: var(--muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
}

.masthead > p { margin: 0; font-size: 12px; letter-spacing: 0.08em; }

.hero {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 48px;
  align-items: end;
  padding: 72px 6.5% 54px;
}

.eyebrow, .step, footer {
  margin: 0;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
}

h1, h2, p { margin-top: 0; }

h1 {
  max-width: 720px;
  margin: 13px 0 19px;
  font-family: "STKaiti", "KaiTi", "Songti SC", serif;
  font-size: clamp(54px, 8vw, 104px);
  font-weight: 800;
  line-height: 0.93;
  letter-spacing: -0.08em;
}

h1 em { color: var(--forest); font-style: normal; }
.intro { max-width: 390px; margin: 0; font-size: 15px; line-height: 1.8; }

.rule-note {
  position: relative;
  padding: 22px 22px 20px;
  border: 1.5px solid var(--ink);
  background: var(--mint);
  box-shadow: 6px 6px 0 var(--ink);
  transform: rotate(2deg);
}

.rule-note p { margin: 0 0 8px; font-size: 11px; font-weight: 800; letter-spacing: 0.1em; }
.rule-note strong { font-family: "STKaiti", "KaiTi", serif; font-size: 19px; line-height: 1.3; }
.star { position: absolute; top: -18px; right: -12px; color: var(--coral); font-size: 32px; }

.machine-layout {
  display: grid;
  grid-template-columns: minmax(250px, 0.88fr) minmax(360px, 1.25fr) minmax(215px, 0.72fr);
  gap: 20px;
  align-items: start;
  padding-bottom: 58px;
}

.input-station, .history-panel {
  min-height: 490px;
  padding: 23px;
  border: 1.5px solid var(--ink);
  background: rgba(255, 251, 237, 0.72);
}

.section-heading { display: flex; justify-content: space-between; align-items: start; gap: 8px; }
.section-heading h2 { margin: 5px 0 0; font-family: "STKaiti", "KaiTi", serif; font-size: 25px; line-height: 1; }
.count { padding: 5px 8px; border: 1px solid var(--ink); font-size: 11px; font-weight: 700; }

textarea {
  display: block;
  width: 100%;
  min-height: 170px;
  margin-top: 26px;
  padding: 13px;
  resize: vertical;
  border: 1.5px solid var(--ink);
  border-radius: 0;
  outline: none;
  background: var(--cream);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.7;
  transition: box-shadow 160ms ease, transform 160ms ease;
}

textarea::placeholder { color: #92978d; }
textarea:focus { box-shadow: 4px 4px 0 var(--coral); transform: translate(-1px, -1px); }
.field-hint { margin: 9px 0 18px; font-size: 10px; line-height: 1.55; }

.choice-preview { display: flex; min-height: 34px; flex-wrap: wrap; gap: 6px; align-content: flex-start; }
.choice-chip { max-width: 100%; overflow: hidden; padding: 5px 8px; border: 1px solid var(--ink); background: var(--mint); text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.preview-empty { color: var(--muted); font-family: "STKaiti", "KaiTi", serif; font-size: 14px; }

.input-actions { display: flex; gap: 16px; margin-top: 20px; }
.text-button, .icon-button { padding: 0; border: 0; background: none; cursor: pointer; text-decoration: underline; text-underline-offset: 4px; font-size: 12px; font-weight: 700; }
.text-button:hover, .icon-button:hover { color: var(--coral); }
.subtle { color: var(--muted); }

.draw-machine { position: relative; min-height: 540px; padding-top: 1px; }
.machine-topline { display: flex; justify-content: space-between; align-items: center; min-height: 39px; padding: 0 3px 8px; }
.ready-light { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-family: ui-monospace, monospace; font-size: 10px; }
.ready-light i { width: 8px; height: 8px; border: 1px solid var(--ink); border-radius: 50%; background: #b7baaf; }
.ready-light.ready { color: var(--forest); }
.ready-light.ready i { background: #8fc673; box-shadow: 0 0 0 2px rgba(143, 198, 115, 0.35); }

.machine-body {
  position: relative;
  min-height: 466px;
  padding: 42px 36px 28px;
  overflow: hidden;
  border: 1.5px solid var(--ink);
  background: var(--forest);
  color: var(--cream);
  box-shadow: var(--shadow);
  text-align: center;
}

.machine-body::before, .machine-body::after { position: absolute; content: ""; opacity: 0.35; border: 1px solid var(--cream); border-radius: 50%; }
.machine-body::before { width: 250px; height: 250px; top: -155px; left: -105px; }
.machine-body::after { width: 315px; height: 315px; right: -178px; bottom: -180px; }
.machine-body h2 { position: relative; z-index: 1; margin: 0; font-family: "STKaiti", "KaiTi", serif; font-size: clamp(29px, 3vw, 38px); letter-spacing: 0.22em; }
.machine-subtitle { position: relative; z-index: 1; margin: 9px 0 23px; color: rgba(255, 251, 237, 0.72); font-size: 9px; letter-spacing: 0.16em; }
.machine-rivets { position: absolute; inset: 12px; display: flex; justify-content: space-between; pointer-events: none; }
.machine-rivets i { width: 6px; height: 6px; border-radius: 50%; background: rgba(255, 251, 237, 0.55); }

.result-window {
  position: relative;
  z-index: 1;
  display: flex;
  min-height: 137px;
  padding: 20px 20px 18px;
  border: 5px double var(--ink);
  background: var(--cream);
  color: var(--ink);
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
}

.window-label { align-self: flex-start; font-family: ui-monospace, monospace; font-size: 9px; font-weight: 700; letter-spacing: 0.12em; }
output { display: block; overflow-wrap: anywhere; margin: 13px 0 4px; font-family: "STKaiti", "KaiTi", serif; font-size: clamp(27px, 4vw, 43px); font-weight: 800; line-height: 1; }
.window-line { width: 36px; border-bottom: 2px solid var(--coral); }

.result-window.is-drawing output { animation: tick 110ms steps(2, end) infinite; }
.result-window.is-winner { animation: ticket-pop 450ms cubic-bezier(.16, .8, .25, 1); }

@keyframes tick { 50% { transform: translateX(2px); opacity: 0.7; } }
@keyframes ticket-pop { 0% { transform: scale(0.92); } 55% { transform: scale(1.04); } 100% { transform: scale(1); } }

.draw-button {
  position: relative;
  z-index: 1;
  display: inline-grid;
  width: 113px;
  height: 78px;
  margin-top: 25px;
  padding: 0;
  border: 0;
  cursor: pointer;
  background: transparent;
}

.button-face, .button-shadow { position: absolute; inset: 0; display: grid; place-items: center; border: 1.5px solid var(--ink); }
.button-face { z-index: 1; background: var(--coral); font-family: "STKaiti", "KaiTi", serif; font-size: 29px; font-weight: 800; letter-spacing: 0.1em; transition: transform 130ms ease; }
.button-shadow { top: 7px; left: 7px; background: var(--ink); }
.draw-button:hover .button-face { transform: translate(-2px, -2px); }
.draw-button:active .button-face { transform: translate(5px, 5px); }
.draw-button:disabled { cursor: not-allowed; opacity: 0.62; }
.draw-button:disabled .button-face { transform: none; }
.draw-status { position: relative; z-index: 1; min-height: 16px; margin: 18px 0 0; color: rgba(255, 251, 237, 0.75); font-size: 10px; }

.ticket-slot { position: absolute; z-index: 2; left: 50%; bottom: 0; display: flex; width: 88px; height: 28px; padding: 8px 12px; border: 1.5px solid var(--ink); background: var(--cream); gap: 3px; transform: translate(-50%, 20px); }
.ticket-slot span { flex: 1; border-top: 2px dotted var(--ink); }

.history-panel { display: flex; flex-direction: column; }
.icon-button { width: 24px; height: 24px; border: 1px solid var(--ink); text-decoration: none; font-size: 19px; line-height: 20px; }
.history-list { display: flex; padding: 0; margin: 29px 0 0; list-style: none; flex-direction: column; gap: 0; }
.history-list li { display: flex; justify-content: space-between; gap: 8px; padding: 12px 0; border-top: 1px dashed var(--line); font-size: 13px; }
.history-list li:first-child { border-top: 1.5px solid var(--ink); }
.history-list strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-list time { flex: 0 0 auto; color: var(--muted); font-family: ui-monospace, monospace; font-size: 9px; }
.history-list .empty-history { display: block; color: var(--muted); border-top: 1.5px solid var(--ink); font-family: "STKaiti", "KaiTi", serif; font-size: 14px; line-height: 1.5; }
.history-footnote { margin: auto 0 0; padding-top: 20px; font-size: 9px; line-height: 1.5; }

footer { display: flex; justify-content: space-between; padding: 18px 1px 31px; border-top: 1.5px solid var(--ink); color: var(--muted); font-size: 9px; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 920px) {
  .machine-layout { grid-template-columns: minmax(260px, 0.85fr) minmax(350px, 1.15fr); }
  .history-panel { min-height: auto; grid-column: 1 / -1; }
  .history-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 20px; }
  .history-list .empty-history { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100% - 28px, 540px);
    padding-bottom: max(4px, env(safe-area-inset-bottom));
  }
  .masthead { min-height: 70px; }
  .masthead > p { display: none; }
  .hero { grid-template-columns: 1fr; gap: 31px; padding: 45px 3% 38px; }
  .rule-note { width: min(220px, 75%); justify-self: end; }
  .machine-layout { grid-template-columns: 1fr; gap: 18px; }
  .input-station { min-height: auto; }
  .draw-machine { min-height: 509px; }
  .machine-body { min-height: 445px; padding: 38px 22px 26px; }
  .history-list { display: flex; }
  .history-panel { min-height: 280px; }
  footer { gap: 11px; font-size: 8px; }

  textarea { font-size: 16px; }
  .text-button { min-height: 44px; padding: 0 2px; }
  .icon-button { width: 36px; height: 36px; font-size: 23px; line-height: 31px; }
}

@media (max-width: 420px) {
  .page-shell { width: calc(100% - 24px); }
  .wordmark { gap: 8px; font-size: 20px; }
  .wordmark-mark { width: 28px; height: 28px; font-size: 18px; }
  .hero { gap: 26px; padding: 38px 0 32px; }
  h1 { margin-bottom: 16px; font-size: clamp(46px, 16vw, 64px); }
  .intro { font-size: 14px; line-height: 1.75; }
  .rule-note { padding: 18px; }
  .rule-note strong { font-size: 18px; }
  .input-station, .history-panel { padding: 18px; }
  .section-heading h2 { font-size: 23px; }
  textarea { min-height: 156px; margin-top: 21px; }
  .input-actions { justify-content: space-between; gap: 10px; margin-top: 13px; }
  .draw-machine { min-height: 485px; }
  .machine-body { min-height: 420px; padding: 34px 17px 22px; box-shadow: 6px 6px 0 var(--ink); }
  .machine-body h2 { font-size: 29px; }
  .result-window { min-height: 126px; padding: 17px 15px; }
  output { font-size: clamp(26px, 9vw, 37px); }
  .draw-button { width: 118px; height: 74px; margin-top: 21px; }
  .history-panel { min-height: 250px; }
  footer { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 12px; padding-bottom: 25px; }
  footer span:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
  footer span:last-child { text-align: right; }
}

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