/* ─────────────────────────────────────────────────────────────
   kal_foundry · arcade · cabinet styles
   Pages set <html data-theme="dark"> so tokens.css serves the dark
   SIGNAL palette. Everything here reads tokens — no new colours.
   ───────────────────────────────────────────────────────────── */

html { background: var(--surface); }
body.arc {
  background: var(--surface);
  color: var(--ink);
  position: relative;
  min-height: 100dvh;
}

/* cabinet texture · faded hairline grid + faint scanlines */
body.arc::before,
body.arc::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
body.arc::before {
  background-image:
    linear-gradient(var(--hair) 1px, transparent 1px),
    linear-gradient(90deg, var(--hair) 1px, transparent 1px);
  background-size: 32px 32px;
  opacity: 0.45;
  -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 0%, transparent 75%);
          mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 0%, transparent 75%);
}
body.arc::after {
  background: repeating-linear-gradient(180deg, var(--hair) 0 1px, transparent 1px 4px);
  opacity: 0.18;
}
body.arc > * { position: relative; z-index: 1; }

.vh {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ── buttons ── */
.arc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: var(--tracking-meta);
  text-transform: lowercase;
  text-decoration: none;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: var(--radius-1);
  cursor: pointer;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease), transform var(--dur-1) var(--ease);
}
.arc-btn:hover { border-color: var(--ink); text-decoration: none; }
.arc-btn:active { transform: scale(0.97); }
.arc-btn--primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.arc-btn--primary:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.arc-btn[hidden] { display: none; }

.arc-icon {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--hair);
  border-radius: var(--radius-1);
  cursor: pointer;
  transition: color var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}
.arc-icon:hover:not(:disabled) { color: var(--ink); border-color: var(--rule); }
.arc-icon:disabled { opacity: 0.35; cursor: default; }
.arc-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* sound toggle · speaker with waves (on) or a slash (off) */
[data-arc-sound] .on { display: none; }
[data-arc-sound][aria-pressed="true"] .on { display: inline; }
[data-arc-sound][aria-pressed="true"] .off { display: none; }
[data-arc-sound][aria-pressed="true"] { color: var(--signal); }

/* pause toggle · two bars, or a play triangle while paused */
[data-arc-pause] .play { display: none; }
[data-arc-pause][data-mode="resume"] .play { display: inline; }
[data-arc-pause][data-mode="resume"] .bars { display: none; }

kbd, .arc-kbd {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  line-height: 1;
  color: var(--ink-2);
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: var(--radius-1);
  background: var(--surface-2);
}

/* corner ticks · brand motif on framed panels */
.arc-ticks { position: relative; }
.arc-ticks::before,
.arc-ticks::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  pointer-events: none;
}
.arc-ticks::before { top: -1px; left: -1px; border-top: 1px solid var(--accent); border-left: 1px solid var(--accent); }
.arc-ticks::after { bottom: -1px; right: -1px; border-bottom: 1px solid var(--accent); border-right: 1px solid var(--accent); }

/* ─────────────────────────────────────────────────────────────
   game page shell
   bar → hud → stage (fills) → touch pad / key help
   ───────────────────────────────────────────────────────────── */
body.arc-game {
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}
@supports not (height: 100dvh) { body.arc-game { height: 100vh; } }

