:root {
  --ink: #f4ece0;
  --dim: #a99a8c;
  --paper: #17131c;
  --panel: #221b29;
  --line: #3a2f45;
  --gold: #e0b25f;
  --rose: #e2617a;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  /* nothing in the game is text you would want to select, and long-press
     selection on iOS pops a Copy / Search menu over the controls */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  background:
    radial-gradient(120% 90% at 50% 0%, #241d2d 0%, #14101a 55%, #0d0a12 100%);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, "Segoe UI", Helvetica, Arial, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 12px 12px;
  gap: 12px;
}

/* ---------- HUD ---------- */

#hud {
  position: absolute;
  top: 12px;
  left: 0;
  right: 0;
  margin: 0 auto;
  padding: 0 14px;
  width: 100%;
  max-width: 1100px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  letter-spacing: 0.02em;
}

.hud-left, .hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.hud-title {
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--gold);
  white-space: nowrap;
}

.hud-room {
  color: var(--dim);
  border-left: 1px solid var(--line);
  padding-left: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-count { color: var(--dim); white-space: nowrap; }
.hud-count b { color: var(--ink); }

.hud-btn {
  background: var(--panel);
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 9px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  line-height: 1.4;
}
.hud-btn:hover { color: var(--ink); border-color: var(--gold); }
.hud-btn[aria-pressed="true"] { color: var(--gold); border-color: var(--gold); }

/* ---------- Stage ---------- */

#stage {
  position: relative;
  flex: 0 0 auto;
  line-height: 0;
  box-shadow:
    0 0 0 1px #000,
    0 0 0 5px #2b2334,
    0 0 0 6px #100d16,
    0 24px 60px rgba(0, 0, 0, 0.6);
  border-radius: 2px;
}

#game {
  display: block;
  touch-action: none;
  -webkit-touch-callout: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #0d0a12;
}

#prompt {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, 0);
  background: rgba(20, 15, 26, 0.92);
  border: 1px solid var(--gold);
  color: var(--ink);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
  animation: bob 1.6s ease-in-out infinite;
}
#prompt .key {
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.08em;
}

@keyframes bob {
  0%, 100% { margin-top: 0; }
  50% { margin-top: -3px; }
}

/* ---------- Touch controls ---------- */

#touch {
  display: none;
  width: 100%;
  max-width: 520px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  user-select: none;
}

.dpad {
  position: relative;
  width: 150px;
  height: 150px;
}

.pad, .act {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--dim);
  border-radius: 12px;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  font-size: 0;                 /* no text on the pads at all */
}

.pad { width: 50px; height: 50px; }

