/* /watch — the world is the content.
 *
 * Design intent: the simulation frame dominates; every control is a small, quiet
 * thing arranged around its edges; research telemetry is dense and organised but
 * only appears when asked for. Nothing here should read as debug UI.
 */

.watch-root { display: flex; flex-direction: column; gap: 0.7rem; }

/* ------------------------------------------------------------------- status bar -- */

.watch-topbar { display: flex; align-items: stretch; gap: 0.6rem; }

.watch-status {
  flex: 1 1 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.7rem;
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(0,0,0,0.06)), var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.55rem 0.95rem;
  font-variant-numeric: tabular-nums;
  font-size: 0.92rem;
  line-height: 1.4;
}
.watch-status .name { font-weight: 700; letter-spacing: 0.01em; }
.watch-status .sep { color: var(--text-faint); opacity: 0.6; }
.watch-status .period { color: var(--text-faint); font-size: 0.86em; letter-spacing: 0.06em; }
.watch-status .west { color: #7fb6e8; }
.watch-status .east { color: #e8a97f; margin-left: -0.35rem; }
.watch-status .contact-yes { color: var(--accent-strong); font-weight: 600; }
.watch-status .contact-no { color: var(--text-faint); }

.conn {
  flex: 0 0 auto;
  align-self: center;
  font-size: 0.76rem;
  letter-spacing: 0.04em;
  padding: 0.32rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--text-faint);
  white-space: nowrap;
}
.conn.live { color: var(--accent-strong); border-color: var(--accent); }
.conn.live::before {
  content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent-strong); margin-right: 0.45rem; vertical-align: 1px;
}
.conn.stale { color: var(--danger); border-color: var(--danger); }

/* ------------------------------------------------------------------------ stage -- */

.watch-stage { display: flex; flex-direction: column; gap: 0.55rem; }

.watch-canvas-frame {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #05070a;
  height: clamp(360px, 76vh, 980px);
  touch-action: none;
}
@media (max-width: 640px) { .watch-canvas-frame { height: clamp(320px, 58vh, 580px); } }

.watch-canvas-frame:fullscreen,
.watch-canvas-frame:-webkit-full-screen { height: 100vh; border-radius: 0; border: none; }

/* In fullscreen the world should dominate: controls fade back until the pointer
   moves, then return. Touch counts as movement, so they are always reachable. */
.watch-canvas-frame:fullscreen .watch-zoom-controls,
.watch-canvas-frame:fullscreen .watch-side-controls,
.watch-canvas-frame:fullscreen .watch-overlay-note { opacity: 0.25; transition: opacity 0.5s ease; }
.watch-canvas-frame:fullscreen:hover .watch-zoom-controls,
.watch-canvas-frame:fullscreen:hover .watch-side-controls,
.watch-canvas-frame:fullscreen:hover .watch-overlay-note { opacity: 1; }

#watch-canvas { display: block; width: 100%; height: 100%; cursor: grab; }
#watch-canvas:active { cursor: grabbing; }

.watch-overlay-note {
  position: absolute; left: 0.8rem; bottom: 0.8rem;
  font-size: 0.78rem; letter-spacing: 0.01em;
  color: rgba(232, 238, 238, 0.86);
  background: rgba(6, 9, 9, 0.55);
  backdrop-filter: blur(6px);
  padding: 0.32rem 0.7rem; border-radius: 999px;
  pointer-events: none; max-width: 58%;
}

.watch-empty-note {
  position: absolute; top: 3.5rem; left: 50%; transform: translateX(-50%);
  font-size: 0.85rem; color: var(--text-dim);
  background: rgba(6, 9, 9, 0.78); border: 1px solid var(--line);
  padding: 0.4rem 0.95rem; border-radius: 999px;
  pointer-events: none; text-align: center; max-width: 82%;
}

/* --------------------------------------------------------------- first-time card -- */

.watch-first-time {
  position: absolute; inset: 0; z-index: 6;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(5,7,10,0.62), rgba(5,7,10,0.86));
  padding: 1.5rem;
}
.watch-first-time[hidden] { display: none; }
.ft-card {
  max-width: 34rem; text-align: center;
  background: rgba(9, 13, 16, 0.82);
  border: 1px solid var(--line); border-radius: calc(var(--radius) * 1.4);
  padding: 1.6rem 1.7rem; backdrop-filter: blur(10px);
}
.ft-lead { font-size: 1.15rem; font-weight: 700; margin: 0 0 0.6rem; color: var(--text); }
.ft-card p { margin: 0 0 0.7rem; color: var(--text-dim); font-size: 0.94rem; line-height: 1.55; }
.ft-hint { font-size: 0.84rem !important; color: var(--text-faint) !important; }
.watch-first-time button {
  font: inherit; font-weight: 600;
  background: var(--accent); color: #05100e; border: none; border-radius: 999px;
  padding: 0.55rem 1.5rem; cursor: pointer; margin-top: 0.4rem;
}

