:root, [data-iht-theme="light"] {
  --ink: #2b2118; --muted: #7a6a58; --paper: #f6efe3; --card: #fffaf2; --line: #e5d9c6;
  --field: #fff; --soft: #fffdf8; --stripe: #f8f0e3; --chip: #f3e9d9; --hl: #fde7c4; --thumb: #ddd;
  --banner: #fdf0d6; --banner-line: #f1d9a6; --good: #2f8a57; --on-ink: #fff;
  --accent: #c8553d; --accent-ink: #fff; --gold: #e0a43a;
  --clock: #2b2118; --clock-ink: #fff7e8; --shadow: rgba(60, 40, 20, .16);
  --felt: #23493f; --felt-hi: #2e5e51; --felt-lo: #183229;
  color-scheme: light;
}
/* Dark mode: the platform SDK marks the page with data-iht-theme="dark" (site menu: Auto / Light / Dark).
   Before the SDK has loaded, Auto users get dark from their device setting, so there is no bright flash. */
[data-iht-theme="dark"] {
  --ink: #f2e8d8; --muted: #b9a78f; --paper: #1b1510; --card: #251e17; --line: #3e3227;
  --field: #2e261d; --soft: #2a2219; --stripe: #2c241c; --chip: #352b21; --hl: #4d3b22; --thumb: #2e261d;
  --banner: #382a19; --banner-line: #5a4527; --good: #6cc792; --on-ink: #1b1510;
  --accent: #dd6a4f; --accent-ink: #fff; --gold: #e0a43a;
  --clock: #0f0b08; --clock-ink: #fff0d8; --shadow: rgba(0, 0, 0, .45);
  --felt: #1a382f; --felt-hi: #22473c; --felt-lo: #0f2119;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-iht-theme]) {
    --ink: #f2e8d8; --muted: #b9a78f; --paper: #1b1510; --card: #251e17; --line: #3e3227;
    --field: #2e261d; --soft: #2a2219; --stripe: #2c241c; --chip: #352b21; --hl: #4d3b22; --thumb: #2e261d;
    --banner: #382a19; --banner-line: #5a4527; --good: #6cc792; --on-ink: #1b1510;
    --accent: #dd6a4f; --accent-ink: #fff; --gold: #e0a43a;
    --clock: #0f0b08; --clock-ink: #fff0d8; --shadow: rgba(0, 0, 0, .45);
    --felt: #1a382f; --felt-hi: #22473c; --felt-lo: #0f2119;
    color-scheme: dark;
  }
}
:root { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { color: var(--ink); background: var(--paper); }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { display: flex; flex-direction: column; min-height: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }
.boot { padding: 40px; text-align: center; color: var(--muted); }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 18px; background: var(--card); border-bottom: 1px solid var(--line); color: var(--ink); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 800; font-size: 1.25rem; letter-spacing: .01em; }
.logo { width: 30px; height: 30px; fill: var(--accent); }
nav { display: flex; align-items: center; gap: 14px; }
.home-link { text-decoration: none; color: var(--muted); font-weight: 600; }
.home-link:hover { color: var(--ink); }
.theme-btn { border: 1px solid var(--line); background: var(--field); color: var(--ink); border-radius: 999px; padding: 5px 11px; font-size: .88rem; font-weight: 600; }

