/* ==========================================================================
   Ink Side Down — Desk & paper visual layer
   --------------------------------------------------------------------------
   Builds on tokens.css / base.css / components.css. Adds the ink-desk palette
   and the game-specific stage, legend, keyboard chips and accessibility bar.
   The game canvas paints its own art, so the stage intentionally stays dark
   in both site themes; everything around it still follows semantic tokens.
   ========================================================================== */

:root {
  /* Ink-desk primitives */
  --ink-950: #0d0a14;
  --ink-900: #14111c;
  --ink-800: #221d2e;
  --ink-700: #2a2437;
  --ink-600: #4a4058;
  --seal-400: #f0717f;
  --seal-500: #d7263d;
  --seal-600: #b51d31;
  --paper-100: #faf6ee;
  --paper-200: #f3eee6;
  --mint-400: #5eead4;

  /* Semantic aliases used by game components */
  --isd-stage-bg: var(--ink-900);
  --isd-stage-border: var(--ink-700);
  --isd-panel-bg: color-mix(in srgb, var(--surface) 94%, var(--ink-900));
  --isd-chip-bg: color-mix(in srgb, var(--surface) 90%, var(--ink-800));
  --isd-legend-bg: color-mix(in srgb, var(--surface) 96%, var(--paper-200));
}

[data-theme="dark"] {
  --isd-stage-bg: var(--ink-950);
  --isd-stage-border: var(--ink-600);
  --isd-panel-bg: color-mix(in srgb, var(--surface) 90%, var(--ink-900));
  --isd-chip-bg: color-mix(in srgb, var(--surface-sunken) 84%, var(--ink-800));
  --isd-legend-bg: color-mix(in srgb, var(--surface) 88%, var(--ink-900));
}

/* ---------- App shell ---------- */
.isd-app {
  width: min(1240px, 100%);
  margin-inline: auto;
}

.isd-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.isd-topbar h3 {
  margin: 0.15rem 0 0.35rem;
}

.isd-topbar p {
  margin: 0;
  max-width: 62ch;
  color: var(--text-muted);
}

.isd-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 270px;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 900px) {
  .isd-layout { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- Canvas stage ---------- */
.isd-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  min-height: 380px;
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid var(--isd-stage-border);
  background: var(--isd-stage-bg);
  box-shadow: 0 18px 44px rgb(0 0 0 / 0.18);
}

@media (max-width: 720px) {
  .isd-stage {
    aspect-ratio: 3 / 4;
    min-height: 460px;
  }
}

.isd-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
  cursor: pointer;
}

.isd-stage canvas:focus-visible {
  outline: 3px solid var(--seal-400);
  outline-offset: -3px;
}

.isd-caption {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.isd-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 32px;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--isd-chip-bg);
  color: var(--text-muted);
  font-size: var(--font-size-xs);
  font-weight: 600;
}

.isd-chip kbd {
  font-family: var(--font-family-mono);
  font-size: var(--font-size-2xs);
  color: var(--text);
}

/* ---------- Side legend ---------- */
.isd-panel {
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--isd-panel-bg);
  padding: 1.1rem;
}

.isd-panel h3 {
  margin: 0 0 0.6rem;
  font-size: var(--font-size-lg);
}

.isd-panel p {
  margin: 0 0 0.85rem;
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  line-height: 1.6;
}

.isd-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
}

.isd-legend li {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  font-size: var(--font-size-sm);
  line-height: 1.5;
}

.isd-swatch {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
}

.isd-swatch--mark { border: 2px dashed var(--seal-500); background: transparent; }
.isd-swatch--ink { background: var(--seal-500); }
.isd-swatch--block { background: var(--ink-700); }
.isd-swatch--star { background: var(--mint-400); }

.isd-keys {
  margin: 1rem 0 0;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 0.45rem;
  font-size: var(--font-size-sm);
}

.isd-keys div {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.isd-keys dt { color: var(--text-muted); }
.isd-keys dd { margin: 0; font-family: var(--font-family-mono); font-size: var(--font-size-xs); }

/* ---------- Accessible control bar (upstream parity) ---------- */
#status { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#controls {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

#controls:focus-within {
  position: relative;
  left: auto;
  right: auto;
  bottom: auto;
  width: auto;
  height: auto;
  clip: auto;
  white-space: normal;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.85rem;
  padding: 0.7rem;
  border-radius: 12px;
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
}

#controls button,
#controls a {
  min-height: 44px;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  padding: 0 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--ink-600);
  background: var(--ink-700);
  color: var(--paper-200);
  font: 600 15px var(--font-family-base);
  cursor: pointer;
}

#controls a[hidden] { display: none; }
#controls button:focus,
#controls a:focus { outline: 2px solid var(--seal-400); outline-offset: 2px; }

/* ---------- Copy fallback dialog ---------- */
#copybox {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgb(10 7 16 / 0.82);
  z-index: 50;
}

#copybox.open { display: flex; }

#copybox .card {
  width: min(92vw, 440px);
  box-sizing: border-box;
  padding: 1.15rem;
  border-radius: 16px;
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
  color: var(--paper-200);
}

#copybox p { margin: 0 0 0.65rem; font-size: 15px; line-height: 1.45; }

#copybox textarea {
  width: 100%;
  height: 110px;
  box-sizing: border-box;
  padding: 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--ink-600);
  background: var(--ink-900);
  color: var(--seal-400);
  font: 15px/1.45 var(--font-family-mono);
  resize: none;
}

#copyclose {
  min-height: 44px;
  margin-top: 0.65rem;
  padding: 0 1rem;
  border-radius: 10px;
  border: 1px solid var(--ink-600);
  background: var(--seal-500);
  color: #fff;
  font: 600 15px var(--font-family-base);
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  .isd-stage { box-shadow: none; }
}
