/* MONIAC — stylised machine, Stage 0. Portrait-native; desktop and phone. */

:root {
  --backboard: #141a22;
  --panel: #1e2733;
  --text: #dde5ee;
  --text-dim: #8fa1b5;
  --water: #d64541;
  --accent: #6fb3e0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--backboard);
  color: var(--text);
  font-family: -apple-system, system-ui, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

header {
  width: 100%;
  max-width: 520px;
  padding: 0.9rem 1rem 0.3rem;
}
header h1 { font-size: 1.05rem; margin: 0; font-weight: 650; }
header p { margin: 0.25rem 0 0; color: var(--text-dim); font-size: 0.8rem; }
header a { color: var(--accent); }

/* The machine: portrait column, full width on phone, capped on desktop */
#machine {
  width: 100%;
  max-width: 520px;
  padding: 0 0.5rem;
}
#machine svg { width: 100%; height: auto; display: block; }

/* Controls: a row of large touch targets; sticks to the bottom on phones */
#controls {
  width: 100%;
  max-width: 520px;
  display: flex;
  gap: 0.5rem;
  padding: 0.7rem 1rem calc(0.7rem + env(safe-area-inset-bottom));
  position: sticky;
  bottom: 0;
  background: color-mix(in srgb, var(--backboard) 88%, transparent);
  backdrop-filter: blur(6px);
}
#controls button {
  flex: 1;
  min-height: 44px;
  border: 1px solid var(--text-dim);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
#controls button:active { background: #2a3646; }

footer {
  width: 100%;
  max-width: 520px;
  padding: 0.5rem 1rem 1.2rem;
  color: var(--text-dim);
  font-size: 0.75rem;
}
footer a { color: var(--accent); }

/* Controls as a grid of touch targets */
#controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}
#controls button.wide { grid-column: span 4; }
#controls button.wide2 { grid-column: span 2; }

/* Mechanism hit areas: invisible until hovered/pulsed */
.hit {
  fill: transparent;
  stroke: transparent;
  stroke-width: 2;
  cursor: pointer;
  pointer-events: all;
}
.hit:hover { stroke: #ffd479; stroke-opacity: 0.5; }

/* Ghost areas sit over draggable levers: highlight-only, never intercept */
.hit.ghost { pointer-events: none; }

/* Draggable levers (plates, hand-wheel): grab cursor; touch-action scoped
   here so dragging a lever doesn't scroll the page, but the rest of the
   machine still scrolls normally on phones */
.grab {
  cursor: grab;
  touch-action: none;
}
.grab:active { cursor: grabbing; }
.hit.active {
  stroke: #ffd479;
  stroke-opacity: 0.95;
  stroke-width: 2.5;
  animation: hitpulse 1.1s ease-in-out infinite;
}
@keyframes hitpulse {
  50% { stroke-opacity: 0.35; }
}

/* Inspector card: bottom sheet */
#card {
  position: fixed;
  left: 50%;
  transform: translate(-50%, 110%);
  bottom: 0;
  width: 100%;
  max-width: 520px;
  background: var(--panel);
  border: 1px solid #3a4a5d;
  border-bottom: none;
  border-radius: 16px 16px 0 0;
  padding: 0.9rem 1.1rem calc(1rem + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0,0,0,0.5);
  transition: transform 0.25s ease;
  z-index: 30;
  max-height: 60dvh;
  overflow-y: auto;
}
#card.show { transform: translate(-50%, 0); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.card-m {
  font-size: 0.7rem; color: var(--backboard); background: var(--accent);
  border-radius: 5px; padding: 0.1rem 0.35rem; font-weight: 700;
  margin-right: 0.4rem; white-space: nowrap;
}
.card-title { font-weight: 650; font-size: 1rem; }
.card-close {
  border: none; background: none; color: var(--text-dim);
  font-size: 1.1rem; cursor: pointer; padding: 0.2rem 0.4rem; min-height: 44px;
}
.card-body { font-size: 0.88rem; line-height: 1.45; color: var(--text); }
.card-body p { margin: 0.5rem 0; }
.card-body .eq {
  font-family: ui-monospace, monospace; background: #141a22;
  padding: 0.35rem 0.55rem; border-radius: 6px; font-size: 0.85rem;
}
.card-body .eq small { color: var(--text-dim); font-family: inherit; }
.card-body a { color: var(--accent); }
.card-source { margin-top: 0.6rem; font-size: 0.72rem; color: var(--text-dim); }
.eqlink {
  color: var(--accent);
  border-bottom: 1px dashed var(--accent);
  cursor: pointer;
}
.exp-btn {
  display: block; width: 100%; margin: 0.4rem 0; min-height: 44px;
  border: 1px solid var(--text-dim); border-radius: 10px;
  background: var(--backboard); color: var(--text);
  font-size: 0.9rem; font-weight: 600; cursor: pointer; text-align: left;
  padding: 0 0.8rem;
}

/* The nine-function panel */
.fn-row {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.3rem 0; border-bottom: 1px solid #2a3646;
}
.fn-label { flex: 1; font-size: 0.78rem; }
.fn-val {
  font-family: ui-monospace, monospace; font-size: 0.8rem;
  color: var(--accent); min-width: 3.2em; text-align: right;
}
.fn-na { font-size: 0.72rem; color: var(--text-dim); font-style: italic; }
.fn-btn {
  width: 40px; min-height: 36px;
  border: 1px solid var(--text-dim); border-radius: 8px;
  background: var(--backboard); color: var(--text);
  font-size: 1rem; font-weight: 700; cursor: pointer;
}

/* Experiment narration: floats above the controls */
#narr {
  position: fixed;
  left: 50%;
  transform: translate(-50%, 150%);
  bottom: 0;
  width: 100%;
  max-width: 520px;
  background: #24313f;
  border: 1px solid #3a4a5d;
  border-radius: 14px 14px 0 0;
  padding: 0.8rem 1rem calc(0.8rem + env(safe-area-inset-bottom));
  transition: transform 0.25s ease;
  z-index: 20;
}
#narr.show { transform: translate(-50%, 0); }
.narr-title { font-size: 0.75rem; color: var(--accent); font-weight: 700; }
.narr-text { font-size: 0.9rem; line-height: 1.45; margin: 0.4rem 0 0.6rem; }
.narr-buttons { display: flex; gap: 0.5rem; justify-content: flex-end; }
.narr-buttons button {
  min-height: 44px; padding: 0 1.2rem;
  border: 1px solid var(--text-dim); border-radius: 10px;
  background: var(--panel); color: var(--text);
  font-size: 0.9rem; font-weight: 600; cursor: pointer;
}
.narr-next { background: var(--accent) !important; color: #10151c !important; border: none !important; }

/* Desktop: give the machine air; controls no longer need to stick */
@media (min-width: 900px) {
  #controls { position: static; backdrop-filter: none; background: none; }
}