/* ---------- gallery */
.gallery { width: min(1240px, 100%); margin: 0 auto; padding: 22px 18px 50px; }
.intro h1 { margin: 6px 0 4px; font-size: clamp(1.8rem, 4vw, 2.6rem); }
.intro p { margin: 0 0 16px; color: var(--muted); font-size: 1.05rem; }
.banner { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 12px 16px; margin-bottom: 16px; background: var(--banner); border: 1px solid var(--banner-line); border-radius: 12px; }
.banner span { flex: 1 1 260px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.filters button { border: 1px solid var(--line); background: var(--card); padding: 7px 14px; border-radius: 999px; font-weight: 600; color: var(--muted); }
.filters button[aria-selected="true"] { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.card { display: flex; flex-direction: column; text-align: left; padding: 0; border: 1px solid var(--line); background: var(--card); border-radius: 14px; overflow: hidden; transition: transform .15s, box-shadow .15s; }
.card:hover, .card:focus-visible { transform: translateY(-3px); box-shadow: 0 10px 24px var(--shadow); }
.thumb { position: relative; display: block; aspect-ratio: 16 / 9; background: var(--thumb); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card.locked .thumb img { filter: saturate(.75) brightness(.92); }
.tag { position: absolute; top: 8px; font-size: .78rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.tag.free { left: 8px; background: #2f8a57; color: #fff; }
.tag.lock { left: 8px; background: rgba(30, 20, 10, .72); color: #fff; }
.tag.going { right: 8px; background: var(--gold); color: #2b1a00; }
.name { padding: 10px 12px 12px; font-weight: 700; }

/* ---------- buttons and dialogs */
.primary, .actions button, .banner button { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 16px; font-weight: 700; }
.primary { background: var(--accent) !important; color: var(--accent-ink) !important; border-color: var(--accent) !important; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 4px; font-size: .9rem; }
.overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(25, 18, 10, .55); }
.dialog { position: relative; width: min(460px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--card); border-radius: 18px; padding: 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.dialog h2 { margin: 0 0 8px; font-size: 1.35rem; }
.dialog h3 { margin: 12px 0 6px; font-size: 1rem; }
.dialog p { margin: 6px 0; }
.x { position: absolute; top: 10px; right: 12px; border: 0; background: none; font-size: 1.6rem; line-height: 1; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.pick-thumb { width: 100%; aspect-ratio: 16 / 9; max-height: 20vh; object-fit: cover; border-radius: 12px; margin-bottom: 10px; }
.levels { display: grid; gap: 8px; margin-top: 12px; }
.level-row { display: flex; align-items: center; gap: 6px; }
.level { flex: 1; display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; text-align: left; border: 1px solid var(--line); background: var(--field); border-radius: 12px; padding: 11px 14px; }
.level:hover { border-color: var(--accent); }
.level strong { font-size: 1.05rem; }
.level span { color: var(--muted); }
.level .best { grid-column: 1 / -1; font-size: .88rem; }
.level .resume { grid-column: 1 / -1; color: var(--accent); font-weight: 700; font-size: .9rem; }
.custom { margin-top: 10px; border: 1px dashed var(--line); border-radius: 12px; padding: 11px 14px; background: var(--soft); }
.custom-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.custom-head span { color: var(--muted); font-size: .9rem; }
.custom-head .tag-m { margin-left: auto; font-size: .78rem; font-weight: 700; color: #fff; background: rgba(30, 20, 10, .72); padding: 2px 9px; border-radius: 999px; }
.custom input[type=range] { width: 100%; margin: 12px 0 8px; accent-color: var(--accent); }
.custom.locked input[type=range] { opacity: .45; }
.custom-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.custom-foot output { font-weight: 700; font-variant-numeric: tabular-nums; }
.big-time { font-size: 2.6rem; font-weight: 800; margin: 4px 0 !important; font-variant-numeric: tabular-nums; }
.new-best { color: var(--good); font-weight: 700; }
.board-list ol { list-style: none; margin: 0; padding: 0; font-variant-numeric: tabular-nums; }
.board-list li { display: flex; justify-content: space-between; padding: 5px 8px; border-radius: 8px; }
.board-list li:nth-child(odd) { background: var(--stripe); }
.board-list li.you { background: var(--hl); font-weight: 700; }

/* ---------- play */
body[data-view="play"] { height: 100vh; height: 100dvh; overflow: hidden; }
body[data-view="play"] main { flex: 1; min-height: 0; display: flex; }
.play { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 8px 14px; background: var(--card); border-bottom: 1px solid var(--line); }
.back { text-decoration: none; font-weight: 700; white-space: nowrap; }
.title { display: flex; flex-direction: column; min-width: 0; flex: 1 1 160px; }
.title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title span { color: var(--muted); font-size: .85rem; }
.clock { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; padding: 2px 12px; border-radius: 10px; background: var(--clock); color: var(--clock-ink); min-width: 92px; text-align: center; }
.clock.penalty { animation: penalty .8s; }
@keyframes penalty { 0%, 60% { background: var(--accent); } 100% { background: var(--clock); } }
.tools { display: flex; flex-wrap: wrap; gap: 6px; }
.tools button { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--field); border-radius: 10px; padding: 6px 10px; font-weight: 600; font-size: .9rem; }
.tools button[aria-pressed="true"] { background: var(--hl); border-color: var(--gold); }
.table { position: relative; flex: 1; min-height: 0; background: radial-gradient(ellipse at center, var(--felt-hi) 0%, var(--felt) 60%, var(--felt-lo) 100%); overflow: hidden; }
.table canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.table canvas:active { cursor: grabbing; }
.preview { position: absolute; right: 14px; bottom: 14px; width: min(34%, 420px); border: 4px solid var(--card); border-radius: 8px; box-shadow: 0 10px 30px rgba(0, 0, 0, .45); pointer-events: none; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: #e8f2ee; font-weight: 600; }
.paused { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(20, 35, 30, .92); color: #fff; text-align: center; }
.paused h2 { font-size: 2rem; margin: 0 0 6px; }
.paused p { margin: 0 0 16px; color: #cfe2db; }
[hidden] { display: none !important; }

/* ---------- playing with friends */
.together p { margin: 6px 0 10px; }
.together-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.together-btns button { border: 1px solid var(--line); background: var(--field); border-radius: 10px; padding: 7px 11px; font-weight: 600; font-size: .9rem; }
.together-btns button:hover { border-color: var(--accent); }
.together.locked .together-btns button { opacity: .7; }
.players { display: flex; flex-wrap: wrap; gap: 6px; }
.pl { font-size: .85rem; padding: 4px 10px; border-radius: 999px; background: var(--chip); font-variant-numeric: tabular-nums; }
.pl b { font-weight: 700; margin-right: 2px; }
.pl.you { background: var(--hl); outline: 1px solid var(--gold); }
.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 60; background: rgba(30, 20, 10, .9); color: #fff8ea; padding: 9px 16px; border-radius: 999px; font-weight: 600; pointer-events: none; }
.notice { max-width: 420px; padding: 22px; border-radius: 16px; background: var(--card); color: var(--ink); text-align: center; box-shadow: 0 16px 40px rgba(0, 0, 0, .35); }
.notice h2 { margin: 0 0 8px; }
.notice .actions { justify-content: center; }
.btn { display: inline-block; text-decoration: none; border-radius: 10px; padding: 9px 16px; font-weight: 700; }
.next-round select { font: inherit; padding: 7px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--field); color: var(--ink); }
.next-row { display: flex; flex-wrap: wrap; gap: 8px; }
.next-row .np { flex: 1 1 180px; }

@media (max-width: 760px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
}

/* ---------- phones: easy one-handed play
   Portrait: slim bar at the top (back, title, clock), the table in the middle, tools along the bottom.
   Landscape: tools down the right side so the table keeps the height. */
button, a, input, select { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.table canvas { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }

@media (max-width: 640px), (max-height: 480px) and (pointer: coarse) {
  /* gallery */
  .top { padding: calc(8px + env(safe-area-inset-top)) 12px 8px; }
  .brand { font-size: 1.1rem; gap: 8px; }
  .logo { width: 26px; height: 26px; }
  nav { gap: 10px; }
  .home-link { font-size: .9rem; }
  .theme-btn { padding: 5px 9px; font-size: .82rem; }
  .gallery { padding: 14px 12px calc(30px + env(safe-area-inset-bottom)); }
  .intro h1 { font-size: 1.7rem; margin: 2px 0 4px; }
  .intro p { font-size: .92rem; margin-bottom: 12px; }
  .banner { padding: 10px 12px; font-size: .92rem; gap: 8px; }
  .banner .primary, .banner button, .banner .btn { padding: 8px 14px; }
  .filters { flex-wrap: nowrap; overflow-x: auto; margin: 0 -12px 14px; padding: 0 12px 2px; scrollbar-width: none; }
  .filters::-webkit-scrollbar { display: none; }
  .filters button { flex: none; padding: 8px 14px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { border-radius: 12px; }
  .card:hover { transform: none; }
  .name { padding: 8px 10px 10px; font-size: .9rem; line-height: 1.25; }
  .tag { top: 6px; font-size: .7rem; padding: 2px 7px; }
  .tag.free, .tag.lock { left: 6px; }
  .tag.going { right: 6px; }

  /* dialogs slide up from the bottom */
  .overlay { place-items: end center; padding: 0; }
  .dialog { width: 100%; max-width: 560px; max-height: 90vh; max-height: 90dvh; border-radius: 18px 18px 0 0; padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); animation: sheet .2s ease-out; }
  @keyframes sheet { from { transform: translateY(40px); opacity: .6; } }
  .dialog h2 { font-size: 1.2rem; padding-right: 28px; }
  .x { top: 8px; right: 8px; width: 40px; height: 40px; }
  .pick-thumb { max-height: 15vh; margin-bottom: 8px; }
  .level { padding: 10px 12px; min-height: 52px; }
  .custom { padding: 10px 12px; }
  .custom input[type=range] { height: 32px; margin: 6px 0; }
  .together-btns button { flex: 1 1 calc(50% - 6px); padding: 10px 8px; }
  .actions button, .actions .btn { flex: 1 1 auto; padding: 11px 14px; }
  .big-time { font-size: 2.2rem; }
  .next-row select { padding: 10px 8px; }

  /* play screen */
  body[data-view="play"] .top { display: none; }
  .play {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-rows: auto auto minmax(0, 1fr) auto;
    background: var(--card); padding-top: env(safe-area-inset-top);
  }
  .play .toolbar { display: contents; }
  .play .back { grid-area: 1 / 1; padding: 10px 6px 10px 12px; font-size: .92rem; }
  .play .title { grid-area: 1 / 2; padding: 6px 6px; }
  .play .title strong { font-size: .95rem; }
  .play .title span { font-size: .74rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .play .clock { grid-area: 1 / 3; align-self: center; margin-right: 10px; font-size: 1.15rem; min-width: 66px; padding: 2px 8px; }
  .play .players { grid-area: 2 / 1 / 3 / 4; flex-wrap: nowrap; overflow-x: auto; padding: 0 12px 6px; scrollbar-width: none; }
  .play .players::-webkit-scrollbar { display: none; }
  .play .pl { flex: none; font-size: .78rem; padding: 3px 9px; }
  .play .table { grid-area: 3 / 1 / 4 / 4; border-top: 1px solid var(--line); }
  .play .tools {
    grid-area: 4 / 1 / 5 / 4; flex-wrap: nowrap; justify-content: space-around; gap: 2px; overflow-x: auto;
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); scrollbar-width: none;
  }
  .play .tools::-webkit-scrollbar { display: none; }
  .play .tools button {
    flex: 1 0 44px; flex-direction: column; justify-content: center; gap: 1px; min-height: 50px; padding: 4px 2px;
    border: 0; border-radius: 10px; background: none; font-size: 1.2rem; line-height: 1.1;
  }
  .play .tools button span { display: block; font-size: .62rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
  .play .tools button[aria-pressed="true"] { background: var(--hl); }
  .preview { right: 8px; bottom: 8px; width: 48%; border-width: 3px; }
  .notice { margin: 0 12px; padding: 18px 16px; }
  body[data-view="play"] .toast { bottom: calc(72px + env(safe-area-inset-bottom)); max-width: calc(100% - 24px); text-align: center; }
}

/* phones held sideways: tools in a column on the right */
@media (max-height: 480px) and (orientation: landscape) and (pointer: coarse) {
  .play { grid-template-columns: auto minmax(0, 1fr) auto auto; grid-template-rows: auto auto minmax(0, 1fr); padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left); }
  .play .back { padding: 6px 6px 6px 10px; }
  .play .title { padding: 4px 6px; }
  .play .players { grid-area: 1 / 4 / 2 / 5; padding: 4px 8px; align-self: center; }
  .play .clock { margin-right: 6px; }
  .play .table { grid-area: 2 / 1 / 4 / 4; }
  .play .tools { grid-area: 2 / 4 / 4 / 5; flex-direction: column; justify-content: flex-start; overflow-y: auto; overflow-x: hidden; padding: 4px; border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
  .play .tools button { flex: none; min-height: 40px; width: 60px; padding: 2px; font-size: 1.05rem; }
  .play .tools button span { font-size: .58rem; }
  .preview { width: 36%; }
  body[data-view="play"] .toast { bottom: 16px; }
}
