/* Roundhouser interface. Menus, HUD chrome and touch controls live in screen space;
   the canvas behind them draws the arena. Look: carved stone, brass edges, saffron. */
:root {
  --cream: #f3e9d2; --muted: #b9adc6; --dim: #9d90ab;
  --brass: #d9a441; --brass-hi: #f1d27a; --brass-dk: #8a6a2f;
  --saffron: #e8892b; --saffron-hi: #f5a94a;
  --stone: #2b2434; --stone-hi: #3b3246; --stone-deep: #1c1724;
  --sky: #7fd0e6;
  --font-head: "Lilita One", "Segoe UI Black", "Arial Black", Impact, sans-serif;
  --font-body: "Nunito", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: #150f1d; overflow: hidden; font-family: var(--font-body); color: var(--cream); }
canvas { display: block; width: 100vw; height: 100vh; height: 100dvh; touch-action: none; }
button, input, select { font: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
:is(button, input, select, summary):focus-visible { outline: 3px solid var(--brass-hi); outline-offset: 3px; }
button:disabled { opacity: .5; cursor: default; }

/* ---- buttons: stone slabs with a brass edge ---- */
.btn, .panel > button, #result-actions button, #online button:not(.text-button), .menu-actions button {
  font-family: var(--font-head); font-weight: 400; letter-spacing: .05em; font-size: 18px; line-height: 1.1;
  color: var(--cream); background: linear-gradient(var(--stone-hi), #241d2d);
  border: 2px solid var(--brass-dk); border-radius: 14px; padding: 12px 20px; min-height: 48px;
  box-shadow: inset 0 1px 0 rgba(255,235,200,.14), inset 0 -3px 0 rgba(0,0,0,.35), 0 6px 18px rgba(0,0,0,.45);
  text-shadow: 0 2px 0 rgba(0,0,0,.45);
  transition: transform .08s ease, border-color .12s ease, filter .12s ease;
}
:is(.btn, .panel > button, #result-actions button, #online button, .menu-actions button):hover { filter: brightness(1.1); border-color: var(--brass-hi); transform: translateY(-1px); }
:is(.btn, .panel > button, #result-actions button, #online button, .menu-actions button):active { transform: translateY(1px); box-shadow: inset 0 3px 6px rgba(0,0,0,.45); }
.btn-primary { background: linear-gradient(#f2a53f, #d97a1c) !important; color: #2a1200 !important; border-color: #a85f14 !important; text-shadow: 0 1px 0 rgba(255,230,190,.45) !important; }
.btn-online { background: linear-gradient(#5cc4dc, #2f95ad) !important; color: #06212b !important; border-color: #24707f !important; text-shadow: 0 1px 0 rgba(220,250,255,.5) !important; }
.ghost, .btn-ghost { background: rgba(28,23,36,.75) !important; color: var(--muted) !important; border-color: #5e4d6b !important; }
.text-button { background: transparent !important; border: 0 !important; box-shadow: none !important; color: #d8c6a5 !important; font-family: var(--font-body) !important; font-weight: 700 !important; font-size: 13px !important; letter-spacing: .02em !important; text-shadow: none !important; min-height: 36px !important; padding: 6px 10px !important; }
.text-button:hover { color: var(--brass-hi) !important; transform: none !important; }
.title-links { display: flex; justify-content: center; align-items: center; gap: 4px; flex-wrap: wrap; }
a.text-button { text-decoration: none; display: inline-flex; align-items: center; }

/* ---- safe area probe and toolbar ---- */
#safe-area { position: fixed; inset: 0; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); pointer-events: none; visibility: hidden; }
#toolbar { position: fixed; z-index: 7; top: max(8px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); }
.icon-button { width: 44px; height: 44px; padding: 0; border-radius: 50%; font-size: 20px; color: var(--cream); background: radial-gradient(circle at 35% 30%, #3b3246, #1c1724); border: 2px solid var(--brass-dk); box-shadow: 0 4px 12px rgba(0,0,0,.5); }
.icon-button:hover { border-color: var(--brass-hi); }

/* ---- screens ---- */
.screen { position: fixed; inset: 0; z-index: 6; overflow: auto; overscroll-behavior: contain;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); }

/* title */
#title-menu { display: grid; align-items: center; text-align: center;
  background: radial-gradient(ellipse at 50% 42%, rgba(14,9,22,.18) 0%, rgba(14,9,22,.6) 55%, rgba(14,9,22,.8) 100%); }
.title-content { width: min(940px, 100%); margin: auto; padding: 14px 0; }
.eyebrow { font-family: var(--font-head); color: var(--brass-hi); letter-spacing: .24em; font-size: clamp(11px, 2.3vw, 15px); margin: 0 0 2px; text-shadow: 0 2px 0 rgba(0,0,0,.55); }
h1 { font-family: var(--font-head); font-weight: 400; color: var(--saffron-hi); font-size: clamp(32px, 11vw, 108px); max-width: 100%; line-height: 1; margin: 0 0 8px; letter-spacing: -.005em;
  transform: rotate(-2.5deg); display: inline-block;
  text-shadow: 0 3px 0 #9a4c12, 0 6px 0 #3a1a04, 0 14px 26px rgba(0,0,0,.6); }
.story { font-size: clamp(13px, 1.55vw, 16px); line-height: 1.55; color: #d9cfe3; max-width: 600px; margin: 12px auto 22px; }
.story strong { color: #fff; font-weight: 800; }
.menu-actions { display: grid; gap: 12px; width: min(760px, 100%); margin: 0 auto 18px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.menu-actions button { width: 100%; padding: 14px 10px; border-radius: 16px; }
.menu-actions small { display: block; font-family: var(--font-body); font-weight: 800; font-size: 11px; letter-spacing: .06em; opacity: .85; margin-top: 5px; text-transform: uppercase; text-shadow: none; }
.how-to { font-size: 13px; line-height: 1.7; color: #cfc4d8; max-width: 620px; margin: 0 auto 4px; }
.how-to strong { color: var(--brass-hi); font-family: var(--font-head); font-weight: 400; letter-spacing: .08em; }
.input-hint { font-size: 11px; color: var(--dim); line-height: 1.5; margin: 8px auto 0; }
@media (max-width: 719px) { .menu-actions { grid-template-columns: 1fr; width: min(340px, 100%); } }

/* pause / settings */
.modal { display: flex; align-items: flex-start; background: rgba(8,5,13,.72); z-index: 12; }
.panel { width: min(420px, 100%); margin: auto; padding: 22px 22px 18px; color: var(--cream);
  background: linear-gradient(#2e2637, #1f1927); border: 2px solid var(--brass-dk); border-radius: 18px;
  box-shadow: 0 0 0 1px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,235,200,.1), 0 24px 60px rgba(0,0,0,.6); }
.panel h2, #online h2 { font-family: var(--font-head); font-weight: 400; color: var(--brass-hi); text-align: center; margin: 0 0 6px; letter-spacing: .16em; font-size: 22px; text-shadow: 0 2px 0 rgba(0,0,0,.5); }
.panel > button { width: 100%; margin-top: 8px; }
.panel .muted { font-size: 13px; color: var(--muted); text-align: center; line-height: 1.45; margin: 0 0 10px; }
.panel fieldset { margin: 16px 0 10px; padding: 6px 12px 8px; border: 1px solid #58455f; border-radius: 10px; background: rgba(0,0,0,.18); }
.panel legend { font-family: var(--font-head); font-size: 12px; letter-spacing: .12em; color: var(--brass); padding: 0 8px; }
.panel label { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 42px; font-size: 14px; font-weight: 600; }
.panel input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--saffron); }
.panel select { background: #392a43; color: #fff; border: 1px solid var(--brass-dk); border-radius: 8px; min-height: 40px; padding: 4px 10px; font-weight: 700; }
.panel details { margin: 10px 0 4px; font-size: 13px; line-height: 1.55; color: #d6c9df; }
.panel summary { min-height: 44px; padding: 10px 0; cursor: pointer; color: var(--brass-hi); font-family: var(--font-head); letter-spacing: .08em; }
.panel details p { margin: 6px 0; }
.panel kbd { font-family: var(--font-body); font-weight: 800; background: #14101a; border: 1px solid #5e4d6b; border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; color: var(--cream); }

/* result buttons under the winner text */
#result-actions { position: fixed; z-index: 6; left: 50%; top: 64%; transform: translateX(-50%); width: min(360px, calc(100% - 32px)); display: flex; gap: 12px; justify-content: center; }
#result-actions button { flex: 1; }

/* ---- online lobby ---- */
#online { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 11; background: rgba(8,5,13,.7); overflow: auto; overscroll-behavior: contain;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
#online .card { width: min(440px, 100%); max-height: 100%; overflow: auto; padding: 22px 20px 18px; text-align: center;
  background: linear-gradient(#2e2637, #1f1927); border: 2px solid var(--brass-dk); border-radius: 18px;
  box-shadow: 0 0 0 1px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,235,200,.1), 0 24px 60px rgba(0,0,0,.6); }
#online p { margin: 6px 0 14px; color: var(--muted); font-size: 13px; line-height: 1.5; }
#online .row { display: flex; gap: 10px; justify-content: center; margin: 10px 0; flex-wrap: wrap; }
#online input { width: 170px; font-family: var(--font-head); font-size: 30px; letter-spacing: .38em; text-align: center; text-transform: uppercase; padding: 8px 4px 8px 16px;
  border-radius: 10px; border: 2px solid var(--brass-dk); background: #120b17; color: #fff; }
#online .code { font-family: var(--font-head); font-size: 52px; letter-spacing: .32em; color: #fff; margin: 6px 0 2px; padding-left: .32em; text-shadow: 0 3px 0 rgba(0,0,0,.5); }
#online .status { min-height: 18px; font-size: 13px; font-weight: 700; color: var(--brass-hi); }

/* ---- tuning panel (T) ---- */
#tweak { position: fixed; top: 12px; right: 12px; width: 260px; max-height: calc(100dvh - 24px); overflow-y: auto; max-width: calc(100vw - 24px); z-index: 13;
  background: rgba(24,18,30,.95); color: var(--cream); border: 1px solid var(--brass-dk); border-radius: 12px; padding: 12px 14px; font-size: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
#tweak h3 { margin: 0 0 8px; font-family: var(--font-head); font-weight: 400; font-size: 13px; letter-spacing: .14em; color: var(--brass-hi); }
#tweak label { display: grid; grid-template-columns: 1fr 44px; align-items: center; gap: 6px; margin: 6px 0; }
#tweak label span.v { text-align: right; color: var(--brass-hi); font-variant-numeric: tabular-nums; }
#tweak input[type=range] { grid-column: 1 / span 2; width: 100%; accent-color: var(--saffron); }
#tweak select, #tweak input[type=checkbox] { justify-self: end; }
#tweak select { background: #2a1d33; color: var(--cream); border: 1px solid var(--brass-dk); border-radius: 4px; font-size: 12px; }
#tweak .hint { color: #a89a7c; margin-top: 8px; line-height: 1.4; }
#tweak-close { float: right; padding: 0 4px !important; min-height: 30px !important; }

/* ---- touch controls ---- */
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 5; --button-size: 88px; --touch-bottom: max(12px, env(safe-area-inset-bottom)); }
#touch .tb { position: absolute; pointer-events: auto; width: var(--button-size); height: var(--button-size); min-height: 0; border-radius: 50%; padding: 8px; bottom: var(--touch-bottom);
  display: flex; flex-direction: column; gap: 2px; align-items: center; justify-content: center; touch-action: none; -webkit-user-select: none; user-select: none;
  color: #fff7e8; font-family: var(--font-head); font-size: 10px; letter-spacing: .12em;
  background: radial-gradient(circle at 35% 30%, #3b3246, #1a1421); border: 3px solid var(--player-color, var(--brass));
  box-shadow: 0 0 0 2px rgba(0,0,0,.5), 0 0 22px color-mix(in srgb, var(--player-color, var(--brass)) 45%, transparent), 0 6px 16px rgba(0,0,0,.5); }
#touch .tb.pressed { background: radial-gradient(circle at 35% 30%, #7a5b39, #4a3520); transform: scale(.94); }
#touch .tb svg { width: 38px; height: 38px; fill: currentColor; flex-shrink: 0; }
#touch .tb .turn-icon { fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
#touch .tb[data-next-dir="-1"] .turn-icon { transform: scaleX(-1); }
#touch .p1[data-a=turn] { left: max(20px, env(safe-area-inset-left)); }
#touch .p1[data-a=step] { right: max(20px, env(safe-area-inset-right)); }
#touch.local { --button-size: min(78px, calc((100vw - 60px) / 4)); }
#touch.local .p1[data-a=turn] { left: max(10px, env(safe-area-inset-left)); }
#touch.local .p1[data-a=step] { left: calc(max(10px, env(safe-area-inset-left)) + var(--button-size) + 8px); right: auto; }
#touch.local .p2[data-a=turn] { right: calc(max(10px, env(safe-area-inset-right)) + var(--button-size) + 8px); }
#touch.local .p2[data-a=step] { right: max(10px, env(safe-area-inset-right)); }
#touch.local .tb svg { width: 30px; height: 30px; }

/* ---- rotate hint (touch phones in portrait) ---- */
#rotate-hint { position: fixed; inset: 0; z-index: 14; display: grid; place-items: center; background: rgba(8,5,13,.86); text-align: center; padding: 24px; }
#rotate-hint .panel { max-width: 320px; }
#rotate-hint .phone { width: 46px; height: 82px; margin: 4px auto 14px; border: 3px solid var(--brass-hi); border-radius: 9px; position: relative; animation: rotate-phone 2.4s ease-in-out infinite; }
#rotate-hint .phone::after { content: ""; position: absolute; left: 50%; bottom: 5px; width: 8px; height: 8px; margin-left: -4px; border-radius: 50%; background: var(--brass-hi); }
@keyframes rotate-phone { 0%, 20% { transform: rotate(0); } 55%, 80% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }
#rotate-hint p { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0 0 14px; }

/* ---- short / small screens ---- */
@media (max-height: 520px) and (min-width: 600px) {
  .title-content { padding: 6px 0; }
  h1 { font-size: clamp(34px, 7.5vw, 64px); margin-bottom: 6px; }
  .story { display: none; }
  .menu-actions { margin: 14px auto 10px; gap: 10px; }
  .menu-actions button { padding: 10px 6px; font-size: 15px; }
  .menu-actions small { font-size: 10px; margin-top: 3px; }
  .how-to { font-size: 12px; line-height: 1.5; }
  .input-hint { margin-top: 4px; }
  #touch { --button-size: 76px; }
}
@media (max-height: 680px) and (max-width: 599px) {
  .title-content { padding: 4px 0; }
  h1 { margin-bottom: 8px; }
  .story { font-size: 12px; margin: 10px auto 14px; }
  .menu-actions { gap: 8px; margin-bottom: 12px; }
  .menu-actions button { padding: 10px 12px; font-size: 16px; }
  .how-to { font-size: 12px; }
  .input-hint { display: none; }
}
@media (prefers-reduced-motion: reduce) { #rotate-hint .phone { animation: none; transform: rotate(-90deg); } }