.arc-app {
  height: 100%;
  max-width: 760px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 10px;
  padding:
    max(6px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    calc(12px + var(--embed-bottom, 0px) + env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.arc-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  border-bottom: 1px solid var(--hair);
}
.arc-back {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding-right: 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: var(--tracking-meta);
  text-transform: uppercase;
  color: var(--signal);
  text-decoration: none;
}
.arc-back:hover { text-decoration: none; color: var(--ink); }
.arc-back svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.arc-title {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-transform: lowercase;
  white-space: nowrap;
}
.arc-title .n { color: var(--ink-muted); font-weight: 500; margin-right: 8px; }
.arc-bar-actions { justify-self: end; display: flex; gap: 6px; }

/* HUD · hairline-ruled stat cells, tabular numbers */
.arc-hud {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(var(--hud-cols, 3), minmax(0, 1fr));
  border: 1px solid var(--hair);
  background: var(--surface-2);
}
.arc-hud > div {
  padding: 7px 12px 8px;
  min-width: 0;
  border-left: 1px solid var(--hair);
}
.arc-hud > div:first-child { border-left: 0; }
.arc-hud dt {
  font-family: var(--font-mono);
  font-size: var(--t-micro);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--ink-muted);
}
.arc-hud dd {
  margin: 2px 0 0;
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.15;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.arc-hud dd.is-beaten { color: var(--accent); }

/* stage · a size container so boards fit whatever space is left */
.arc-stage {
  position: relative;
  min-height: 0;
  container-type: size;
  display: grid;
  place-items: center;
  outline: none;
}
.arc-board {
  position: relative;
  aspect-ratio: var(--ar, 1);
  width: min(100cqw, 100cqh * var(--ar, 1), var(--board-max, 600px));
  border: 1px solid var(--rule);
  background: var(--surface-2);
}
.arc-board canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* overlay · menu / paused / game over */
.arc-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 58%, transparent);
  -webkit-backdrop-filter: blur(2px);
          backdrop-filter: blur(2px);
  animation: arc-fade var(--dur-2) var(--ease);
}
.arc-overlay[hidden] { display: none; }
@keyframes arc-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes arc-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.arc-panel {
  width: min(320px, 100%);
  padding: 22px 22px 18px;
  background: var(--surface-2);
  border: 1px solid var(--rule);
  text-align: center;
  animation: arc-rise var(--dur-3) var(--ease);
}
.arc-ov-eyebrow {
  margin: 0 0 10px;
  font-family: var(--font-mono);
  font-size: var(--t-micro);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--ink-muted);
}
.arc-ov-title {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: var(--tracking-heading);
  line-height: 1.05;
  color: var(--ink);
  text-transform: lowercase;
}
.arc-ov-score {
  margin: 14px 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.arc-ov-score[hidden] { display: none; }
.arc-ov-score .v {
  font-family: var(--font-mono);
  font-size: 44px;
  font-weight: 600;
  letter-spacing: var(--tracking-display);
  line-height: 1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.arc-ov-score .l {
  font-family: var(--font-mono);
  font-size: var(--t-micro);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--ink-muted);
}
.arc-badge {
  display: inline-block;
  margin-top: 12px;
  padding: 3px 8px;
  font-family: var(--font-mono);
  font-size: var(--t-micro);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--ink-2);
  border: 1px solid var(--rule);
}
.arc-badge[hidden] { display: none; }
.arc-badge.is-best { color: var(--accent); border-color: var(--accent); }
/* the page's one serif moment */
.arc-ov-sub {
  margin: 12px 0 0;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 20px;
  line-height: 1.2;
  color: var(--accent);
}
.arc-ov-sub[hidden] { display: none; }
.arc-ov-actions {
  margin-top: 18px;
  display: grid;
  gap: 8px;
}
.arc-ov-hint {
  margin: 12px 0 0;
  min-height: 1em;
  font-family: var(--font-mono);
  font-size: var(--t-micro);
  letter-spacing: var(--tracking-meta);
  color: var(--ink-muted);
}
.arc-ov-hint:empty { display: none; }

/* foot · keyboard help on desktop, touch pad on phones */
.arc-foot { display: grid; justify-items: center; gap: 10px; }
.arc-help {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px 14px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
}
.arc-help span { display: inline-flex; align-items: center; gap: 5px; }

.arc-pad {
  display: none;
  width: 100%;
  max-width: 380px;
  gap: 8px;
  -webkit-user-select: none;
  user-select: none;
}
.arc-key {
  min-height: 52px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  padding: 0;
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius-2);
  cursor: pointer;
  touch-action: none;
  transition: background 80ms var(--ease), color 80ms var(--ease), transform 80ms var(--ease);
}
.arc-key small {
  font-size: 9px;
  font-weight: 500;
  letter-spacing: var(--tracking-meta);
  text-transform: uppercase;
  color: var(--ink-muted);
}
.arc-key svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
/* pressed state comes from .is-down (set by the input handlers) — touch
   :active lingers after a tap in mobile browsers, so it's mouse-only */
.arc-key.is-down { background: var(--ink); color: var(--surface); transform: scale(0.95); }
.arc-key.is-down small { color: var(--surface); }
@media (hover: hover) and (pointer: fine) {
  .arc-key:active { background: var(--ink); color: var(--surface); transform: scale(0.95); }
  .arc-key:active small { color: var(--surface); }
}

/* d-pad · snake */
.arc-pad--dpad {
  grid-template-columns: repeat(3, 60px);
  grid-template-rows: repeat(3, 52px);
  width: auto;
  justify-content: center;
}
.arc-pad--dpad .up    { grid-area: 1 / 2; }
.arc-pad--dpad .left  { grid-area: 2 / 1; }
.arc-pad--dpad .right { grid-area: 2 / 3; }
.arc-pad--dpad .down  { grid-area: 3 / 2; }
.arc-pad--dpad .mid   { grid-area: 2 / 2; display: grid; place-items: center; font-family: var(--font-mono); font-size: 9px; letter-spacing: var(--tracking-meta); color: var(--ink-muted); text-transform: uppercase; }

@media (hover: none) and (pointer: coarse) {
  .arc-pad { display: grid; }
  .arc-help { display: none; }
}

/* short screens · tighten chrome so the board keeps its size */
@media (max-height: 640px) {
  .arc-app { gap: 6px; }
  .arc-bar { min-height: 44px; }
  .arc-hud > div { padding: 4px 10px 5px; }
  .arc-hud dd { font-size: 16px; }
  .arc-key { min-height: 46px; }
  .arc-pad--dpad { grid-template-rows: repeat(3, 46px); }
}
@media (max-width: 380px) {
  .arc-app { padding-left: 12px; padding-right: 12px; }
  .arc-hud > div { padding-left: 9px; padding-right: 9px; }
  .arc-title .n { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .arc-overlay, .arc-panel { animation: none; }
  .arc-key, .arc-btn { transition: none; }
}