/* --------------------------------------------------------------------- badges --- */

.watch-badge-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.watch-badge {
  position: absolute; transform: translate(-50%, -100%);
  font-size: 0.62rem; font-weight: 700; letter-spacing: 0.06em;
  color: #05100e; background: var(--accent-strong);
  padding: 0.06rem 0.38rem; border-radius: 3px; white-space: nowrap;
  transition: opacity 0.35s linear;
}
.watch-badge.kind-injury { background: #e0655a; color: #200807; }
.watch-badge.kind-birth { background: #bfe8a0; }
.watch-badge.kind-death { background: #8a8f92; }
.watch-badge.kind-contact { background: #cbb8f2; }
.watch-badge.kind-manipulate { background: #d8c07a; }

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

.watch-zoom-controls, .watch-side-controls, .watch-field-bar {
  position: absolute; display: flex; gap: 0.25rem; z-index: 4;
  background: rgba(6, 9, 9, 0.5); backdrop-filter: blur(8px);
  padding: 0.28rem; border-radius: 999px;
}
.watch-zoom-controls { top: 0.8rem; left: 0.8rem; }
.watch-side-controls { top: 0.8rem; right: 0.8rem; align-items: center; }
.watch-side-sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 0.2rem; }

.watch-field-bar {
  bottom: 0.8rem; left: 50%; transform: translateX(-50%);
  flex-wrap: nowrap; justify-content: flex-start; max-width: calc(100% - 2rem);
  overflow-x: auto; scrollbar-width: none;
}
.watch-field-bar::-webkit-scrollbar { display: none; }
.watch-field-bar[hidden] { display: none; }

/* Relocated into the research panel on narrow viewports: an ordinary wrapping row
   of buttons rather than a floating overlay competing with the world for space. */
.watch-field-bar.in-panel {
  position: static; transform: none; max-width: none;
  flex-wrap: wrap; overflow: visible; backdrop-filter: none;
  background: transparent; padding: 0; margin-bottom: 0.9rem; gap: 0.35rem;
}
.watch-field-bar.in-panel .watch-field-btn {
  border-color: var(--line); font-size: 0.78rem; padding: 0.3rem 0.7rem;
}

/* The field bar occupies the bottom centre, which is where the view-mode note also
   sits; at desktop width they touch. Lift the note above the bar whenever research
   mode has the bar on screen. */
body.research-on .watch-overlay-note { bottom: 3.5rem; }

.watch-tier-btn, .watch-side-btn, .watch-field-btn {
  font: inherit; font-size: 0.76rem;
  background: transparent; color: var(--text-dim);
  border: 1px solid transparent; border-radius: 999px;
  padding: 0.24rem 0.66rem; cursor: pointer; white-space: nowrap;
}
.watch-tier-btn:hover, .watch-side-btn:hover, .watch-field-btn:hover { color: var(--text); }
.watch-tier-btn[aria-pressed="true"], .watch-side-btn[aria-pressed="true"],
.watch-field-btn[aria-pressed="true"] {
  background: var(--accent); color: #05100e; font-weight: 600;
}

.watch-field-legend {
  position: absolute; left: 0.8rem; top: 3.5rem; z-index: 4;
  display: flex; flex-direction: column; gap: 0.3rem;
  background: rgba(6, 9, 9, 0.72); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 0.55rem 0.75rem; max-width: min(26rem, 60%);
  font-size: 0.76rem; color: var(--text-dim);
}
.watch-field-legend[hidden] { display: none; }
.watch-field-legend strong { color: var(--text); font-size: 0.84rem; }
.lg-scale { display: flex; align-items: center; gap: 0.4rem; }
.lg-sw { width: 0.7rem; height: 0.7rem; border-radius: 2px; display: inline-block; flex: 0 0 auto; }
.lg-ramp { flex: 1 1 4rem; height: 0.55rem; border-radius: 3px; min-width: 3rem; }
.lg-note { color: var(--text-faint); line-height: 1.4; }

.watch-controls { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.watch-controls-spacer { flex: 1 1 auto; }
.watch-controls-hint { color: var(--text-faint); font-size: 0.8rem; }
.watch-controls-hint kbd {
  font: inherit; font-size: 0.74rem; border: 1px solid var(--line);
  border-radius: 4px; padding: 0 0.28rem; color: var(--text-dim);
}
.watch-controls button {
  font: inherit; background: var(--bg-card); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 0.42rem 1rem; cursor: pointer;
}
.watch-controls button:hover { border-color: var(--text-dim); }
.watch-controls button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent-strong); }

/* ------------------------------------------------------------------- inspector --- */

.watch-inspector {
  position: absolute; top: 0.8rem; right: 0.8rem; z-index: 5;
  width: min(21rem, calc(100% - 1.6rem));
  max-height: calc(100% - 1.6rem); overflow-y: auto;
  background: rgba(9, 13, 16, 0.9); backdrop-filter: blur(12px);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 0.85rem 1rem; font-size: 0.84rem; color: var(--text-dim);
}
.watch-inspector[hidden] { display: none; }
/* When the inspector is open it would sit under the island controls; push those
   controls out of its way rather than letting them overlap. */
.watch-canvas-frame:has(.watch-inspector:not([hidden])) .watch-side-controls { top: auto; bottom: 0.8rem; }

.watch-inspector header { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.6rem; }
.watch-inspector h3 {
  margin: 0; font-size: 0.98rem; color: var(--text); flex: 1 1 auto;
  display: flex; align-items: center; gap: 0.45rem;
}
.watch-inspector h4 {
  margin: 0.9rem 0 0.35rem; font-size: 0.76rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-faint);
}
.insp-close {
  font: inherit; font-size: 1.25rem; line-height: 1; background: none; border: none;
  color: var(--text-faint); cursor: pointer; padding: 0 0.2rem;
}
.insp-close:hover { color: var(--text); }

.insp-portrait { display: flex; justify-content: center; margin: 0.2rem 0 0.7rem; }
.insp-portrait canvas {
  image-rendering: pixelated; width: 96px; height: 96px;
  background: rgba(255,255,255,0.03); border-radius: 10px;
}

.insp-rows { display: grid; grid-template-columns: auto 1fr; gap: 0.24rem 0.75rem; margin: 0; }
.insp-rows dt { color: var(--text-faint); }
.insp-rows dd { margin: 0; color: var(--text); font-variant-numeric: tabular-nums; text-align: right; }

.insp-acts { list-style: none; margin: 0; padding: 0; font-size: 0.8rem; }
.insp-acts li { padding: 0.14rem 0; color: var(--text-dim); }

.traits { display: flex; flex-direction: column; gap: 0.22rem; }
.trait { display: grid; grid-template-columns: 8.5rem 1fr 2.2rem; gap: 0.5rem; align-items: center; font-size: 0.78rem; }
.tbar { background: rgba(255,255,255,0.08); border-radius: 3px; height: 0.42rem; overflow: hidden; }
.tbar i { display: block; height: 100%; background: var(--accent); }
.tval { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-faint); }

.insp-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.9rem; }
.insp-actions button {
  font: inherit; font-size: 0.78rem; background: rgba(255,255,255,0.05);
  color: var(--text); border: 1px solid var(--line); border-radius: 999px;
  padding: 0.32rem 0.8rem; cursor: pointer;
}
.insp-actions button:hover { border-color: var(--accent); color: var(--accent-strong); }

