@font-face {
  font-family: 'AnotherTag';
  src: url('../AnotherTag.woff') format('woff');
  font-display: swap;
}

:root {
  --bg: #0d0d0f;
  --fg: #f2f0ea;
  --muted: #8d8a84;
  --surface: rgba(18, 18, 20, 0.72);
  --line: rgba(242, 240, 234, 0.14);
  --paint: #ff3d9a;            /* live: set to the selected can colour */
  --danger: #ff5a4a;
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --r: 14px;
  --ui: 'Jura', system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--ui);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

canvas#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}

a { color: var(--fg); text-underline-offset: 3px; }
a:hover { color: var(--paint); }

button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--paint); outline-offset: 3px; }

.tag {
  font-family: 'AnotherTag', cursive;
  font-weight: normal;
  line-height: 0.9;
  margin: 0;
  color: var(--fg);
}

/* ---------- screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  overflow-y: auto;
  touch-action: pan-y;
}
.screen[hidden] { display: none; }

#intro {
  background:
    radial-gradient(120% 80% at 50% 110%, rgba(0,0,0,0.9), transparent 60%),
    linear-gradient(to bottom, rgba(13,13,15,0.55), rgba(13,13,15,0.82));
  transition: opacity 0.6s var(--ease-out-expo);
}
#intro.is-leaving { opacity: 0; pointer-events: none; }

.intro__inner {
  width: min(640px, 100%);
  text-align: center;
}

#intro .tag {
  font-size: clamp(3.6rem, 13vw, 9rem);
  text-shadow: 0 0 40px rgba(0,0,0,0.6);
  transform: rotate(-3deg);
}

.intro__by {
  margin: 0.6rem 0 0;
  letter-spacing: 0.35em;
  font-size: 0.8rem;
  color: var(--muted);
}

.intro__lede {
  margin: 1.6rem auto 2rem;
  max-width: 34ch;
  font-size: clamp(1rem, 0.95rem + 0.3vw, 1.15rem);
  line-height: 1.5;
}

.intro__foot {
  margin-top: 2rem;
  font-size: 0.85rem;
  color: var(--muted);
}

/* ---------- buttons ---------- */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 48px;
  padding: 0 1.4rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.06);
  font-weight: 600;
  letter-spacing: 0.04em;
  overflow: hidden;
  transition: transform 0.25s var(--ease-out-expo), background 0.2s, border-color 0.2s;
}
.btn:hover:not(:disabled) { border-color: var(--fg); }
.btn:active:not(:disabled) { transform: scale(0.97); }

.btn--primary {
  min-width: 260px;
  min-height: 56px;
  font-size: 1.05rem;
  background: var(--fg);
  color: var(--bg);
  border-color: transparent;
}
.btn--primary:hover:not(:disabled) { background: #fff; border-color: transparent; }
.btn--primary:disabled {
  background: rgba(255,255,255,0.1);
  color: var(--fg);
  cursor: progress;
}
.btn__fill {
  position: absolute;
  inset: 0;
  transform-origin: left;
  transform: scaleX(0);
  background: var(--paint);
  opacity: 0.45;
  transition: transform 0.3s ease-out;
}
.btn:not(:disabled) .btn__fill { display: none; }
.btn__label { position: relative; }

.btn--danger:hover { border-color: var(--danger); color: var(--danger); }

/* ---------- key legend ---------- */
.keys {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem 1.5rem;
  margin: 2.2rem auto 0;
  max-width: 460px;
  text-align: left;
  font-size: 0.85rem;
}
.keys div { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 1px solid var(--line); padding-bottom: 0.4rem; }
.keys dt { font-weight: 700; }
.keys dd { margin: 0; color: var(--muted); text-align: right; }
.keys--touch { display: none; text-align: center; color: var(--muted); }

body.touch #keys-desktop { display: none; }
body.touch .keys--touch { display: block; }

/* ---------- pause ---------- */
.screen--pause { background: rgba(8,8,10,0.55); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }

.panel {
  width: min(420px, 100%);
  padding: 28px 24px 22px;
  border-radius: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  display: grid;
  gap: 18px;
}
.panel .tag--sm { font-size: 3.2rem; text-align: center; transform: rotate(-2deg); }
.panel .btn--primary { width: 100%; min-width: 0; }
.panel__row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.panel__row .btn { padding: 0 0.8rem; font-size: 0.9rem; }
.panel__foot { margin: 0; font-size: 0.78rem; color: var(--muted); text-align: center; }

.field { display: grid; gap: 8px; font-size: 0.9rem; }
.field__label { color: var(--muted); font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase; }
.field--row { display: flex; align-items: center; gap: 10px; }
.field input[type=range] { width: 100%; accent-color: var(--paint); }
.field input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--paint); }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: none; border-radius: 999px; min-height: 38px; font-weight: 600; color: var(--muted); }
.seg button[aria-checked=true] { background: var(--fg); color: var(--bg); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud[hidden] { display: none; }
#hud button { pointer-events: auto; }

.hud__brand {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 18px;
  font-size: 1.9rem;
  opacity: 0.85;
  transform: rotate(-3deg);
  text-shadow: 0 2px 10px rgba(0,0,0,0.6);
}

.online {
  position: absolute;
  top: calc(max(14px, env(safe-area-inset-top)) + 44px);
  left: 20px;
  display: flex; align-items: center; gap: 6px;
  font-size: 0.78rem; letter-spacing: 0.06em;
  text-shadow: 0 1px 6px rgba(0,0,0,0.9);
}
.online[hidden] { display: none; }
.online i { width: 8px; height: 8px; border-radius: 50%; background: #3ddc84; box-shadow: 0 0 0 3px rgba(61,220,132,0.25); }
.online.is-off i { background: var(--danger); box-shadow: 0 0 0 3px rgba(255,90,74,0.25); }
body.touch .online { top: max(18px, env(safe-area-inset-top)); left: 16px; }
body.erasing .ch__ring { border-style: dashed; border-color: #fff; }
body.erasing .spray-btn { background: #56606a; }

.hud__top {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  display: flex;
  gap: 8px;
}
.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: var(--fg); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { border-color: var(--fg); }

#crosshair {
  position: absolute;
  left: 50%; top: 50%;
  width: 0; height: 0;
}
.ch__dot {
  position: absolute; left: -2px; top: -2px;
  width: 4px; height: 4px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.6);
}
.ch__ring {
  position: absolute;
  left: 0; top: 0;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1.5px solid var(--paint);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.35), inset 0 0 0 1px rgba(0,0,0,0.35);
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 0.15s;
}
#crosshair.can-paint .ch__ring { opacity: 0.85; }

.hud__bottom {
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: grid;
  justify-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100vw - 24px);
}