/* the arrows are shapes, not characters, so there is nothing to copy */
.pad::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  background: currentColor;
  clip-path: polygon(50% 12%, 92% 88%, 8% 88%);
  transition: transform 0.05s;
}
.pad.down::before  { transform: rotate(180deg); }
.pad.left::before  { transform: rotate(-90deg); }
.pad.right::before { transform: rotate(90deg); }
.pad.up    { left: 50px; top: 0; }
.pad.left  { left: 0; top: 50px; }
.pad.right { left: 100px; top: 50px; }
.pad.down  { left: 50px; top: 100px; }
.pad:active, .act:active { background: #34294010; border-color: var(--gold); color: var(--gold); }

.act {
  position: static;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  color: var(--gold);
}

.act span {
  font-size: 13px;
  letter-spacing: 0.1em;
  pointer-events: none;
}

body.touch #touch { display: flex; }

/* ---------- Overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 6, 12, 0.86);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
  animation: fade 0.18s ease-out;
}
.overlay[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.viewer-box, .help-box {
  position: relative;
  background: linear-gradient(180deg, #241d2c, #1b1622);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.viewer-box {
  display: flex;
  gap: 0;
  max-width: 1000px;
  width: 100%;
}

.viewer-art {
  padding: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,0.014) 0 2px, transparent 2px 4px),
    #191420;
  border-right: 1px solid var(--line);
  border-radius: 10px 0 0 10px;
}

/* the mount board + frame around the painting */
.matte {
  padding: 18px;
  background: #efe6d6;
  border: 9px solid #5a4326;
  border-radius: 2px;
  box-shadow:
    inset 0 0 0 1px #cabfa9,
    0 0 0 1px #2a1f12,
    0 18px 40px rgba(0, 0, 0, 0.55);
  line-height: 0;
}

#artCanvas {
  display: block;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.viewer-info {
  padding: 30px 30px 26px;
  width: 340px;
  flex: 0 0 340px;
}

.plate-no {
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
}

.viewer-info h2 {
  margin: 0 0 6px;
  font-size: 26px;
  line-height: 1.15;
  font-weight: 600;
  font-family: Georgia, "Times New Roman", serif;
}

.byline { margin: 0 0 2px; font-size: 14px; color: var(--ink); }
.medium { margin: 0 0 18px; font-size: 13px; color: var(--dim); font-style: italic; }

.note {
  margin: 0 0 22px;
  font-size: 14px;
  line-height: 1.6;
  color: #cfc3b6;
}

.viewer-nav { display: flex; gap: 8px; }
.viewer-nav button {
  flex: 1;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--dim);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.viewer-nav button:hover { color: var(--gold); border-color: var(--gold); }

.close {
  position: absolute;
  right: 10px;
  top: 10px;
  z-index: 2;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(10, 8, 14, 0.7);
  border: 1px solid var(--line);
  color: var(--dim);
  font-size: 13px;
  cursor: pointer;
}
.close:hover { color: var(--ink); border-color: var(--gold); }

.help-box { max-width: 440px; padding: 28px 30px; }
.help-box h2 {
  margin: 0 0 16px;
  font-size: 22px;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
}
.help-box ul { margin: 0 0 18px; padding-left: 18px; }
.help-box li { font-size: 14px; line-height: 1.9; color: #cfc3b6; }
.help-box b { color: var(--gold); font-weight: 600; }
.help-foot { margin: 0; font-size: 13px; color: var(--dim); font-style: italic; }

@media (max-width: 860px) {
  .viewer-box { flex-direction: column; }
  .viewer-art { border-right: 0; border-bottom: 1px solid var(--line); border-radius: 10px 10px 0 0; padding: 18px; }
  .viewer-info { width: auto; flex: 1 1 auto; padding: 22px; }
  .viewer-info h2 { font-size: 22px; }
  .matte { padding: 12px; border-width: 7px; }
}

@media (max-width: 560px) {
  .hud-title { font-size: 11px; letter-spacing: 0.1em; }
  .hud-room { font-size: 11px; }
  .hud-count { font-size: 11px; }
}

/* ---------- Title card ---------- */

#boot {
  position: fixed;
  touch-action: none;
  -webkit-touch-callout: none;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background:
    radial-gradient(120% 90% at 50% 40%, #16111f 0%, #0a0810 60%, #050409 100%);
  cursor: pointer;
  transition: opacity 0.45s ease-out;
}
#boot[hidden] { display: none; }
#boot.gone { opacity: 0; pointer-events: none; }

/* the tube: a dark bezel with a slightly domed glass */
#boot .crt {
  position: relative;
  padding: 14px;
  border-radius: 26px;
  line-height: 0;
  background: linear-gradient(160deg, #2a2533, #14111b 60%, #0d0b12);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.06),
    inset 0 -3px 6px rgba(0, 0, 0, 0.6),
    0 0 0 1px #000,
    0 30px 70px rgba(0, 0, 0, 0.75),
    0 0 90px rgba(120, 90, 200, 0.10);
}

#boot .crt::after {
  content: "";
  position: absolute;
  inset: 14px;
  border-radius: 14px;
  pointer-events: none;
  background:
    radial-gradient(80% 55% at 50% 0%, rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0) 60%);
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.55);
}

#bootCanvas {
  display: block;
  border-radius: 12px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #07060b;
}

@media (max-width: 420px) {
  #boot .crt { padding: 9px; border-radius: 18px; }
  #boot .crt::after { inset: 9px; border-radius: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  #boot { transition: none; }
}

/* the wall labels are worth reading and copying; the controls are not */
.viewer-info, .help-box {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}