.lswatch {
  display: inline-block; width: 0.62rem; height: 0.62rem; border-radius: 2px; flex: 0 0 auto;
}

/* ------------------------------------------------------------ research panel ----- */

.watch-research-panel {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1.4rem;
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem 1.2rem;
}
.watch-research-panel[hidden] { display: none; }
@media (max-width: 860px) { .watch-research-panel { grid-template-columns: 1fr; } }
.watch-research-panel h2 {
  font-size: 0.78rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--text-faint); margin: 0 0 0.6rem; font-weight: 600;
}
.research-col > h2:not(:first-child) { margin-top: 1.4rem; }

.telemetry { display: flex; flex-direction: column; gap: 0.35rem; }
.tgroup { border: 1px solid var(--line); border-radius: 8px; padding: 0.35rem 0.7rem; }
.tgroup summary {
  cursor: pointer; font-size: 0.82rem; color: var(--text); padding: 0.2rem 0; font-weight: 600;
}
.tgroup dl {
  display: grid; grid-template-columns: 1fr auto; gap: 0.2rem 0.9rem;
  margin: 0.35rem 0 0.3rem; font-size: 0.82rem;
}
.tgroup dt { color: var(--text-faint); }
.tgroup dd { margin: 0; color: var(--text); font-variant-numeric: tabular-nums; text-align: right; }
.tgroup code { font-size: 0.76rem; color: var(--text-dim); }

