:root {
  color-scheme: light;
  font-family: "Pretendard Variable", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  color: #3c2656;
  background: #f7efff;
  --ink: #ad90cb;
  --muted: #654a7e;
  --line: #b69bd3;
  --panel: #fffbff;
  --mint: #c2f3dd;
  --pink: #e18cc5;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", "Pretendard Variable", monospace;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 280px;
  min-height: 100vh;
  background: radial-gradient(ellipse at 45% 28%, #fff9e9 0, transparent 67%),
    radial-gradient(circle, #ac7fc844 1px, transparent 1px) 0 0 / 24px 24px,
    #f7efff;
}
button { font: inherit; }
button:focus-visible { outline: 2px solid #7956a7; outline-offset: 3px; }
.shell { width: min(100% - 48px, 1060px); margin: auto; padding: 26px 0 48px; }
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #dbcaeb;
  padding-bottom: 18px;
}
.wordmark, .clock time, .zone, .eyebrow, .screen-name, .counts button, .records dd { font-family: var(--mono); }
.wordmark { font-weight: 900; letter-spacing: .13em; }
.logo {
  display: inline-grid;
  place-items: center;
  width: 33px;
  height: 32px;
  color: #3a2453;
  background: var(--pink);
  box-shadow: 3px 3px #b284cf;
  margin-right: 6px;
}
.clock { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .8rem; white-space: nowrap; }
.clock time { color: #27634e; font-size: 1rem; font-weight: 800; }
.clock-light, .status > span { height: 7px; width: 7px; background: currentColor; color: #4c9a79; }
.clock-light { box-shadow: 0 0 8px #80cdaa80; }
.zone { font-size: .7rem; }
.intro { display: flex; gap: 22px; align-items: center; margin: 36px 0 30px; }
.sticker {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 96px;
  height: 86px;
  background: #f1dfff;
  border: 2px solid #a778c4;
  box-shadow: 4px 5px #ad90cb, inset 4px 4px #fdf3ff;
  transform: rotate(-5deg);
}
.sticker canvas { width: 67px; image-rendering: pixelated; }
.sticker span { position: absolute; top: 8px; right: 8px; color: #ad6b27; }
.eyebrow { margin: 0 0 4px; font-size: .75rem; color: #7a5198; letter-spacing: .16em; font-weight: 800; }
h1 { margin: 0; font-size: clamp(2.4rem, 5.7vw, 4.6rem); line-height: 1.06; font-weight: 950; letter-spacing: -.09em; text-shadow: 4px 4px #dfbce8; }
h1 span { color: var(--pink); margin-left: .09em; }
.subtitle { margin: 11px 0 0; color: #624674; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 272px; align-items: start; gap: 22px; }
.cabinet, .panel { background: var(--panel); border: 2px solid var(--line); box-shadow: 4px 5px var(--ink), inset 0 3px #f4e6fb; }
.cabinet { padding: 15px; }
.cabinet-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 13px; }
.screen-name { color: #644377; font-size: .85rem; letter-spacing: .11em; font-weight: 800; }
.screen-name span { color: var(--pink); margin-right: 4px; }
.status { display: flex; align-items: center; gap: 7px; padding: 4px 8px; border: 1px solid #d5bde6; color: #5c3c72; background: #f3e8fa; font-size: .8rem; }
.status > span { color: #a681bf; }
.status[data-phase="running"] > span { color: #bd8a3a; }
.status[data-phase="done"] > span { color: #4c9a79; }
.screen { overflow: hidden; border: 2px solid #a786c5; background: #f5eaff; box-shadow: 0 0 0 1px #e2d0ef; }
.racers, .finish { display: grid; grid-template-columns: repeat(var(--lanes, 4), minmax(0, 1fr)); padding-inline: 5%; }
.racers { padding-block: 8px 4px; background: #f3e3fd; }
.racer { display: grid; justify-items: center; gap: 2px; min-width: 0; font-size: .76rem; color: #53396b; white-space: nowrap; }
.racer canvas { width: clamp(25px, 5vw, 42px); height: auto; max-width: 100%; image-rendering: pixelated; }
#board { display: block; width: 100%; height: clamp(210px, 34vw, 345px); image-rendering: pixelated; }
.finish { min-height: 37px; align-items: center; background: #f3e3fd; }
.slot { justify-self: center; width: calc(100% - 5px); max-width: 72px; padding: 3px 0; text-align: center; border: 1px solid #d5bae6; background: #f6eafa; color: #6c4d84; font-size: .76rem; white-space: nowrap; }
.slot[data-result="winner"] { border-color: #ad7945; color: #57301c; background: #ffdfaa; font-weight: 800; }
.hint { min-height: 1.4em; margin: 14px 0 1px; color: #614676; font-size: .9rem; }
.controls { display: grid; gap: 18px; }
.panel { padding: 17px; }
.panel h2 { margin: 0; font-size: 1.02rem; }
.panel h2 span { display: inline-block; width: 1.2em; color: var(--pink); }
.panel p { color: var(--muted); margin: 6px 0 13px; font-size: .88rem; }
.counts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; margin-bottom: 13px; }
.counts button, .start { min-height: 40px; border: 1px solid #bea0d7; color: #542e72; background: #f5e7fc; box-shadow: 0 3px #a786c5; cursor: pointer; font-weight: 800; }
.counts button:not(:disabled):hover { background: #ead8f8; }
.counts button[aria-pressed="true"] { background: var(--mint); color: #235942; border-color: #80bfa2; box-shadow: 0 3px #88b89f; }
.start { width: 100%; min-height: 44px; background: #70478c; border-color: #70478c; color: white; font-size: .95rem; }
.start:not(:disabled):hover { background: #5b3574; }
.start:disabled { opacity: .56; cursor: default; }
.records dl { display: grid; gap: 9px; margin: 13px 0 0; }
.records dl div { display: flex; gap: 8px; justify-content: space-between; border-top: 1px solid #eddeef; padding-top: 8px; }
.records dt { color: var(--muted); font-size: .86rem; }
.records dd { margin: 0; color: #27634e; font-size: .93rem; font-weight: 700; }
@media (max-width: 760px) {
  .shell { width: min(100% - 30px, 520px); padding-top: 18px; }
  .layout { grid-template-columns: 1fr; gap: 15px; }
  .controls { display: contents; }
  .controls > :first-child { grid-row: 1; }
  .counts { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .intro { margin: 26px 0 23px; }
  .cabinet { padding: 10px; }
}
@media (max-width: 430px) {
  .clock > span:not(.zone) { display: none; }
  .wordmark { font-size: .81rem; }
  .sticker { flex-basis: 66px; height: 62px; }
  .sticker canvas { width: 50px; }
  .intro { gap: 14px; }
  .subtitle { font-size: .88rem; }
  .racer { font-size: .67rem; }
  .slot { font-size: .67rem; }
}
.screen-name small { margin-left: 4px; color: #775591; font-family: "Pretendard Variable", system-ui, sans-serif; letter-spacing: 0; font-size: .76rem; }
.difficulty { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin: 10px 0 20px; }
.difficulty button { min-height: 37px; border: 1px solid #bea0d7; color: #542e72; background: #f5e7fc; box-shadow: 0 3px #a786c5; cursor: pointer; font-weight: 800; }
.difficulty button:hover { background: #ead8f8; }
.difficulty button[aria-pressed="true"] { background: var(--pink); border-color: #bb78ad; color: #512347; box-shadow: 0 3px #c789b6; }
[hidden] { display: none !important; }
.roster {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px 2px;
  margin: 16px 0;
  padding: 8px 4px;
  border: 1px solid #e6d2f2;
  background: #fbf3ff;
}
.roster canvas { width: 32px; }
.board-actions { display: flex; align-items: center; gap: 8px; }
.exit {
  min-height: 34px;
  padding: 4px 9px;
  border: 1px solid #ba9bd4;
  background: #f2e5fb;
  box-shadow: 0 2px #c3a6de;
  color: #593c70;
  cursor: pointer;
  font-size: .82rem;
  font-weight: 750;
}
.exit:hover { background: #e9d5f7; }
.rankings { margin-top: 12px; }
.rankings h2 { margin: 0 0 8px; font-size: .97rem; }
.rankings ol {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(113px, 1fr));
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.rankings li {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  padding: 4px 6px;
  border: 1px solid #dec8eb;
  background: #faf0fd;
  font-size: .82rem;
}
.rankings li:first-child { border-color: #daa965; background: #fff0cf; }
.rankings strong { color: #684687; }
.rankings canvas { width: 22px; height: 22px; image-rendering: pixelated; }
.counts button:disabled, .difficulty button:disabled { cursor: default; }

.shell.playing {
  position: fixed;
  inset: 0;
  z-index: 10;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  overflow: auto;
  padding: 12px max(14px, calc((100% - 1350px) / 2)) 24px;
  background: radial-gradient(ellipse at 45% 28%, #fff9e9 0, transparent 72%), #f7efff;
}
.shell.playing::backdrop { background: #f7efff; }
.playing .intro, .playing .controls > :first-child { display: none; }
.playing .top { padding: 3px 0 12px; margin-bottom: 12px; }
.playing #board { height: clamp(160px, 48dvh, 600px); }
.playing .layout { align-items: start; }
@media (max-width: 760px) {
  .playing .layout { gap: 12px; }
  .playing .screen-name { font-size: .72rem; letter-spacing: .04em; }
  .playing .board-actions { gap: 5px; }
  .playing .exit { font-size: .76rem; padding-inline: 5px; }
  .playing .rankings ol { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-height: 500px) and (min-width: 640px) {
  .playing #board { height: 42dvh; }
}
.blink-face { display: block; width: min(100%, 36px); aspect-ratio: 1; overflow: hidden; }
.blink-face canvas { display: block; width: 100%; max-width: none; }
@media (prefers-reduced-motion: no-preference) {
  .blink-face canvas { animation: blink 5.4s step-end var(--blink-delay) infinite; }
}
@keyframes blink {
  0%, 90%, 100% { transform: translateY(0); }
  87% { transform: translateY(-50%); }
}
.results h2 { margin: 5px 0 6px; font-size: 1.35rem; }
.results h2:focus { outline: none; }
.results p { margin: 0 0 15px; color: #745025; font-size: .95rem; font-weight: 750; }
.results table { width: 100%; border-collapse: collapse; background: #fdf6ff; text-align: left; }
.results th, .results td { padding: 6px clamp(4px, 2vw, 16px); border-bottom: 1px solid #e9d8f0; }
.results th { background: #f1e2f9; color: #593c70; font-size: .84rem; }
.results td { font-size: .91rem; }
.results td:last-child { font-variant-numeric: tabular-nums; }
.results canvas { display: block; width: 30px; height: 30px; image-rendering: pixelated; }
.results tr:first-child td { background: #fff2d7; }
.results td:first-child { color: #594078; font-weight: 800; }
.result-toggle {
  min-height: 40px;
  margin-top: 12px;
  padding: 4px 14px;
  border: 1px solid #70478c;
  background: #70478c;
  box-shadow: 0 2px #bc9bd8;
  color: white;
  cursor: pointer;
  font-weight: 750;
}
.result-toggle:hover { background: #5b3574; }
.slow-motion .screen { box-shadow: 0 0 0 1px #ca9a56, 0 0 14px #e9ba7480; }