.palette {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow-x: auto;
  max-width: 100%;
  scrollbar-width: none;
}
.palette::-webkit-scrollbar { display: none; }
.swatch {
  flex: none;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.35);
  background: var(--c);
  transition: transform 0.25s var(--ease-out-expo), box-shadow 0.2s;
}
.swatch:hover { transform: translateY(-2px); }
.swatch[aria-checked=true] {
  transform: translateY(-4px) scale(1.18);
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--fg);
}

.caps {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.caps button {
  display: flex; align-items: center; gap: 6px;
  border: 0; background: none;
  padding: 5px 12px 5px 8px;
  border-radius: 999px;
  font-size: 0.8rem; font-weight: 600;
  color: var(--muted);
}
.caps button[aria-checked=true] { background: rgba(255,255,255,0.12); color: var(--fg); }
.hud__row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.tools svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
body.touch .tools span { display: none; }

.cap { display: block; border-radius: 50%; background: var(--paint); }
.cap--s { width: 5px; height: 5px; }
.cap--m { width: 9px; height: 9px; }
.cap--l { width: 14px; height: 14px; filter: blur(0.6px); }

.colorname {
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-shadow: 0 1px 6px rgba(0,0,0,0.9);
  min-height: 1em;
}

/* ---------- touch ---------- */
.stick, .spray-btn, .jump-btn { display: none; }
body.touch .stick {
  display: block;
  position: absolute;
  left: max(22px, env(safe-area-inset-left));
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 110px);
  width: 120px; height: 120px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(18,18,20,0.35);
  pointer-events: auto;
}
.stick__knob {
  position: absolute; left: 50%; top: 50%;
  width: 52px; height: 52px; margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(242,240,234,0.75);
}
body.touch .spray-btn {
  display: grid; place-items: center;
  position: absolute;
  right: max(22px, env(safe-area-inset-right));
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 120px);
  width: 92px; height: 92px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.85);
  background: var(--paint);
  font-weight: 700; font-size: 0.8rem; letter-spacing: 0.1em;
  color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.7);
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
}
body.touch .spray-btn.is-on { transform: scale(0.92); }
body.touch .jump-btn {
  display: grid; place-items: center;
  position: absolute;
  right: calc(max(22px, env(safe-area-inset-right)) + 104px);
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 118px);
  width: 54px; height: 54px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 1.3rem;
}
body.touch .hud__brand { display: none; }
body.touch .caps span { display: none; }
body.touch .caps button { padding: 8px 10px; }

/* ---------- toast / flash ---------- */
.toast {
  position: fixed;
  top: max(70px, calc(env(safe-area-inset-top) + 60px));
  left: 50%;
  transform: translate(-50%, -8px);
  z-index: 30;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.35s var(--ease-out-expo);
  white-space: nowrap;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

.flash { position: fixed; inset: 0; z-index: 25; background: #fff; opacity: 0; pointer-events: none; }
.flash.is-on { animation: flash 0.45s ease-out; }
@keyframes flash { from { opacity: 0.8; } to { opacity: 0; } }

@media (max-width: 560px) {
  .keys { grid-template-columns: 1fr; }
  .swatch { width: 24px; height: 24px; }
  .hud__brand { font-size: 1.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
body.erasing .palette, body.erasing .colorname { opacity: 0.3; pointer-events: none; }

/* pause hub */
.panel--wide { width: min(860px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; }
.pause-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; text-align: left; }
.pause-col { display: grid; gap: 18px; align-content: start; }
.actions { display: grid; gap: 8px; }
.actions .btn { width: 100%; font-size: 0.92rem; }
#menu-tools button { font-size: 0.85rem; }
.keys--menu { grid-template-columns: 1fr; margin: 0; max-width: none; gap: 0.45rem; }
.keys--touch-note { display: none; margin: 0; font-size: 0.85rem; color: var(--muted); }
body.touch .keys--menu { display: none; }
body.touch .keys--touch-note { display: block; }
@media (max-width: 720px) { .pause-grid { grid-template-columns: 1fr; gap: 20px; } }