.ltable { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.ltable th {
  text-align: left; font-weight: 500; color: var(--text-faint);
  font-size: 0.72rem; letter-spacing: 0.05em; text-transform: uppercase;
  padding: 0 0.4rem 0.3rem 0; border-bottom: 1px solid var(--line);
}
.ltable td { padding: 0.3rem 0.4rem 0.3rem 0; border-bottom: 1px solid var(--line); color: var(--text-dim); }
.ltable td:nth-child(2) { color: var(--text); }
.ltable tbody tr { cursor: pointer; }
.ltable tbody tr:hover td { color: var(--text); background: rgba(255,255,255,0.03); }
.ltable tr.sel td { color: var(--accent-strong); }
.ltable .bar {
  display: inline-block; width: 3rem; height: 0.4rem; border-radius: 2px;
  background: rgba(255,255,255,0.08); margin-right: 0.35rem; overflow: hidden; vertical-align: -1px;
}
.ltable .bar span { display: block; height: 100%; background: var(--accent); }

.charts { display: flex; flex-direction: column; gap: 1.1rem; }
.chart { margin: 0; }
.chart figcaption { font-size: 0.78rem; color: var(--text-faint); margin-bottom: 0.2rem; }
.chart svg { width: 100%; height: 86px; display: block; }
.chart svg .ax { fill: var(--text-faint); font-size: 9px; font-variant-numeric: tabular-nums; }
.chart svg .grid { stroke: rgba(255,255,255,0.08); stroke-width: 1; }
.chart-legend { display: flex; gap: 0.9rem; font-size: 0.76rem; color: var(--text-dim); margin-top: 0.15rem; }
.chart-legend i { display: inline-block; width: 0.55rem; height: 0.55rem; border-radius: 2px; margin-right: 0.3rem; }
.chart-legend b { color: var(--text); font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------- lower ---- */

.watch-lower {
  display: grid; grid-template-columns: 1fr 1.15fr 1fr; gap: 1.4rem; margin-top: 0.4rem;
}
@media (max-width: 980px) { .watch-lower { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px) { .watch-lower { grid-template-columns: 1fr; } }

.events-list { list-style: none; margin: 0.6rem 0 0; padding: 0; font-size: 0.86rem; max-height: 20rem; overflow-y: auto; }
.events-list li { padding: 0.35rem 0; border-bottom: 1px solid var(--line); color: var(--text-dim); }
.events-list li:last-child { border-bottom: none; }
.events-list .tick { color: var(--text-faint); margin-right: 0.5rem; font-variant-numeric: tabular-nums; }
.events-list button.event-jump {
  display: block; width: 100%; text-align: left; font: inherit;
  background: none; border: none; color: inherit; cursor: pointer; padding: 0;
}
.events-list button.event-jump:hover { color: var(--text); }

.legend { display: flex; gap: 0.5rem 1.1rem; flex-wrap: wrap; font-size: 0.84rem; color: var(--text-dim); margin-top: 0.7rem; }
.legend .swatch {
  display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 2px;
  margin-right: 0.35rem; vertical-align: -1px;
}
.muted { color: var(--text-faint); }
.small { font-size: 0.8rem; line-height: 1.5; }

/* ----------------------------------------------------------------- narrow view --- */

@media (max-width: 560px) {
  /* The status line wraps to three lines at phone width and ate a third of the
     first screenful before the world appeared. Same facts, tighter. */
  .watch-status { font-size: 0.8rem; gap: 0.4rem 0.55rem; padding: 0.45rem 0.65rem; line-height: 1.35; }
  .watch-status .name { flex-basis: 100%; font-size: 0.86rem; }
  .watch-status .sep { display: none; }
  .watch-status .period { font-size: 0.78em; }
  .conn { font-size: 0.68rem; padding: 0.24rem 0.55rem; }
  .watch-side-controls { top: auto; bottom: 0.65rem; right: 0.65rem; }
  .watch-zoom-controls { left: 0.65rem; top: 0.65rem; }
  .watch-tier-btn, .watch-side-btn, .watch-field-btn { font-size: 0.7rem; padding: 0.22rem 0.5rem; }
  .watch-overlay-note { max-width: 44%; font-size: 0.7rem; left: 0.65rem; bottom: 0.65rem; }
  /* At phone width the inspector is a bottom sheet, not a floating card: a
     side panel would cover most of the world it is describing. */
  .watch-inspector {
    top: auto; bottom: 0; left: 0; right: 0; width: auto;
    max-height: 62%; border-radius: 14px 14px 0 0; border-bottom: none;
  }
  .watch-canvas-frame:has(.watch-inspector:not([hidden])) .watch-side-controls { bottom: auto; top: 0.65rem; }
  /* The field bar is relocated into the research panel at this width (see
     `placeFieldBar` in watch.js), so it stops being an overlay entirely. */
  body.research-on .watch-overlay-note { bottom: 0.65rem; }
  .watch-field-legend { left: 0.65rem; right: 0.65rem; top: 3.2rem; max-width: none; }
  .trait { grid-template-columns: 7rem 1fr 2.2rem; }
  .watch-controls-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .watch-badge { transition: none; }
  .watch-canvas-frame:fullscreen .watch-zoom-controls,
  .watch-canvas-frame:fullscreen .watch-side-controls,
  .watch-canvas-frame:fullscreen .watch-overlay-note { transition: none; opacity: 1; }
}
