:root {
  color-scheme: light;
  --paper: #ece8de;
  --paper-soft: rgba(247, 244, 236, .92);
  --ink: #202321;
  --muted: #6c706b;
  --line: rgba(32, 35, 33, .17);
  --coral: #ff5a3c;
  --cyan: #35cada;
  --lime: #b9df48;
  --yellow: #ffc84a;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body { background: var(--paper); color: var(--ink); touch-action: none; -webkit-tap-highlight-color: transparent; }
button, a { color: inherit; font: inherit; }
button { border: 0; }
[hidden] { display: none !important; }

.game-shell { position: relative; width: 100%; height: 100%; height: 100svh; overflow: hidden; isolation: isolate; }
#game { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; }

.topbar {
  position: absolute;
  z-index: 5;
  top: 0;
  left: 0;
  display: grid;
  width: 100%;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: max(14px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 8px max(18px, env(safe-area-inset-left));
  pointer-events: none;
}

.wordmark { display: inline-flex; width: max-content; align-items: center; gap: 9px; color: var(--ink); font-size: .64rem; font-weight: 1000; letter-spacing: .13em; line-height: .8; text-decoration: none; pointer-events: auto; }
.mark { position: relative; display: block; width: 27px; height: 26px; }
.mark i { position: absolute; display: block; width: 18px; height: 6px; border-radius: 2px; background: var(--ink); }
.mark i:nth-child(1) { top: 1px; left: 0; background: var(--coral); }
.mark i:nth-child(2) { top: 10px; left: 7px; }
.mark i:nth-child(3) { top: 19px; left: 1px; background: var(--cyan); }

.status { display: grid; min-width: 116px; justify-items: center; padding: 7px 16px; border: 1px solid var(--line); border-radius: 99px; background: rgba(236, 232, 222, .77); box-shadow: 0 7px 24px rgba(32,35,33,.06); backdrop-filter: blur(10px); }
.status span { color: var(--coral); font-size: .52rem; font-weight: 950; letter-spacing: .22em; }
.status strong { margin-top: 1px; font-size: .72rem; font-variant-numeric: tabular-nums; letter-spacing: .05em; }
.status.is-run span { color: var(--cyan); }
.status.is-urgent { border-color: var(--coral); animation: urgent 700ms ease-in-out infinite alternate; }

.level-actions { justify-self: end; display: flex; gap: 6px; pointer-events: auto; }
.level-actions button { min-height: 34px; padding: 0 11px; border: 1px solid var(--line); border-radius: 3px; background: rgba(236,232,222,.76); color: var(--muted); cursor: pointer; font-size: .51rem; font-weight: 900; letter-spacing: .09em; backdrop-filter: blur(9px); transition: transform 130ms ease, background 130ms ease, color 130ms ease; }
.level-actions button:hover { color: var(--ink); background: #f8f5ed; transform: translateY(-1px); }

.brief { position: absolute; z-index: 3; top: 84px; left: max(18px, env(safe-area-inset-left)); display: grid; gap: 4px; width: 232px; padding: 12px 13px; border-left: 3px solid var(--coral); background: rgba(236,232,222,.79); color: var(--muted); font-size: .58rem; font-weight: 700; line-height: 1.35; pointer-events: none; backdrop-filter: blur(7px); transition: opacity 280ms ease, transform 280ms ease; }
.brief b { margin-bottom: 2px; color: var(--ink); font-size: .55rem; letter-spacing: .16em; }
.brief.is-dismissed { opacity: 0; transform: translateX(-8px); }
kbd { display: inline-grid; min-width: 19px; height: 19px; padding: 0 4px; place-items: center; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 3px; background: rgba(255,255,255,.45); color: var(--ink); font: 850 .56rem ui-monospace, monospace; }

.mode-dock { position: absolute; z-index: 6; bottom: max(38px, env(safe-area-inset-bottom)); left: 50%; display: flex; gap: 5px; padding: 5px; border: 1px solid var(--line); border-radius: 7px; background: rgba(244,241,233,.88); box-shadow: 0 12px 34px rgba(32,35,33,.12); backdrop-filter: blur(10px); transform: translateX(-50%); transition: opacity 180ms ease, transform 180ms ease; }
.mode-dock.is-locked { opacity: .36; transform: translateX(-50%) translateY(5px); pointer-events: none; }
.mode { display: flex; min-width: 86px; min-height: 42px; padding: 4px 9px; align-items: center; gap: 8px; border-radius: 3px; background: transparent; color: var(--muted); cursor: pointer; font-size: .58rem; font-weight: 950; letter-spacing: .1em; }
.mode i { display: grid; width: 27px; height: 27px; place-items: center; border: 1px solid var(--line); border-radius: 3px; font-size: .85rem; font-style: normal; }
.mode small { color: #999c96; font-size: .48rem; }
.mode.is-active { background: var(--ink); color: white; }
.mode[data-mode="pull"].is-active i { background: var(--cyan); color: var(--ink); }
.mode[data-mode="push"].is-active i { background: var(--yellow); color: var(--ink); }

.desktop-help { position: absolute; z-index: 4; right: 18px; bottom: max(18px, env(safe-area-inset-bottom)); color: var(--muted); font-size: .51rem; font-weight: 850; letter-spacing: .08em; pointer-events: none; }
.desktop-help kbd { margin-inline: 1px; }

.touch-controls { display: none; }
.announcement { position: absolute; z-index: 8; top: 50%; left: 50%; color: var(--ink); font-size: clamp(4rem, 18vw, 9rem); font-weight: 1000; letter-spacing: -.08em; line-height: .8; pointer-events: none; text-shadow: 5px 6px 0 rgba(255,255,255,.72); transform: translate(-50%, -50%); }
.announcement.pop { animation: pop 450ms ease-out both; }
.toast { position: absolute; z-index: 20; top: 72px; left: 50%; padding: 9px 13px; border-radius: 3px; background: var(--ink); color: white; font-size: .56rem; font-weight: 900; letter-spacing: .12em; opacity: 0; pointer-events: none; transform: translate(-50%, -8px); transition: opacity 180ms ease, transform 180ms ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.complete { position: absolute; z-index: 15; inset: 0; display: grid; padding: 20px; place-items: center; background: rgba(32,35,33,.2); backdrop-filter: blur(7px); animation: reveal 250ms ease both; }
.complete-card { width: min(100%, 430px); padding: clamp(26px, 7vw, 43px); border: 1px solid var(--ink); border-radius: 3px; background: var(--paper-soft); box-shadow: 11px 12px 0 rgba(32,35,33,.17); }
.eyebrow { margin: 0 0 8px; color: var(--cyan); font-size: .58rem; font-weight: 1000; letter-spacing: .22em; }
.complete h1 { margin: 0; font-size: clamp(2.8rem, 11vw, 5rem); font-weight: 1000; letter-spacing: -.075em; line-height: .78; }
.complete h1 span { color: var(--coral); }
.results { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 29px; border-block: 1px solid var(--line); }
.results div { display: grid; gap: 3px; padding: 13px 8px; text-align: center; }
.results div + div { border-left: 1px solid var(--line); }
.results small { color: var(--muted); font-size: .5rem; font-weight: 900; letter-spacing: .13em; }
.results strong { font-size: .9rem; font-variant-numeric: tabular-nums; }
.complete-actions { display: grid; grid-template-columns: 1fr 1.25fr; gap: 7px; margin-top: 24px; }
.complete-actions button { min-height: 50px; border: 1px solid var(--ink); border-radius: 2px; background: transparent; cursor: pointer; font-size: .61rem; font-weight: 950; letter-spacing: .09em; }
.complete-actions .primary { display: flex; padding-inline: 17px; align-items: center; justify-content: space-between; background: var(--ink); color: white; }
.complete-actions .primary span { color: var(--cyan); font-size: 1.1rem; }
.text-button { display: block; margin: 14px auto 0; padding: 5px; background: transparent; color: var(--muted); cursor: pointer; font-size: .52rem; font-weight: 900; letter-spacing: .12em; }

@keyframes reveal { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -50%) scale(.65); } 55% { opacity: 1; } to { opacity: 0; transform: translate(-50%, -50%) scale(1.08); } }
@keyframes urgent { to { box-shadow: 0 0 0 4px rgba(255,90,60,.13); } }

@media (pointer: coarse), (max-width: 740px) {
  .topbar { padding-inline: 11px; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
  .wordmark > span:last-child { display: none; }
  .level-actions { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 11px; gap: 4px; }
  .level-actions button { width: 32px; min-height: 32px; padding: 0; overflow: hidden; color: transparent; font-size: 0; }
  .level-actions button::after { color: var(--ink); font-size: .8rem; }
  #reset-button::after { content: "\21BA"; }
  #reroll-button::after { content: "\2726"; }
  #share-button::after { content: "\2197"; }
  .brief { top: 66px; left: 11px; width: 205px; padding: 9px 10px; font-size: .53rem; }
  .desktop-help { display: none; }
  .mode-dock { bottom: max(12px, env(safe-area-inset-bottom)); }
  .mode { min-width: 65px; min-height: 39px; padding: 3px 7px; }
  .mode i { width: 26px; height: 26px; }
  .mode span { font-size: 0; }
  .mode span::first-letter { font-size: 0; }
  .mode small { display: none; }
  .touch-controls { position: absolute; z-index: 7; right: max(10px, env(safe-area-inset-right)); bottom: max(9px, env(safe-area-inset-bottom)); left: max(10px, env(safe-area-inset-left)); display: flex; align-items: end; justify-content: space-between; pointer-events: none; }
  .touch-move { display: flex; gap: 7px; pointer-events: auto; }
  .touch-controls button { display: grid; width: 58px; height: 58px; padding: 0; place-items: center; border: 1px solid rgba(32,35,33,.2); border-radius: 50%; background: rgba(244,241,233,.84); box-shadow: 0 7px 23px rgba(32,35,33,.12); color: var(--ink); font-size: 1.1rem; font-weight: 900; touch-action: none; backdrop-filter: blur(8px); }
  .touch-controls button.is-pressed { background: var(--ink); color: white; transform: scale(.95); }
  .touch-jump { position: absolute; right: 0; bottom: 0; pointer-events: auto; }
  .touch-jump span { font-size: .48rem; letter-spacing: .08em; }
  .touch-jump b { display: none; }
}

@media (pointer: coarse) and (orientation: portrait), (max-width: 600px) and (orientation: portrait) {
  .mode-dock { left: 50%; bottom: max(82px, calc(env(safe-area-inset-bottom) + 70px)); }
  .touch-controls { bottom: max(11px, env(safe-area-inset-bottom)); }
}

@media (max-height: 500px) {
  .brief { display: none; }
  .mode-dock { bottom: 8px; }
  .touch-controls button { width: 48px; height: 48px; }
  .touch-controls { bottom: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
