/* Wind-Up. One deliberate look: a dark workshop, with paper and print the colours of a lithographed tin toy box.
   Layout: full-bleed canvas; a tool row bottom-left; a tag top-left; the bench as a right-hand catalogue page. */
:root {
  --night: #0d0a08;
  --paper: #f3ead6;
  --paper-2: #e8dcc0;
  --ink: #22406e;
  --tomato: #b8462f;
  --brass: #c9a24a;
  --cream: #f1e6cf;
  --smoke: rgba(18, 13, 10, 0.74);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "URW Palladio L", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--night); color: var(--cream); font: 15px/1.45 var(--sans); overflow: hidden; }
canvas#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; outline: none; }
canvas#view:active { cursor: grabbing; }
.layer { position: fixed; z-index: 2; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

/* title */
#title { inset: 0; display: grid; place-items: center; background: radial-gradient(ellipse at 50% 55%, rgba(13,10,8,0.35), rgba(13,10,8,0.86) 70%); transition: opacity 0.9s ease; padding: 16px; }
#title.gone { opacity: 0; pointer-events: none; }
#title .card { text-align: center; max-width: 34rem; }
.kicker { font: 600 0.72rem/1 var(--sans); letter-spacing: 0.32em; text-transform: uppercase; color: var(--brass); margin: 0 0 1.1rem; }
#title h1 { font: 400 clamp(3.4rem, 9vw, 6.6rem)/0.95 var(--serif); letter-spacing: 0.01em; margin: 0; color: var(--paper); text-wrap: balance; }
#title .sub { font: italic 1.25rem/1.4 var(--serif); margin: 1rem 0 1.8rem; color: var(--cream); }
.go { background: var(--tomato); color: var(--paper); border: 0; border-radius: 999px; padding: 0.85rem 2.1rem; font-weight: 600; letter-spacing: 0.04em; box-shadow: 0 0 0 1px rgba(255,255,255,0.08), 0 10px 30px rgba(184,70,47,0.35); }
.go:disabled { background: #5b4639; box-shadow: none; cursor: default; }
.go:not(:disabled):hover { filter: brightness(1.08); }
#title .small { font-size: 0.82rem; color: rgba(241,230,207,0.66); margin-top: 1.4rem; }

/* tool row */
#hud { left: max(16px, env(safe-area-inset-left, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); right: max(16px, env(safe-area-inset-right, 0px)); display: flex; flex-wrap: wrap; gap: 8px; pointer-events: none; }
#hud button { pointer-events: auto; background: var(--smoke); border: 1px solid rgba(201,162,74,0.38); border-radius: 999px; padding: 0.5rem 1rem; font-size: 0.86rem; backdrop-filter: blur(6px); }
#hud button:hover { border-color: var(--brass); }
#hud button.primary { background: var(--tomato); border-color: transparent; color: var(--paper); font-weight: 600; }
#hud button[aria-pressed="true"] { background: var(--brass); color: var(--night); }

/* the arena picker, above the tool row */
#arenas { left: max(16px, env(safe-area-inset-left, 0px)); bottom: calc(var(--hud-h, 54px) + 26px + env(safe-area-inset-bottom, 0px)); width: min(22rem, calc(100vw - 32px)); background: var(--paper); color: var(--ink); border-radius: 10px; padding: 0.8rem 0.8rem 0.6rem; box-shadow: 0 14px 40px rgba(0,0,0,0.5); z-index: 3; max-height: calc(100vh - var(--hud-h, 54px) - 60px - env(safe-area-inset-bottom, 0px)); overflow-y: auto; overscroll-behavior: contain; }
.arenas-h { font: 700 0.68rem/1 var(--sans); letter-spacing: 0.2em; text-transform: uppercase; margin: 0.1rem 0.2rem 0.6rem; color: var(--tomato); }
.arena-opt { display: block; width: 100%; text-align: left; background: transparent; color: var(--ink); border: 1.5px solid rgba(34,64,110,0.35); border-radius: 8px; padding: 0.55rem 0.75rem; margin: 0 0 0.45rem; }
.arena-opt:hover { border-color: var(--ink); }
.arena-opt[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.arena-name { display: block; font: 600 1.05rem/1.2 var(--serif); }
.arena-desc { display: block; font-size: 0.78rem; line-height: 1.35; margin-top: 0.15rem; opacity: 0.85; }

/* the tag for a chosen creature */
#tag { top: calc(16px + env(safe-area-inset-top, 0px)); left: max(16px, env(safe-area-inset-left, 0px)); width: min(19rem, calc(100vw - 32px)); background: var(--paper); color: var(--ink); border-radius: 6px 18px 6px 6px; padding: 0.9rem 1rem 0.85rem; box-shadow: 0 12px 34px rgba(0,0,0,0.45); }
#tag::before { content: ""; position: absolute; top: 12px; right: 14px; width: 9px; height: 9px; border-radius: 50%; background: var(--night); box-shadow: inset 0 0 0 2px var(--brass); }
.tag-name { font: 600 1.28rem/1.15 var(--serif); margin: 0 1.4rem 0.2rem 0; }
.tag-desc { font-size: 0.8rem; margin: 0 0 0.7rem; color: #3c557f; }
.spring { height: 6px; background: var(--paper-2); border-radius: 3px; overflow: hidden; }
.spring span { display: block; height: 100%; background: linear-gradient(90deg, var(--brass), #e1bf6a); transform-origin: left; transform: scaleX(0); }
.tag-spring { font: 0.72rem/1 var(--mono); letter-spacing: 0.04em; text-transform: uppercase; margin: 0.4rem 0 0.75rem; color: #5a6f93; font-variant-numeric: tabular-nums; }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-row button { background: transparent; color: var(--ink); border: 1px solid rgba(34,64,110,0.45); border-radius: 999px; padding: 0.3rem 0.75rem; font-size: 0.8rem; }
.tag-row button:hover { background: var(--ink); color: var(--paper); }
.tag-state { font: italic 0.9rem/1.3 var(--serif); margin: -0.35rem 0 0.6rem; color: #8a3a22; }
.tag-stand { display: block; width: 100%; margin: 0 0 0.7rem; background: var(--tomato); color: var(--paper); border: 0; border-radius: 999px; padding: 0.45rem 0.9rem; font-size: 0.86rem; font-weight: 600; }
.tag-stand:hover { background: #a93a22; }
.tag-hurt { font: italic 0.9rem/1.3 var(--serif); margin: -0.35rem 0 0.6rem; color: #6b3d8a; }
.tag-stand[hidden], .tag-state[hidden], .tag-hurt[hidden] { display: none; }

/* the bench: a catalogue page */
#bench { top: 0; right: 0; bottom: 0; width: min(24rem, 100vw); background: var(--paper); color: var(--ink); display: flex; flex-direction: column; box-shadow: -18px 0 50px rgba(0,0,0,0.5); padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
#bench header { padding: 1.1rem 1.25rem 0.7rem; padding-right: max(1.25rem, env(safe-area-inset-right, 0px)); border-bottom: 2px solid var(--ink); position: relative; }
#bench .no { font: 700 0.7rem/1 var(--sans); letter-spacing: 0.24em; text-transform: uppercase; color: var(--tomato); margin: 0 0 0.45rem; }
#bench h2 { font: 400 1.75rem/1.08 var(--serif); margin: 0 0 0.3rem; text-wrap: balance; }
#bench .desc { font-size: 0.8rem; margin: 0; color: #3c557f; min-height: 2.3em; }
.link { background: none; border: 0; padding: 0; color: var(--tomato); text-decoration: underline; text-underline-offset: 3px; font-size: 0.78rem; position: absolute; top: 1.05rem; right: 1.25rem; }
#blueprint { display: block; width: 100%; height: 160px; border-bottom: 1px solid rgba(34,64,110,0.3); flex: none; }
#opts { flex: 1; overflow-y: auto; padding: 0.4rem 1.25rem 1rem; overscroll-behavior: contain; scrollbar-color: rgba(34,64,110,0.4) transparent; }
.grp { padding: 0.65rem 0 0.5rem; border-bottom: 1px dashed rgba(34,64,110,0.22); }
.grp h3 { font: 700 0.68rem/1 var(--sans); letter-spacing: 0.2em; text-transform: uppercase; margin: 0 0 0.5rem; color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { background: transparent; border: 1.5px solid rgba(34,64,110,0.5); color: var(--ink); border-radius: 999px; padding: 0.26rem 0.7rem; font-size: 0.82rem; }
.chip:hover { border-color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.range { display: grid; grid-template-columns: auto 1fr auto; gap: 0.6rem; align-items: center; font-size: 0.76rem; color: #3c557f; }
.range input { width: 100%; accent-color: var(--tomato); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.sw { width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(34,64,110,0.25); padding: 0; }
.sw[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--ink); }
#bench footer { padding: 0.85rem 1.25rem 1rem; border-top: 2px solid var(--ink); background: var(--paper-2); display: grid; gap: 8px; }
#bench footer .row { display: flex; gap: 8px; }
#bench footer .row button { flex: 1; }
#bench footer button { border-radius: 999px; padding: 0.55rem 0.9rem; border: 1.5px solid var(--ink); background: transparent; color: var(--ink); font-size: 0.86rem; }
#bench footer button.primary { background: var(--tomato); border-color: var(--tomato); color: var(--paper); font-weight: 600; font-size: 0.95rem; padding: 0.7rem 1rem; }

/* hint and toast */
#hint { left: 50%; bottom: calc(var(--hud-h, 54px) + 26px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); max-width: min(36rem, calc(100vw - 32px)); text-align: center; pointer-events: none; opacity: 0; transition: opacity 0.6s ease; }
#hint.on { opacity: 1; }
#hint span { display: inline-block; background: var(--smoke); border-radius: 12px; padding: 0.55rem 1rem; font: italic 1rem/1.4 var(--serif); color: var(--cream); }
#toast { top: calc(16px + env(safe-area-inset-top, 0px)); left: 50%; transform: translate(-50%, -8px); background: var(--brass); color: var(--night); padding: 0.5rem 1rem; border-radius: 999px; font-size: 0.86rem; font-weight: 600; opacity: 0; transition: opacity 0.3s ease, transform 0.3s ease; pointer-events: none; max-width: calc(100vw - 32px); text-align: center; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* notes */
#notes { inset: 0; display: grid; place-items: center; background: rgba(8,6,5,0.6); padding: 16px; z-index: 5; }
#notes .card { position: relative; background: var(--paper); color: var(--ink); max-width: 40rem; max-height: calc(100vh - 32px); overflow-y: auto; border-radius: 8px; padding: 1.6rem 1.8rem 1.4rem; box-shadow: 0 20px 60px rgba(0,0,0,0.6); }
#notes h2 { font: 400 1.7rem/1.1 var(--serif); margin: 0 0 0.8rem; }
#notes h3 { font: 700 0.7rem/1 var(--sans); letter-spacing: 0.2em; text-transform: uppercase; color: var(--tomato); margin: 1.2rem 0 0.4rem; }
#notes p, #notes li { font-size: 0.92rem; max-width: 65ch; }
#notes ul { padding-left: 1.1rem; margin: 0; }
#notes li { margin: 0.35rem 0; }
#notes .fine { font-size: 0.8rem; color: #3c557f; margin-top: 1.1rem; }
.close { position: absolute; top: 0.6rem; right: 0.8rem; background: none; border: 0; font-size: 1.7rem; line-height: 1; color: var(--ink); }

#fail { inset: 0; display: grid; place-items: center; padding: 16px; }
#fail .card { max-width: 30rem; text-align: center; }
#fail h1 { font: 400 3rem/1 var(--serif); }

@media (max-width: 720px) {
  #bench { top: auto; width: 100vw; height: 62vh; border-radius: 14px 14px 0 0; }
  #blueprint { height: 110px; }
  #hud button { padding: 0.45rem 0.8rem; font-size: 0.8rem; }
}
@media (prefers-reduced-motion: reduce) {
  #title, #hint, #toast { transition: none; }
}
