:root {
  --ink: #17140f;
  --paper: #f2e6cc;
  --paper2: #f8f0de;
  --red: #c8102e;
  --gold: #e0a92e;
  --heavy: "Arial Black", "Helvetica Neue", Impact, system-ui, sans-serif;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper); color: var(--ink); font-family: var(--ui);
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
canvas#game { position: fixed; inset: 0; display: block; touch-action: none; }
.clip-canvas { position: fixed; left: -10000px; top: 0; width: 72px; height: 128px; pointer-events: none; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: inherit; }

/* HUD */
#hud { position: fixed; left: 0; right: 0; top: 0; padding: calc(env(safe-area-inset-top) + 8px) 8px 8px; display: flex; align-items: center; gap: 8px; pointer-events: none; }
#hud > * { pointer-events: auto; }
.icon { width: 44px; height: 44px; flex: none; border-radius: 50%; display: grid; place-items: center; }
.icon svg { width: 24px; height: 24px; fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.b-mute .x { display: none; }
.b-mute.off .x { display: inline; } .b-mute.off .wave { display: none; }
.side { flex: 1; min-width: 0; }
.side .nm { font: 800 12px/1.2 var(--ui); letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side.p1 .nm { text-align: right; }
.bar { height: 12px; margin-top: 4px; background: rgba(23,20,15,.14); border: 2px solid var(--ink); border-radius: 2px; overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; background: var(--ink); transition: width .25s; }
.p1 .bar { justify-content: flex-end; }
.bar.flash { animation: flash .35s; }
@keyframes flash { 0%, 60% { border-color: var(--red); transform: scale(1.04); } 100% { border-color: var(--ink); transform: none; } }
.mid { text-align: center; flex: none; min-width: 70px; }
#clock { font: 900 18px/1 var(--heavy); font-variant-numeric: tabular-nums; }
#speed { font: 700 10px/1.4 var(--ui); letter-spacing: .08em; text-transform: uppercase; color: var(--red); }

#hint { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 22px); transform: translateX(-50%); max-width: calc(100% - 32px);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 999px; font: 700 15px/1.3 var(--ui); text-align: center; pointer-events: none;
  animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translate(-50%, -4px); } }

/* stamps */
.stamp { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%) rotate(-6deg) scale(.4); opacity: 0; pointer-events: none;
  font: 900 clamp(48px, 16vw, 120px)/1 var(--heavy); color: var(--paper); background: var(--red); padding: .12em .3em .08em; border-radius: 6px;
  box-shadow: 0 0 0 4px var(--paper), 0 0 0 8px var(--red); }
.stamp.show { animation: stamp 1.5s cubic-bezier(.2,1.6,.4,1) forwards; }
.stamp.fight { background: var(--ink); box-shadow: 0 0 0 4px var(--paper), 0 0 0 8px var(--ink); }
.stamp.lose { background: var(--ink); box-shadow: 0 0 0 4px var(--paper), 0 0 0 8px var(--ink); }
@keyframes stamp { 0% { opacity: 0; transform: translate(-50%, -50%) rotate(-6deg) scale(2.2); } 12% { opacity: 1; transform: translate(-50%, -50%) rotate(-6deg) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -50%) rotate(-6deg) scale(1); } }

#toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translate(-50%, 20px); opacity: 0; transition: .25s;
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 10px; font: 600 14px var(--ui); pointer-events: none; z-index: 20; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* VS card */
#vs { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; pointer-events: none;
  background: linear-gradient(transparent 25%, rgba(242,230,204,.92) 40%, rgba(242,230,204,.92) 60%, transparent 75%); animation: vs .4s ease-out; }
.vs-you { font: 900 28px var(--heavy); }
.vs-v { font: 900 18px var(--heavy); color: var(--red); margin: 4px 0; }
#vs-name { font: 900 clamp(30px, 9vw, 54px)/1 var(--heavy); }
#vs-tag { font: italic 600 16px var(--ui); margin-top: 8px; opacity: .75; padding: 0 20px; }
@keyframes vs { from { opacity: 0; transform: scale(1.1); } }

