:root {
  color-scheme: light;
  --paper: #f5f2e9;
  --surface: #fffdf7;
  --ink: #1d211d;
  --muted: #5d6258;
  --line: #d8d6cc;
  --accent: #f4cb4c;
  --green: #315740;
  --mark: #f7e7a4;
  --display: "Arial Black", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 280px; }
h1, h2, p { margin: 0; }
button, input { font: inherit; }
:focus-visible { outline: 3px solid #3d744c; outline-offset: 4px; }

.wrap { width: min(1120px, calc(100% - 64px)); margin-inline: auto; }
.header { border-bottom: 1px solid var(--line); }
.header-inner { display: flex; align-items: center; justify-content: space-between; min-height: 66px; gap: 12px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-size: .83rem; font-weight: 900; letter-spacing: .11em; }
.brand-mark { display: grid; grid-template-columns: 6px 6px; gap: 2px; padding: 4px; background: var(--ink); border: 1px solid var(--ink); }
.brand-mark i { width: 6px; height: 6px; background: var(--paper); }
.brand-mark i:last-child { background: var(--accent); }
.connection { color: var(--muted); white-space: nowrap; font-size: .78rem; font-weight: 700; }
.connection::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 7px; border: 1px solid currentColor; border-radius: 50%; }
.connection.live { color: var(--green); }
.connection.live::before { background: currentColor; }
.notice { margin: 30px 0; padding: 16px; border: 1px solid var(--line); background: var(--surface); line-height: 1.6; }
.error, .form-error { color: #9c302a; }

.home-layout {
  min-height: calc(100svh - 67px);
  display: grid;
  grid-template-columns: 1fr .85fr;
  align-items: center;
  gap: clamp(40px, 7vw, 110px);
  padding: clamp(56px, 10vh, 124px) 0;
}
.home-copy h1 {
  font-family: var(--display);
  font-size: clamp(3.2rem, 7.25vw, 6.6rem);
  font-weight: 1000;
  letter-spacing: -.085em;
  line-height: 1.06;
}
.home-copy h1 span { display: block; width: max-content; box-shadow: inset 0 -.29em var(--accent); padding: 0 .12em .02em 0; }
.intro { color: var(--muted); margin: 25px 0 34px; font-size: 1rem; line-height: 1.7; }
.form { display: grid; gap: 10px; width: min(100%, 400px); }
.form label, .share label { font-size: .86rem; font-weight: 800; }
.extra-field { display: grid; gap: 10px; }
input {
  width: 100%;
  min-height: 48px;
  padding: 9px 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid #85887d;
  border-radius: 3px;
}
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 46px;
  border: 1px solid var(--ink);
  border-radius: 3px;
  padding: 9px 15px;
  cursor: pointer;
  line-height: 1.35;
  font-size: .86rem;
  font-weight: 850;
  color: var(--ink);
}
.button:disabled { opacity: .48; cursor: default; }
.button.primary { background: var(--accent); }
.button.primary:hover:not(:disabled) { background: #ffda65; }
.button.secondary { background: var(--surface); }
.button.secondary:hover:not(:disabled) { background: #eae7dd; }
.form .button { justify-content: space-between; min-height: 51px; margin-top: 4px; }
.form .button span { font-size: 1.2rem; }
.form-error { font-size: .87rem; line-height: 1.5; }

.ticket {
  position: relative;
  justify-self: center;
  width: min(100%, 380px);
  transform: rotate(7deg);
  padding: 19px 19px 24px;
  border: 1px solid var(--ink);
  border-right-width: 2px;
  border-bottom-width: 2px;
  background: var(--accent);
  box-shadow: 8px 8px 0 var(--ink);
  user-select: none;
}
.ticket-header, .ticket-grid { display: grid; grid-template-columns: repeat(5, 1fr); text-align: center; }
.ticket-header { padding: 10px 0; border-bottom: 2px solid var(--ink); font: 900 clamp(1.25rem, 4vw, 2.8rem) / 1 var(--display); }
.ticket-grid { margin-top: 10px; border-top: 1px solid var(--ink); border-left: 1px solid var(--ink); background: var(--surface); }
.ticket-grid span { display: grid; place-items: center; aspect-ratio: 1; border-right: 1px solid var(--ink); border-bottom: 1px solid var(--ink); font-weight: 850; font-size: clamp(.9rem, 3vw, 1.45rem); }
.ticket-grid .printed { background: var(--mark); }
.ticket-ball {
  position: absolute;
  right: -25px;
  bottom: -12px;
  display: grid;
  place-items: center;
  width: 34%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 4px solid var(--paper);
  background: var(--ink);
  color: var(--paper);
  font: 900 clamp(2rem, 5vw, 4.25rem) / 1 var(--display);
  transform: rotate(-12deg);
}

.room-header { display: flex; align-items: end; justify-content: space-between; gap: 18px 28px; margin: 42px 0 23px; }
.eyebrow { margin-bottom: 8px; font-size: .78rem; font-weight: 850; color: var(--muted); }
.room-header h1 { font-family: var(--display); font-size: clamp(1.7rem, 5vw, 3.25rem); line-height: 1.18; overflow-wrap: anywhere; }
.room-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; color: var(--muted); font-size: .83rem; white-space: nowrap; }
.phase, .card-status { padding: 5px 9px; border: 1px solid var(--line); border-radius: 3px; color: var(--ink); font-weight: 850; }
.phase[data-phase="playing"], .card-status[data-kind="reach"] { background: var(--accent); border-color: var(--ink); }
.phase[data-phase="finished"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.share {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: end;
  gap: 10px;
  padding: 14px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.share label { display: block; margin-bottom: 5px; }
.share input { min-height: 46px; }
.copy-status, #copy-fallback { grid-column: 1 / -1; font-size: .85rem; }

.game-layout { display: grid; grid-template-columns: minmax(250px, .8fr) minmax(0, 1.2fr); gap: 18px; padding-bottom: 40px; }
.game-side, .game-main { display: grid; align-content: start; gap: 18px; min-width: 0; }
.panel { padding: 18px; border: 1px solid var(--line); background: var(--surface); }
.panel h2, .draw-panel h2 { font-size: 1rem; font-weight: 850; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px 14px; }
.count { font-size: .82rem; color: var(--muted); white-space: nowrap; }
.empty { color: var(--muted); margin-top: 14px; line-height: 1.6; font-size: .86rem; }

.draw-panel { display: grid; gap: 12px; padding: 24px; color: var(--paper); background: var(--ink); border-top: 4px solid var(--accent); }
.draw-panel h2 { color: var(--paper); }
.number-line { --ball-color: #ffc83f; display: flex; align-items: baseline; gap: 10px; min-height: 1em; }
.ball-letter { color: var(--accent); font-size: clamp(1.4rem, 3vw, 2.4rem); font-weight: 900; }
.latest { color: var(--accent); font: 900 clamp(4.4rem, 11vw, 8.4rem) / .95 var(--display); font-variant-numeric: tabular-nums; }
.draw-count, .draw-message { color: #deded2; font-size: .85rem; }
.controls { display: grid; gap: 8px; margin-top: 3px; }
.finish { color: var(--paper); border-color: #8b8c81; background: transparent; }
.finish:hover:not(:disabled) { background: #333830; }

.history { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 0; padding: 0; list-style: none; }
.history:empty { display: none; }
.history li { min-width: 44px; text-align: center; border: 1px solid var(--line); padding: 4px 6px; font-size: .79rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.history li:first-child { border-color: var(--ink); background: var(--mark); }
.results { list-style: none; padding: 0; margin: 12px 0 0; }
.results:empty { display: none; }
.results li { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 7px 0; border-top: 1px solid var(--line); }
.rank { flex: none; min-width: 2.6rem; padding: 3px 5px; text-align: center; font-size: .79rem; font-weight: 850; background: var(--mark); border: 1px solid var(--ink); }
.result-name { flex: 1; min-width: 0; font-size: .9rem; font-weight: 750; overflow-wrap: anywhere; }
.result-detail { flex: none; color: var(--muted); font-size: .78rem; }
.roster .results { max-height: 340px; overflow: auto; }

.join-layout { margin: 0 auto 40px; }
.join-panel { width: min(100%, 460px); }
.join-panel > p { margin-top: 8px; color: var(--muted); font-size: .9rem; line-height: 1.6; }
.join-panel .form { margin-top: 18px; max-width: none; }
#card-name { margin-top: 3px; color: var(--muted); font-size: .86rem; overflow-wrap: anywhere; }
.card-status { flex: none; font-size: .8rem; }
.card-status[data-kind="bingo"] { background: var(--green); border-color: var(--green); color: white; }
.card { width: 100%; table-layout: fixed; border-collapse: separate; border-spacing: 5px; margin: 9px 0 0; text-align: center; }
.card th { padding: 5px 0; color: var(--green); font: 900 1.1rem / 1 var(--display); }
.card td { height: clamp(40px, 7vw, 68px); border: 1px solid var(--line); font-weight: 850; font-size: clamp(.95rem, 3.4vw, 1.52rem); font-variant-numeric: tabular-nums; }
.card td.marked { background: var(--mark); border-color: #ae9233; }
.card td.free { font-size: clamp(.59rem, 2.4vw, .85rem); }
.card td.latest-mark { box-shadow: inset 0 0 0 2px var(--ink); }
.card td.winning { color: white; background: var(--green); border-color: var(--green); }
.card td.winning.latest-mark { box-shadow: inset 0 0 0 2px var(--accent); }
.card-legend { display: flex; align-items: center; gap: 7px; margin: 9px 4px 0; color: var(--muted); font-size: .8rem; line-height: 1.5; }
.card-legend span { flex: none; width: 12px; height: 12px; background: var(--mark); border: 1px solid #ae9233; }
dialog { width: min(400px, calc(100% - 32px)); margin: auto; padding: 22px; border: 1px solid var(--ink); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgb(29 33 29 / .53); }
dialog h2 { font-size: 1.15rem; }
dialog p { margin: 10px 0 22px; color: var(--muted); line-height: 1.65; }
.dialog-actions { display: flex; justify-content: end; gap: 8px; }

@media (max-width: 760px) {
  .wrap { width: calc(100% - 32px); }
  .header-inner { min-height: 57px; }
  .home-layout { min-height: 0; grid-template-columns: 1fr; gap: 40px; padding: 42px 0 50px; }
  .home-copy h1 { font-size: clamp(2.9rem, 11vw, 4.5rem); }
  .intro { margin: 20px 0 24px; }
  .ticket { width: min(calc(100% - 48px), 258px); padding: 13px 13px 17px; }
  .ticket-header { font-size: 1.7rem; }
  .ticket-ball { right: -17px; }
  .room-header { display: grid; align-items: start; margin: 26px 0 16px; gap: 10px; }
  .share { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .share > div { grid-column: 1 / -1; }
  .game-layout { display: flex; flex-direction: column; gap: 12px; }
  .game-side, .game-main { display: contents; }
  .draw-panel { order: 0; padding: 16px; }
  .card-panel { order: 1; }
  .winners { order: 2; }
  .roster { order: 3; }
  .recent { order: 4; }
  .panel { padding: 14px; }
  .number-line { gap: 7px; }
  .latest { font-size: 4.2rem; }
  .player-layout .draw-panel { grid-template-columns: 1fr auto; gap: 4px 14px; align-items: center; padding: 12px 14px; }
  .player-layout .number-line { grid-column: 2; grid-row: 1 / span 3; }
  .player-layout .latest { font-size: 3.4rem; }
  .player-layout .draw-count, .player-layout .draw-message { grid-column: 1; font-size: .77rem; }
}

.header-tools { display: flex; align-items: center; gap: 14px; }
.sound-switch { padding: 7px 10px; border: 1px solid var(--line); border-radius: 3px; background: var(--surface); color: var(--ink); font-size: .74rem; font-weight: 850; cursor: pointer; white-space: nowrap; }
.sound-switch[aria-pressed="true"] { background: var(--accent); border-color: var(--ink); }

.draw-panel {
  isolation: isolate;
  background: radial-gradient(ellipse at 48% 36%, #3a432d 0%, #20251f 62%, #181c19 100%);
}
.number-line[data-letter]:not([data-letter=""]) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: start;
  gap: .14em;
  width: clamp(116px, 19vw, 198px);
  aspect-ratio: 1;
  border: 5px solid #fff4c6;
  border-radius: 50%;
  background: radial-gradient(circle at 33% 24%, #fffcdf, var(--ball-color) 61%, #9b6320);
  box-shadow: 0 0 32px #efc55a52, inset -7px -9px 0 #1e241a29, 0 8px 0 #0004;
}
.number-line[data-letter="B"] { --ball-color: #fcc15a; }
.number-line[data-letter="I"] { --ball-color: #f89caa; }
.number-line[data-letter="N"] { --ball-color: #81d8ac; }
.number-line[data-letter="G"] { --ball-color: #8dcfec; }
.number-line[data-letter="O"] { --ball-color: #d2aaf1; }
.number-line[data-letter]:not([data-letter=""]) .latest { font-size: clamp(3.1rem, 7vw, 6rem); color: #1a2119; letter-spacing: -.09em; padding-right: .12em; }
.number-line[data-letter]:not([data-letter=""]) .ball-letter { color: #263023; font-size: clamp(.92rem, 2vw, 1.5rem); }
.card td.latest-mark { animation: stamp .5s ease-out; }
@keyframes stamp {
  0%, 30% { box-shadow: inset 0 0 0 3px var(--ink), 0 0 0 4px #f4cb4c88; }
  100% { box-shadow: inset 0 0 0 2px var(--ink); }
}

.celebration { position: fixed; z-index: 8; inset: 0; display: grid; place-items: center; pointer-events: none; }
.celebration-message {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 8px;
  width: max-content;
  max-width: min(90vw, 650px);
  padding: 13px clamp(18px, 5vw, 42px) 19px;
  border: 2px solid var(--ink);
  background: var(--accent);
  box-shadow: 8px 8px 0 var(--ink);
  text-align: center;
}
.celebration-message strong { font-family: var(--display); font-size: clamp(2.4rem, 10vw, 5.7rem); line-height: 1.05; font-weight: 1000; letter-spacing: -.055em; }
.celebration-message span { font-size: clamp(.8rem, 2vw, 1rem); font-weight: 850; overflow-wrap: anywhere; max-width: 100%; }
.celebration[data-kind="bingo"] .celebration-message { background: linear-gradient(115deg, #fff0a9, #ffca49 70%, #ffab70); }
.celebration[data-kind="reach"] { align-items: end; padding-bottom: clamp(24px, 8vh, 85px); }
.celebration[data-kind="reach"] .celebration-message,
.celebration[data-kind="finish"] .celebration-message { background: var(--ink); color: var(--accent); border-color: var(--accent); }
.confetti { position: absolute; inset: 0; overflow: hidden; }
.confetti i { position: absolute; top: 48%; left: 50%; width: 9px; height: 15px; background: #ffe461; }
.confetti i:nth-child(4n + 1) { background: #fa8da4; border-radius: 50%; }
.confetti i:nth-child(4n + 2) { background: #7dddb1; }
.confetti i:nth-child(4n + 3) { background: #8ad5fd; border-radius: 3px; }

@media (max-width: 760px) {
  .header-tools { gap: 8px; }
  .sound-switch { padding-inline: 5px; }
  .player-layout .number-line[data-letter]:not([data-letter=""]) { width: 76px; border-width: 3px; justify-self: end; }
  .player-layout .number-line[data-letter]:not([data-letter=""]) .latest { font-size: 2.1rem; }
  .player-layout .number-line[data-letter]:not([data-letter=""]) .ball-letter { font-size: .74rem; }
}

@media (prefers-reduced-motion: reduce) {
  .card td.latest-mark { animation: none; }
}

/* Christmas palette and draw stage */
:root {
  --paper: #f8f1e5;
  --surface: #fffaf0;
  --ink: #182b24;
  --muted: #526056;
  --line: #d8cdb6;
  --accent: #ebc778;
  --green: #235c40;
  --mark: #f6df9c;
}
.header {
  background: #164433;
  color: #fff7de;
  border-bottom: 4px solid #d5a958;
}
.header .connection { color: #fff0c9; }
.header .connection.live { color: #c1efc5; }
.header .brand-mark { background: #9c343e; border-color: #e0bb72; }
.ticket { background: #9c343e; }
.ticket-header { color: #fff7de; border-color: #f4d28d; }
.ticket-ball { background: #164433; }
.draw-panel {
  border-color: #d5a958;
  background: radial-gradient(ellipse at 46% 42%, #2d6a51, #164433 55%, #102d23);
}
.roulette {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  justify-self: center;
  width: min(100%, 280px);
  aspect-ratio: 1;
  margin-block: 7px;
}
.roulette::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: 50%;
  background: repeating-conic-gradient(#fff1b6 0deg 3deg, #b58445 3deg 12deg);
  box-shadow: 0 0 24px #f1cd7d39, 0 6px 2px #091c15;
}
.roulette-wheel {
  position: absolute;
  inset: 6px;
  border: 2px solid #5b371f;
  border-radius: 50%;
  box-shadow: inset 0 0 12px #301c1488;
  background: repeating-conic-gradient(#9c343e 0deg 18deg, #286d50 18deg 36deg);
}
.roulette-wheel span {
  position: absolute;
  translate: -50% -50%;
  width: 3ch;
  text-align: center;
  font-size: clamp(.62rem, 1.5vw, .79rem);
  font-weight: 850;
  color: #fff8e1;
  text-shadow: 0 1px 3px #122722;
}
.roulette-wheel .selected { color: #252d21; background: #f8dfa0; text-shadow: none; border-radius: 3px; }
.roulette-pointer {
  position: absolute;
  z-index: 2;
  top: -9px;
  left: 50%;
  translate: -50% 0;
  width: 19px;
  height: 22px;
  background: #fff0b8;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.roulette #ball, .roulette-spinning {
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42%;
  height: 42%;
  aspect-ratio: 1;
  border: 3px solid #ecd18a;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 24%, #fff8d4, #edcb7a 68%, #b88a45);
  box-shadow: 0 4px 9px #10201888;
  color: #213126;
}
.roulette #ball .latest { color: #213126; font-size: clamp(2.15rem, 5vw, 4.3rem); }
.roulette #ball .ball-letter { font-size: clamp(.7rem, 1.5vw, 1.1rem); }
.roulette.spinning #ball { visibility: hidden; }
.roulette-spinning { font-size: clamp(.68rem, 2vw, .93rem); font-weight: 900; }
.celebration[data-kind="bingo"] .celebration-message { background: linear-gradient(125deg, #8e2b39, #b64649); border-color: #f2d48a; color: #fff4d0; }
.confetti i { background: #f5d476; }
.confetti i:nth-child(4n + 1) { background: #ff747b; }
.confetti i:nth-child(4n + 2) { background: #8cd5a1; }
.confetti i:nth-child(4n + 3) { background: #fff4dc; }

@media (max-width: 760px) {
  .player-layout .draw-panel { grid-template-columns: minmax(0, 1fr) minmax(105px, 48%); }
  .player-layout .roulette { grid-column: 2; grid-row: 1 / span 3; width: min(100%, 155px); margin-block: 4px; }
  .player-layout .roulette #ball { width: 43%; border-width: 2px; }
  .player-layout .roulette #ball .latest { font-size: clamp(1.25rem, 5.4vw, 2rem); }
  .player-layout .roulette #ball .ball-letter { font-size: .58rem; }
  .player-layout .roulette-wheel { inset: 4px; }
  .player-layout .roulette-wheel span { font-size: .55rem; }
  .player-layout .roulette-pointer { width: 13px; height: 15px; top: -5px; }
}
