* { box-sizing: border-box; }
[hidden] { display: none !important; }
:root {
  color-scheme: light;
  --ink: #1a211c;
  --accent: #007f71;
  --teal: #00b7a6;
  --frame: #19685e;
  font-family: "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: #f4ead9 url("../assets/papier.webp") repeat;
  background-size: 192px;
}
body {
  height: 100vh;
  height: 100svh;
  margin: 0;
  padding: max(.35rem, env(safe-area-inset-top)) max(1.15rem, env(safe-area-inset-right)) max(.65rem, env(safe-area-inset-bottom)) max(1.15rem, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
button, input { font: inherit; }
button { cursor: pointer; color: inherit; touch-action: manipulation; }
:focus-visible { outline: 3px solid #00796e; outline-offset: 4px; }
.mast { width: min(100%, 74rem); margin: 0 auto; display: flex; align-items: center; justify-content: space-between; min-height: 3.5rem; border-bottom: 1px solid #342d2429; }
.mast a, .text-button { display: inline-flex; align-items: center; min-height: 44px; }
.mast img { display: block; width: 5.3rem; height: auto; }
.text-button { border: 0; padding: .45rem .1rem .45rem .5rem; gap: .6rem; background: none; color: var(--ink); font-weight: 650; font-size: .9rem; }
.text-button:hover { text-decoration: underline; }
.podium { display: inline-flex; align-items: end; gap: 2px; height: 14px; }
.podium i { border: 1.5px solid currentColor; width: 4px; height: 55%; }
.podium i:nth-child(2) { height: 100%; background: currentColor; }
.podium i:last-child { height: 36%; }
.game {
  width: min(100%, 64rem); min-height: 0; margin: 0 auto; padding: clamp(.5rem, 2vh, 2rem) 0;
  display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1fr);
  grid-template-areas: "title machine" "console machine";
  gap: 0 clamp(2rem, 7vw, 7rem); align-items: center;
}
.title { grid-area: title; align-self: end; }
h1, h2 { letter-spacing: -.075em; line-height: .98; margin: 0; }
h1 { font-size: clamp(3.4rem, 7.7vw, 6.75rem); font-weight: 800; }
h1 span, h2 span { color: var(--accent); }
.title p { margin: 1rem 0 0; max-width: 24rem; font-size: clamp(1rem, 1.45vw, 1.22rem); line-height: 1.48; }
.board-space {
  grid-area: machine;
  min-width: 0;
  min-height: 0;
  align-self: stretch;
  display: grid;
  place-items: center end;
  container-type: size;
}
.machine {
  --side: .95rem;
  --top: .7rem;
  --dashboard: 2.8rem;
  --footer: 1.3rem;
  /* Fit the 320 × 360 play surface after reserving both borders, the frame and its shadow. */
  width: min(100%, 28rem, 60vh);
  width: min(100%, 28rem, calc((100cqh - var(--top) - var(--dashboard) - var(--footer) - 16px) / 1.125 + 2 * var(--side) + 10px));
  position: relative;
  padding: var(--top) var(--side) 0; border: 2px solid #173f36; border-radius: 1.55rem;
  background: linear-gradient(115deg, #357d6c, var(--frame) 29%, #145349 100%);
  box-shadow: inset 0 2px 1px #96c5ab88, inset 0 -2px 2px #0c3935, 0 5px 0 #103f37, 0 12px 14px -8px #3c362976;
}
.screw { width: 7px; height: 7px; position: absolute; border-radius: 50%; background: linear-gradient(139deg, #c6bc99 38%, #5c604e 41% 54%, #b6af8c 59%); box-shadow: 0 1px 2px #0c352a; }
.tl, .tr { top: 12px; } .tl, .bl { left: 10px; } .tr, .br { right: 10px; } .tr, .bl { transform: rotate(64deg); }
.dashboard { display: flex; height: var(--dashboard); margin: 0 .65rem; padding-bottom: .35rem; align-items: center; justify-content: space-between; gap: .75rem; color: #fffae9; }
.dial { min-width: 0; }
.dial > span, .clock > span { font: 600 .67rem/1.15 ui-monospace, monospace; letter-spacing: .095em; text-transform: uppercase; }
.dial strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: .1rem; font-size: clamp(1.05rem, 2.1vw, 1.35rem); letter-spacing: -.035em; }
.clock { display: flex; align-items: baseline; gap: .45rem; }
#clock { display: inline-block; min-width: 5.3ch; padding: .22rem .45rem; border-radius: 4px; font: 700 clamp(1.15rem, 2vw, 1.6rem)/1.15 ui-monospace, "Courier New", monospace; font-variant-numeric: tabular-nums; letter-spacing: -.06em; background: #0e3c36; color: #dbf1d3; box-shadow: inset 0 2px 3px #092a25aa, 0 1px 0 #69a18a66; white-space: nowrap; }
.rim { border: 3px solid #103e34; border-radius: 12px; overflow: hidden; box-shadow: 0 1px 0 #90b095aa; background: #f3e0b7; }
#board { position: relative; width: 100%; aspect-ratio: 320 / 360; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; outline-offset: -3px; }
#art { display: block; width: 100%; height: 100%; }
#ball { position: absolute; width: 5.625%; aspect-ratio: 1; transform: translate(-50%, -50%); pointer-events: none; border-radius: 50%; }
#ball i { display: block; width: 100%; height: 100%; border-radius: 50%; background: radial-gradient(circle at 31% 24%, #a2fff0 1%, #46dbc0 15%, #00aa98 45%, #00756a 77%, #164f46 100%); box-shadow: inset -1px -1px 1px #174e38a6, 1px 3px 3px #4739227a; }
#ball i::after { content: ""; display: block; width: 100%; height: 100%; border-radius: 50%; transform: rotate(var(--roll, 0rad)); background: radial-gradient(circle at 72% 53%, #00635288 0 7%, transparent 10%); }
.game[data-state="lost"] #ball i { animation: sink .25s ease-in forwards; }
.game:is([data-state="between"], [data-state="won"]) #ball i { transform: scale(.48); opacity: 0; transition: transform .18s ease-out, opacity .18s; }
.game[data-state="won"] #boardNotice { align-items: start; padding-top: 1.5rem; }
@keyframes sink { to { transform: scale(.1); opacity: 0; } }
.footer-rail { height: var(--footer); display: grid; place-items: center; }
.bl,.br { bottom: 7px; }
#progress { display: flex; gap: .4rem; }
#progress i { width: 1.1rem; height: 4px; border-radius: 2px; background: #0d4b40; box-shadow: 0 1px 0 #7daa9166; }
#progress i.done { background: #9be7b3; }
#progress i.current { background: #e9d5a5; }
#stick { position: absolute; z-index: 2; transform: translate(-50%, -50%); width: 54px; height: 54px; border: 1.5px solid #13584f8c; border-radius: 50%; background: #f5f1dd3d; display: grid; place-items: center; pointer-events: none; }
#thumb { width: 16px; height: 16px; border-radius: 50%; background: #126258ab; }
#boardNotice { position: absolute; inset: 0; display: grid; align-items: center; justify-content: center; pointer-events: none; background: #f4e5c012; }
#noticeText { padding: .63em 1em; border-radius: 6px; color: #fbf7e9; background: #173e33f5; box-shadow: 0 3px 0 #092f24; font-weight: 750; font-size: clamp(1.1rem, 2.35vw, 1.7rem); letter-spacing: -.035em; transform: rotate(-3deg); }
.console { grid-area: console; align-self: start; padding-top: 1.65rem; max-width: 25rem; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.primary, .secondary, .entry button { border-radius: .55rem; min-height: 46px; padding: .6rem 1rem; font-size: .98rem; font-weight: 700; border: 1.5px solid var(--ink); }
.primary { color: #fff9ed; background: #163f33; box-shadow: 0 3px 0 #071c15; display: inline-flex; align-items: center; justify-content: center; gap: .55rem; }
.primary i { width: 0; border-width: 5px 0 5px 8px; border-color: transparent transparent transparent currentColor; border-style: solid; }
.game[data-state="playing"] .primary i { width: 8px; height: 11px; border: solid currentColor; border-width: 0 3px; }
.secondary, .entry button { background: #fbf1df; color: var(--ink); }
.primary:active, .secondary:active { transform: translateY(1px); }
#controlsHint, #sensorText, .sub, .ranking-note { font-size: .9rem; line-height: 1.45; color: #55534a; }
#controlsHint, #sensorText { margin: .9rem 0 0; }
#sensorText:empty { display: none; }
.console:has(#sensorText:not([hidden]):not(:empty)) #controlsHint,
.game:is([data-state="lost"], [data-state="won"], [data-state="between"]) #controlsHint { display: none; }
.run-status { font-size: 1.05rem; font-weight: 650; margin: 0 0 .85rem; }
#scoreForm { margin: 0 0 1rem; }
#scoreForm label { display: block; font-size: .9rem; margin-bottom: .4rem; }
.entry { display: flex; gap: .4rem; }
.entry input { min-width: 0; max-width: 14rem; flex: 1; border: 1px solid #a59c84; border-radius: .5rem; padding: .65rem; background: #fff8ec; }
dialog { width: min(calc(100% - 2rem), 27rem); max-height: 85svh; padding: 1.45rem; border: 1.5px solid #302b21; border-radius: 1rem; background: #faf1df; color: var(--ink); box-shadow: 0 6px 0 #203f32, 0 16px 45px #1e2b1b44; }
dialog::backdrop { background: #15271ea6; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.score-select { display: flex; align-items: center; gap: .75rem; margin: .75rem 0; }
.score-select label { font-size: .9rem; font-weight: 600; }
.score-select select { flex: 1; min-width: 0; min-height: 44px; padding: .4rem .5rem; font: inherit; color: var(--ink); background: #fff8ec; border: 1px solid #a59c84; border-radius: .45rem; }
h2 { font-size: 2rem; }
.close { min-width: 44px; min-height: 44px; font-size: 1.5rem; border: 1px solid #c4bba6; border-radius: 50%; background: transparent; }
table { width: 100%; border-collapse: collapse; font-size: .94rem; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: .55rem .16rem; border-bottom: 1px solid #d6cbb3; }
th { font-size: .78rem; color: #585547; }
td:nth-child(2) { overflow-wrap: anywhere; }
td:last-child, th:last-child { text-align: right; white-space: nowrap; }
@media (max-width: 760px), (max-height: 580px) {
  body { padding-inline: max(.75rem, env(safe-area-inset-left)) max(.75rem, env(safe-area-inset-right)); }
  .mast { min-height: 44px; }
  .mast img { width: 4.25rem; }
  .game { gap: 0 1.25rem; }
  h1 { font-size: clamp(1.9rem, 8vw, 2.8rem); }
  .title p { margin: .25rem 0 0; font-size: .94rem; line-height: 1.3; }
  .machine { --side: .55rem; --top: .35rem; --dashboard: 2rem; --footer: .95rem; border-radius: 1.05rem; }
  .dashboard { margin: 0 .48rem; gap: .3rem; padding-bottom: .18rem; }
  .dial { display: flex; align-items: baseline; gap: .45rem; }
  .dial strong { font-size: .92rem; }
  .dial > span, .clock > span { white-space: nowrap; font-size: .65rem; }
  .clock { gap: .3rem; }
  #clock { font-size: 1.05rem; }
  .tl, .tr { top: 7px; } .tl, .bl { left: 5px; } .tr, .br { right: 5px; }
  .bl, .br { bottom: 4px; }
  .console { padding-top: .65rem; }
  .actions { flex-wrap: nowrap; }
  .actions button { flex: 1; min-height: 44px; padding: .4rem .5rem; }
  #controlsHint, #sensorText { margin-top: .35rem; line-height: 1.28; }
  #scoreForm { margin-bottom: .45rem; }
  .run-status { font-size: .95rem; line-height: 1.2; margin-bottom: .4rem; }
}
@media (max-width: 760px) and (orientation: portrait) {
  .mast { max-width: 28rem; }
  .game {
    width: min(100%, 26rem);
    padding: .4rem 0 0;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "title" "machine" "console";
    gap: .4rem;
  }
  .board-space { place-items: center; }
  .console { width: 100%; max-width: none; padding-top: 0; }
}
@media (orientation: landscape) and (max-height: 580px) {
  .game { grid-template-columns: minmax(0, .95fr) minmax(0, 1fr); padding: .25rem 0 0; }
  .board-space { justify-items: center; }
  .title p { max-width: 24rem; }
  .console { padding-top: .4rem; }
}
@container (max-height: 360px) {
  .dial { display: block; }
  .dial > span { display: block; font-size: .61rem; }
  .dial strong { margin: 0; font-size: .8rem; }
  .clock > span { display: none; }
}
@media (max-height: 560px) {
  /* Once a run is over, its name entry can use the inactive board's space. */
  .game:has(#scoreForm:not([hidden])) .console { display: contents; }
  .game:has(#scoreForm:not([hidden])) .controls { grid-area: console; align-self: start; }
  .feedback:has(#scoreForm:not([hidden])) {
    grid-area: machine;
    place-self: center;
    width: min(100% - .75rem, 16rem);
    z-index: 1;
    padding: .65rem;
    border: 1px solid #877b61;
    border-radius: .65rem;
    background: #fbf1df;
    box-shadow: 0 3px 8px #33281644;
  }
  .feedback:has(#scoreForm:not([hidden])) form { margin: 0; }
  .game:has(#scoreForm:not([hidden])) #boardNotice,
  .game[data-state="paused"]:has(#sensorText:not([hidden]):not(:empty)) #status { display: none; }
}
@media (max-height: 560px) and (orientation: portrait) {
  .game { gap: .2rem; }
  h1 { font-size: 1.6rem; }
}
@media (prefers-reduced-motion: reduce) { .game[data-state="lost"] #ball i { animation: none; opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .game:is([data-state="between"], [data-state="won"]) #ball i { transition: none; } }
