/* Clockwork Heist — brass-and-ink technical drawing. */
:root {
  --ink: #0b0d10;
  --ink-2: #101319;
  --panel: #14161d;
  --panel-2: #191c25;
  --line: #2a2f3a;
  --brass: #c9a24b;
  --brass-bright: #f0d488;
  --brass-dim: rgba(201, 162, 75, 0.4);
  --paper: #efe3c6;
  --muted: #a99a74;
  --alarm: #e0503a;
  --ok: #6fbf73;
  --steam: #a9c4d6;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(201, 162, 75, 0.08), transparent 60%),
    repeating-linear-gradient(0deg, rgba(201, 162, 75, 0.035) 0 1px, transparent 1px 28px),
    repeating-linear-gradient(90deg, rgba(201, 162, 75, 0.035) 0 1px, transparent 1px 28px),
    var(--ink);
  overflow-x: hidden;
}

h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; letter-spacing: 0.02em; margin: 0 0 0.4em; }
h1 { font-size: clamp(1.9rem, 6vw, 3.4rem); }
h2 { font-size: clamp(1.4rem, 4vw, 2rem); }
h3 { font-size: 1rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--brass); }
p { line-height: 1.55; }
kbd {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.85em;
  color: var(--brass-bright);
}

/* ---------- top bar ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(25, 28, 37, 0.95), rgba(11, 13, 16, 0.95));
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(4px);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand .mark {
  color: var(--brass-bright);
  font-size: 1.3rem;
  display: inline-block;
  animation: tick 8s steps(8) infinite;
}
@keyframes tick { to { transform: rotate(360deg); } }
.brand-text {
  font-family: Georgia, serif;
  font-weight: 700;
  letter-spacing: 0.18em;
  font-size: clamp(0.72rem, 2.4vw, 0.95rem);
  color: var(--paper);
  white-space: nowrap;
}
.hud { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: flex-end; }
.hud-label {
  display: block;
  font-size: 0.6rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.hud b { font-size: 1.05rem; color: var(--brass-bright); font-variant-numeric: tabular-nums; }
.meter {
  display: inline-block;
  width: 88px;
  height: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: var(--ink-2);
  vertical-align: middle;
}
.meter i { display: block; height: 100%; background: linear-gradient(90deg, var(--brass), var(--alarm)); transition: width 0.2s; }
.pips { display: inline-flex; gap: 5px; }
.pip { width: 11px; height: 11px; border-radius: 50%; border: 1px solid var(--line); background: var(--ink-2); display: inline-block; }
.pip.on { background: var(--alarm); box-shadow: 0 0 8px rgba(224, 80, 58, 0.7); }
.hud-obj { font-size: 0.78rem; color: var(--paper); max-width: 42ch; opacity: 0.9; }

/* ---------- screens ---------- */
#screen-host { display: block; }
.screen { display: none; padding: 22px clamp(12px, 3vw, 32px) 48px; }
.screen.active { display: block; animation: fade 0.4s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- title ---------- */
.title-plate { max-width: 900px; margin: 0 auto; text-align: center; }
.kicker {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  font-size: 0.72rem;
  color: var(--brass);
  margin-bottom: 0.6rem;
}
.lede { color: var(--paper); opacity: 0.88; max-width: 62ch; margin: 0.6rem auto 1.2rem; }
.title-art {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--ink-2);
  padding: 8px;
  box-shadow: var(--shadow);
}
.title-art canvas, .board-panel canvas { width: 100%; height: auto; display: block; border-radius: 6px; }
.title-cta { margin: 1.4rem 0 0.6rem; }
.hint { color: var(--muted); font-size: 0.82rem; }

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--brass-dim);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  color: var(--paper);
  padding: 12px 20px;
  min-height: 44px;
  letter-spacing: 0.04em;
  transition: transform 0.08s, border-color 0.15s, box-shadow 0.15s;
}
.btn:hover:not(:disabled) { border-color: var(--brass); box-shadow: 0 0 0 2px rgba(201, 162, 75, 0.15); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn.primary { background: linear-gradient(180deg, var(--brass-bright), var(--brass)); color: #241a06; font-weight: 700; border-color: var(--brass-bright); }
.btn:disabled { opacity: 0.42; cursor: not-allowed; }
.btn:focus-visible, button:focus-visible, canvas:focus-visible { outline: 2px solid var(--brass-bright); outline-offset: 2px; }

/* ---------- scout ---------- */
.scout-head { max-width: 780px; margin: 0 auto 1.2rem; text-align: center; }
.scout-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(320px, 2fr) minmax(220px, 1fr);
  gap: 16px;
  align-items: start;
  max-width: 1240px;
  margin: 0 auto;
}
.panel {
  background: linear-gradient(180deg, var(--panel), var(--ink-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.board-panel .cap { color: var(--muted); font-size: 0.72rem; text-align: center; margin-top: 8px; }
.intel-row, .entry-row {
  display: grid;
  gap: 2px;
  width: 100%;
  text-align: left;
  font: inherit;
  color: var(--paper);
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  min-height: 44px;
  cursor: pointer;
}
.intel-row:hover:not(:disabled), .entry-row:hover { border-color: var(--brass); }
.intel-row:disabled { opacity: 0.6; cursor: default; }
.intel-row.owned { border-color: var(--ok); }
.intel-row .intel-cost { color: var(--brass-bright); font-size: 0.72rem; }
.intel-row .intel-desc, .entry-note, .entry-risk { color: var(--muted); font-size: 0.76rem; }
.entry-row.selected { border-color: var(--brass-bright); box-shadow: 0 0 0 2px rgba(201, 162, 75, 0.2); }
.entry-name { font-weight: 700; color: var(--brass-bright); }
.actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 1.4rem; }

/* ---------- crew ---------- */
.crew-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  max-width: 1080px;
  margin: 0 auto;
}
.crew-card {
  position: relative;
  text-align: left;
  font: inherit;
  color: var(--paper);
  background: linear-gradient(180deg, var(--panel), var(--ink-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  min-height: 150px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.crew-card:hover { border-color: var(--brass); }
.crew-card.selected { border-color: var(--brass-bright); box-shadow: 0 0 0 2px rgba(201, 162, 75, 0.25); }
.crew-key {
  position: absolute; top: 10px; right: 12px;
  font-family: ui-monospace, monospace;
  color: var(--brass-bright);
  border: 1px solid var(--brass-dim);
  border-radius: 5px; padding: 1px 7px; font-size: 0.75rem;
}
.crew-name { font-family: Georgia, serif; font-size: 1.2rem; color: var(--brass-bright); }
.crew-tag { text-transform: uppercase; letter-spacing: 0.16em; font-size: 0.66rem; color: var(--brass); }
.crew-desc { color: var(--paper); opacity: 0.85; font-size: 0.85rem; flex: 1; }
.crew-uses { color: var(--muted); font-size: 0.75rem; }

/* ---------- play ---------- */
.play-screen { padding-top: 14px; }
.play-grid {
  display: grid;
  grid-template-columns: minmax(200px, 250px) minmax(0, 1fr) minmax(220px, 300px);
  gap: 14px;
  align-items: start;
  max-width: 1500px;
  margin: 0 auto;
}
.board-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  background: var(--ink-2);
  box-shadow: var(--shadow);
  overflow: hidden;
}
#board { width: 100%; height: auto; display: block; border-radius: 6px; cursor: crosshair; }
#board.shake { animation: shake 0.25s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.board-overlay { position: absolute; inset: 8px; pointer-events: none; border-radius: 6px; }

.side { display: flex; flex-direction: column; gap: 8px; max-height: 76vh; overflow: auto; }
.ability, .action {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  font: inherit;
  color: var(--paper);
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 44px;
  cursor: pointer;
  text-align: left;
}
.ability:hover:not(:disabled), .action:hover:not(:disabled) { border-color: var(--brass); }
.ability:disabled, .action:disabled { opacity: 0.45; cursor: not-allowed; }
.ab-key {
  font-family: ui-monospace, monospace;
  color: var(--brass-bright);
  border: 1px solid var(--brass-dim);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 0.72rem;
}
.ab-name { font-size: 0.86rem; }
.ab-tag, .ab-uses { font-size: 0.7rem; color: var(--muted); }
.ab-uses { color: var(--brass-bright); font-weight: 700; }

.log { display: flex; flex-direction: column; gap: 4px; overflow: auto; max-height: 42vh; padding-right: 4px; }
.log-line { font-size: 0.78rem; line-height: 1.4; color: var(--paper); opacity: 0.9; border-left: 2px solid var(--line); padding-left: 8px; }
.log-goal { border-color: var(--brass-bright); color: var(--brass-bright); }
.log-alarm { border-color: var(--alarm); color: #ffb9ac; }
.log-warn { border-color: #d89a3a; color: #f0d488; }
.log-mech { border-color: var(--brass); }
.log-clue { border-color: var(--steam); color: var(--steam); }
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 0.72rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.sw.brass { background: #b8893a; } .sw.paper { background: var(--paper); } .sw.red { background: var(--alarm); }
.sw.green { background: var(--ok); } .sw.cone { background: rgba(201, 162, 75, 0.5); }

/* ---------- touch pad ---------- */
.touch-pad { display: none; margin: 16px auto 0; max-width: 320px; }
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
}
.tbtn {
  font: inherit;
  color: var(--paper);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--brass-dim);
  border-radius: 10px;
  min-height: 60px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.tbtn:active { background: var(--brass); color: #241a06; }
.tbtn small { font-size: 0.6rem; color: var(--muted); }
.tbtn.act { grid-column: 2; grid-row: 2; background: linear-gradient(180deg, var(--brass-bright), var(--brass)); color: #241a06; font-weight: 700; }
/* place directional buttons */
.dpad .tbtn:nth-child(2) { grid-column: 2; grid-row: 1; } /* up */
.dpad .tbtn:nth-child(3) { grid-column: 1; grid-row: 2; } /* left */
.dpad .tbtn:nth-child(4) { grid-column: 3; grid-row: 2; } /* right */
.dpad .tbtn:nth-child(5) { grid-column: 2; grid-row: 3; } /* down */

/* ---------- modals ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(6, 7, 9, 0.78);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: fade 0.2s ease;
}
.modal {
  width: min(560px, 100%);
  max-height: 90vh; overflow: auto;
  background: linear-gradient(180deg, var(--panel-2), var(--ink-2));
  border: 1px solid var(--brass-dim);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 18px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-head h3 { color: var(--brass-bright); }
.modal-x {
  font: inherit; font-size: 1.4rem; line-height: 1;
  background: transparent; color: var(--muted); border: none; cursor: pointer;
  width: 40px; height: 40px; border-radius: 8px;
}
.modal-x:hover { color: var(--paper); }
.puzzle-lede { color: var(--paper); opacity: 0.9; }
.puzzle-note { color: var(--muted); font-size: 0.78rem; }
.valve-row, .gear-row, .clock-row { display: flex; gap: 12px; justify-content: center; align-items: center; margin: 18px 0; flex-wrap: wrap; }
.valve {
  width: 64px; height: 64px; border-radius: 50%;
  font: inherit; font-size: 1.3rem; font-weight: 700;
  color: var(--paper);
  background: radial-gradient(circle at 35% 30%, var(--panel-2), var(--ink-2));
  border: 2px solid var(--brass-dim);
  cursor: pointer;
}
.valve:hover { border-color: var(--brass-bright); }
.valve:active { background: var(--brass); color: #241a06; }
.gear-dial {
  width: 84px; height: 84px; border-radius: 12px;
  font: inherit; color: var(--paper);
  background: linear-gradient(180deg, var(--panel-2), var(--ink-2));
  border: 1px solid var(--brass-dim);
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.gear-dial:hover { border-color: var(--brass-bright); }
.dial-num { font-size: 1.6rem; font-weight: 700; color: var(--brass-bright); font-variant-numeric: tabular-nums; }
.dial-lbl { font-size: 0.65rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }
.clock-display { font-family: Georgia, serif; font-size: 2rem; color: var(--brass-bright); min-width: 90px; text-align: center; }
.valve-prog { text-align: center; color: var(--muted); font-size: 0.85rem; margin: 8px 0; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--brass); color: var(--paper);
  padding: 10px 16px; border-radius: 10px; z-index: 60; box-shadow: var(--shadow);
  font-size: 0.85rem; transition: opacity 0.4s, transform 0.4s;
}
.toast.out { opacity: 0; transform: translateX(-50%) translateY(8px); }

/* ---------- result ---------- */
.result-plate { max-width: 640px; margin: 4vh auto 0; text-align: center; }
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px; margin: 1.6rem 0;
}
.stat {
  display: flex; justify-content: space-between; gap: 8px;
  background: var(--ink-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 14px; font-size: 0.85rem;
}
.stat b { color: var(--brass-bright); }

/* ---------- gear veil ---------- */
#gear-veil {
  position: fixed; inset: 0; z-index: 80; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.2s;
  background: rgba(6, 7, 9, 0.55);
}
#gear-veil.spin { opacity: 1; }
#gear-veil .gear {
  width: 120px; height: 120px; border-radius: 50%;
  border: 10px dashed var(--brass);
  box-shadow: 0 0 40px rgba(201, 162, 75, 0.5);
}
#gear-veil.spin .gear { animation: spin 0.6s linear; }
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .play-grid { grid-template-columns: minmax(0, 1fr) minmax(200px, 260px); }
  #panel-left { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; max-height: none; }
  #panel-left h3 { width: 100%; }
  #panel-left .ability, #panel-left .action { width: auto; flex: 1 1 150px; }
  .board-wrap { grid-column: 1; }
  #panel-right { grid-column: 2; }
}
@media (max-width: 760px) {
  .scout-grid { grid-template-columns: 1fr; }
  .play-grid { grid-template-columns: 1fr; }
  #panel-left, #panel-right, .board-wrap { grid-column: 1; }
  .board-wrap { order: -1; }
  .side { max-height: none; }
  .log { max-height: 26vh; }
  .touch-pad { display: block; }
  .hud-obj { max-width: none; width: 100%; }
  #topbar { flex-wrap: wrap; }
  .hud { gap: 10px; }
}
@media (pointer: coarse) {
  .touch-pad { display: block; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
