﻿:root {
  color-scheme: light;
  --paper: #faf4e6;
  --ink: #172e50;
  --blue: #214d92;
  --blue-dark: #18396d;
  --muted: #525b67;
  --line: #a69f8e;
  --accent: #a04e2c;
  --wheel-gutter: 60px;
  --result-gutter: 124px;
  font-family: "Arial", "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); }
h1, h2, p { margin: 0; }
button { cursor: pointer; font: inherit; }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
button:disabled, button[aria-disabled="true"] { cursor: default; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.game {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: minmax(calc(80px + 2 * var(--result-gutter)), 1fr) auto;
  padding-inline: clamp(14px, 4vw, 56px);
}
.dialog-actions { display: flex; gap: 8px; align-items: center; }
.quiet, .primary {
  min-height: 44px;
  border: 1px solid var(--blue);
  border-radius: 5px;
  padding: 8px 14px;
  font-weight: 700;
}
.quiet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: transparent;
  color: var(--ink);
}
.quiet:hover:not(:disabled) { background: #e9e8df; }
.quiet:disabled { opacity: .48; }
.primary {
  background: var(--blue);
  color: #fff;
  min-inline-size: 135px;
  padding-inline: 25px;
  font-size: clamp(1.04rem, 1.6vw, 1.25rem);
}
.primary:hover:not([aria-disabled="true"]) { background: var(--blue-dark); }
.primary[aria-disabled="true"] { opacity: .65; }

.stage { display: grid; container-type: size; }
#wheel-panel { --media-size: min(100cqw, calc(100cqh - 2 * var(--gutter))); --gutter: var(--wheel-gutter); }
#result-panel { --media-size: min(100cqw, max(80px, calc(100cqh - 2 * var(--gutter)))); --gutter: var(--result-gutter); }
.stage-panel {
  grid-area: 1 / 1;
  display: grid;
  grid-template-rows: minmax(var(--gutter), 1fr) var(--media-size) minmax(var(--gutter), 1fr);
  justify-items: center;
  min-inline-size: 0;
  text-align: center;
}
.wheel-area, .result-art {
  grid-row: 2;
  width: var(--media-size);
  height: var(--media-size);
}
.wheel-area { position: relative; }
.wheel-frame {
  width: 100%;
  height: 100%;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: #dce8f1;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.wheel-frame.pulling { cursor: grabbing; }
.wheel-frame.spinning { cursor: default; }
.wheel-frame svg { display: block; width: 100%; height: 100%; border-radius: 50%; }
.slice path { stroke: var(--paper); stroke-width: 2; }
.slice.latest image, .slice.latest circle { opacity: 1; }
.slice.latest path { fill: #ead19b; }
.pointer, .hub { position: absolute; left: 50%; pointer-events: none; }
.pointer {
  top: -8px;
  width: clamp(18px, 7%, 36px);
  height: clamp(22px, 8%, 42px);
  transform: translateX(-50%);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  background: var(--accent);
}
.hub {
  top: 50%;
  width: 10%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
}
.stage-actions {
  grid-row: 3;
  align-self: start;
  padding-block-start: 10px;
  display: grid;
  justify-items: center;
  gap: 7px;
}
.result-art {
  display: block;
  object-fit: contain;
  border: 1px solid var(--line);
  background: var(--paper);
}
.result-actions { padding-block-start: 8px; gap: 7px; }
#winner {
  font-size: clamp(2rem, min(7vw, 7svh), 4.75rem);
  font-weight: 800;
  line-height: 1;
}
#result-panel.reveal .result-art, #result-panel.reveal #winner { animation: reveal 180ms ease-out both; }
@keyframes reveal { from { opacity: 0; } to { opacity: 1; } }

.draws {
  container-type: inline-size;
  padding-block-end: 4px;
  width: min(100%, 760px);
  margin-inline: auto;
  align-self: start;

  padding-block-start: 3px;
}
.draws-header { border-block-end: 1px solid var(--line); padding-block-end: 6px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 44px; }
.draws-header .count { margin-inline-start: auto; }
.draws-header .quiet { padding-inline: 8px; font-size: .9rem; }
.count { font-variant-numeric: tabular-nums; color: var(--muted); }
.history {
  --columns: 16;
  grid-auto-rows: calc((100cqw - (var(--columns) - 1) * 4px) / var(--columns));
  grid-template-rows: repeat(var(--rows, 1), calc((100cqw - (var(--columns) - 1) * 4px) / var(--columns)));
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(16, minmax(0, 1fr));
  gap: 4px;
}
.history li { aspect-ratio: 1; min-width: 0; }
.history li:last-child { outline: 2px solid var(--accent); outline-offset: -2px; }
.history img { display: block; width: 100%; height: 100%; object-fit: cover; position: relative; z-index: -1; }
.history li { isolation: isolate; }

dialog {
  width: min(calc(100% - 30px), 390px);
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  padding: 24px;
}
dialog::backdrop { background: #172e5090; }
dialog p { margin-block: 10px 22px; color: var(--muted); }
.dialog-actions .primary { min-inline-size: auto; font-size: 1rem; }

@media (max-width: 650px) {
  :root { --wheel-gutter: 54px; --result-gutter: 88px; }


  .history { --columns: 8; --rows: 2; grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .draws { max-width: 328px; }
  .stage-actions { padding-block-start: 8px; gap: 5px; }
  #winner { font-size: clamp(1.65rem, 8vw, 3.2rem); }
}
@media (min-width: 651px) and (max-height: 740px) {
  :root { --result-gutter: 96px; }
  .draws { max-width: 730px; }
    #winner { font-size: clamp(1.75rem, 6vh, 3rem); }
}
@media (orientation: landscape) and (max-height: 440px) {
  :root { --wheel-gutter: 52px; --result-gutter: 75px; }
  .draws { max-width: 480px; }
  .history { --columns: 16; --rows: 1; grid-template-columns: repeat(16, minmax(0, 1fr)); }
  #winner { font-size: 1.5rem; }
  .result-actions { padding-block-start: 4px; gap: 3px; }
}
@media (prefers-reduced-motion: reduce) {
  #result-panel.reveal .result-art, #result-panel.reveal #winner { animation: none; }
}

/* Fit the circle between the pointer and spin control on upright screens. */
#wheel-panel {
  --media-size: min(100cqw, calc(100cqh - var(--wheel-gutter) - 10px));
  grid-template-rows: minmax(10px, 1fr) var(--media-size) minmax(var(--wheel-gutter), 1fr);
}
@media (max-width: 650px) {
  .game { padding-inline: 5px; }
  }

/* On wide screens, use the space beside the circle for controls and history. */
@media (min-width: 760px) and (min-aspect-ratio: 7/5) {
  .game {
    --rail: clamp(144px, 13vw, 240px);
    padding: 12px 8px;
    grid-template-columns: minmax(var(--rail), 1fr) minmax(0, min(calc(100dvh - 24px), calc(100% - 2 * var(--rail)))) minmax(var(--rail), 1fr);
    grid-template-rows: minmax(0, 1fr);
  }

  .stage { grid-area: 1 / 2; }
  #wheel-panel {
    position: relative;
    --media-size: min(100cqw, 100cqh);
    grid-template-rows: 1fr var(--media-size) 1fr;
  }
  #wheel-panel .stage-actions {
    position: absolute;
    left: 100%;
    bottom: 0;
    width: var(--rail);
    padding: 0 4px;
  }
  #spin { min-inline-size: 0; padding-inline: 10px; }
  .draws {
    grid-area: 1 / 3;
    align-self: center;
    width: min(calc(100% - 12px), 220px, calc(100dvh - 66px));
  }
  .history {
    --columns: 4;
    --rows: 4;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.wheel-frame { -webkit-user-select: none; }
.wheel-frame svg { pointer-events: none; }