/* screens */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 12px); overflow-y: auto; }
#pause, #result { background: rgba(242,230,204,.55); }
.panel { width: 100%; max-width: 400px; background: rgba(248,240,222,.88); border: 3px solid var(--ink); border-radius: 14px; padding: 20px 20px 14px; text-align: center;
  box-shadow: 6px 6px 0 var(--ink); margin: auto; }
.panel.small { max-width: 300px; }
.logo { margin: 0; font: 900 clamp(40px, 13vw, 64px)/1 var(--heavy); display: flex; justify-content: center; align-items: center; gap: 10px; letter-spacing: -.02em; }
.logo b { background: var(--red); color: var(--paper); padding: 6px 10px 2px; border-radius: 4px; transform: rotate(-4deg); box-shadow: 0 0 0 3px var(--paper2), 0 0 0 6px var(--red); }
.tag { font: 700 17px/1.3 var(--ui); margin: 14px 0 16px; }
button.big { display: block; width: 100%; min-height: 56px; background: var(--red); color: var(--paper); font: 900 26px/1 var(--heavy); letter-spacing: .04em;
  border-radius: 10px; padding: 12px; box-shadow: 0 4px 0 #7d0a1d; transition: transform .08s; }
button.big:active { transform: translateY(3px); box-shadow: 0 1px 0 #7d0a1d; }
button.big:disabled { opacity: .6; }
button.big small { display: block; font: 700 13px/1.4 var(--ui); letter-spacing: .02em; margin-top: 4px; opacity: .9; }
#ladder { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 14px 0 6px; }
.rung { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 10px; border: 2px solid var(--ink); border-radius: 8px; background: var(--paper2); text-align: left; font: 700 13px/1.15 var(--ui); }
.rung i { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.rung .nm { flex: 1; min-width: 0; }
.rung .bt { font: 800 11px var(--ui); color: var(--red); white-space: nowrap; }
.rung.won .nm::after { content: " ✓"; color: var(--red); }
.rung.locked { opacity: .45; cursor: default; }
.how { font: 500 14px/1.45 var(--ui); margin: 12px 0 8px; }
.panel footer { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 4px 14px; font: 600 13px var(--ui); margin-top: 10px; opacity: .85; }
.panel footer .icon { width: 40px; height: 40px; }
.panel h2 { font: 900 40px/1 var(--heavy); margin: 4px 0 10px; }
#r-title.win { color: var(--red); }
#r-move { font: 800 19px/1.3 var(--ui); margin: 0 0 6px; }
#r-time { font: 500 15px/1.4 var(--ui); margin: 0 0 12px; }
#r-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; }
#r-stats div { border: 2px solid var(--ink); border-radius: 8px; padding: 6px 4px; background: var(--paper2); }
#r-stats b { display: block; font: 900 18px var(--heavy); }
#r-stats span { font: 600 11px var(--ui); opacity: .75; }
#r-extra { font: 800 14px var(--ui); color: var(--red); min-height: 1em; margin: 0 0 10px; }
.row { display: flex; gap: 8px; margin-top: 8px; }
.row button, #pause button:not(.big) { flex: 1; min-height: 48px; border: 2px solid var(--ink); border-radius: 10px; font: 800 15px var(--ui); background: var(--paper2); }
#pause button:not(.big) { width: 100%; margin-top: 8px; }
button.link { margin-top: 8px; min-height: 44px; padding: 0 16px; font: 700 14px var(--ui); text-decoration: underline; }

@media (max-height: 640px) {
  .logo { font-size: 48px; }
  .tag { margin: 8px 0 10px; font-size: 15px; }
  .how { display: none; }
  #ladder { margin: 10px 0 4px; }
}
@media (min-width: 900px) and (min-height: 600px) {
  #menu { justify-content: flex-start; padding-left: 6vw; }
  #menu .panel { margin: auto 0; }
}
