/* Lifting Magnet Lab — "Hold or Drop" */

:root {
  --accent:       #004445;
  --accent-light: #006668;
  --focus-glow:   #FFD166;
  --ink:          #2C3E3E;
  --muted:        #5A6E6E;
  --panel-border: #D8E2DF;
  --chosen-bg:    #E3F0EE;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: #F5F1E5;
  font-family: Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#sim-app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

#stage-panel {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#sim-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#sim-canvas:focus-visible {
  outline: 2px solid #60a5fa;
  outline-offset: -2px;
}

/* ── Control panel (floating card, top right) ──
   It used to be a full-height rail carrying six control groups. Every one of
   those became a scene object across rounds 3 and 4, so it now holds the run
   action and the result and is sized to its content: a card floating over the
   yard rather than a column reserved beside it.
   The scene keeps the full width underneath. Safe because the card sits at the
   top and the scene's tall objects are all along the bottom — the handler's roof
   clears the card by ~200 px at desktop, and the boom rises away to the left. */
.panel {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: 0 3px 14px rgba(0, 40, 40, 0.12);
}

#control-panel {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 252px;
  /* No `bottom`: the card hugs its content. The cap is only a backstop for a
     very short frame or a long translation. */
  max-height: calc(100% - 20px);
  padding: 11px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.group-head {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1.5px solid var(--chosen-bg);
  padding-bottom: 3px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Option pips: one row, equal widths. A grid rather than flex because
   flex-grow filled the row and pushed the 4th pip onto a second line. */
.pip-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 5px;
}

/* Material has four longer labels — 2×2 grid keeps every target ≥24px tall. */
.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.choice-btn {
  font-family: Roboto, Arial, sans-serif;
  font-size: 12.5px;
  font-weight: 500;
  min-height: 30px;
  padding: 5px 6px;
  border: 1.5px solid var(--panel-border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.choice-btn:hover:not(:disabled) {
  background: #F2F7F6;
}

.choice-btn.active,
.choice-btn[aria-checked="true"] {
  background: var(--chosen-bg);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}

.choice-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.choice-btn:focus-visible {
  outline: 3px solid var(--focus-glow);
  outline-offset: 1px;
}

.primary-btn {
  font-family: Roboto, Arial, sans-serif;
  font-size: 15px;
  font-weight: 700;
  min-height: 42px;
  padding: 10px 12px;
  border: none;
  border-radius: 9px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  transition: background 0.15s;
}

.primary-btn:hover:not(:disabled) {
  background: var(--accent-light);
}

.primary-btn:disabled {
  background: #B7C6C4;
  cursor: not-allowed;
}

.primary-btn:focus-visible {
  outline: 3px solid var(--focus-glow);
  outline-offset: 2px;
}

/* ── In-scene controls (v0.3.0) ──
   Real buttons over the canvas rather than canvas hit-testing, so focus order,
   roles and keyboard activation come for free and every target clears 24px.
   The layer itself is inert; only the controls take pointer events. */
#scene-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#scene-controls > * { position: absolute; pointer-events: auto; }

/* Info dots: one beside each variable, positioned from geom() like the hit
   targets. Visible, unlike .hit — they have nothing drawn underneath them. */
/* The "?" itself is drawn on the canvas, in the caption's own font and size, so
   it reads as part of the running text rather than as a badge stuck beside it.
   These are the transparent targets over it — same split as .hit. */
.info-dot {
  position: absolute;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: transparent;
  cursor: pointer;
  z-index: 3;
}

.info-dot:focus-visible {
  outline: 3px solid var(--focus-glow);
  outline-offset: 1px;
  border-radius: 4px;
}

#info-pop {
  position: absolute;
  z-index: 4;
  max-width: 220px;
  padding: 9px 11px;
  background: #ffffff;
  border: 1.5px solid var(--accent);
  border-radius: 9px;
  box-shadow: 0 4px 16px rgba(0, 40, 40, 0.18);
  font-size: 12.5px;
  line-height: 1.42;
  color: var(--ink);
}

/* Transparent hit targets over canvas-drawn objects. Invisible until focused,
   so the scene carries the appearance and these carry focus, roles and keys. */
.hit {
  /* MUST be positioned: these sit inside #coupon-rack / #dial-picker, so the
     `#scene-controls > *` rule does not reach them and they would otherwise
     stack in normal flow at the container origin — visible controls unclickable,
     invisible targets piled at the top of the canvas. */
  position: absolute;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  border-radius: 6px;
}

.hit:hover:not(:disabled) { background: rgba(0, 68, 69, 0.10); }

.hit:focus-visible {
  outline: 3px solid var(--focus-glow);
  outline-offset: 1px;
}

.hit:disabled { cursor: not-allowed; }

#coupon-rack.dragging .hit { cursor: grabbing; }

/* Live mass, moved out of the scene into the result card. */
#mass-live {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 5px;
  margin-bottom: 6px;
}

#mass-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#mass-value {
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
}

/* ── Action dock (Run + Result, pinned to the bottom of the panel) ──
   The dock is what sticks, not the result card: sticking the card alone let it
   cover the Run button as soon as the setup groups overflowed. */
/* Was sticky, with a white shadow to mask the groups scrolling under it. With
   nothing left to scroll, it is just the grouping of the action and its
   result. */
#action-dock {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#results-card {
  background: #ffffff;
  border: 1.5px solid var(--accent);
  border-radius: 10px;
  padding: 9px 10px;
}

.results-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

#run-tag {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}

#status-line {
  font-size: 12px;
  line-height: 1.4;
  color: var(--ink);
}

#capacity-line {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  margin: 2px 0 6px;
}

#capacity-line.nolift {
  font-size: 15px;
  color: #B4522B;
}

#log-btn {
  width: 100%;
  font-family: Roboto, Arial, sans-serif;
  font-size: 13px;
  font-weight: 600;
  min-height: 32px;
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  background: #ffffff;
  color: var(--accent);
  cursor: pointer;
}

#log-btn:hover:not(:disabled) {
  background: var(--chosen-bg);
}

#log-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#log-btn:focus-visible {
  outline: 3px solid var(--focus-glow);
  outline-offset: 2px;
}

.muted {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  margin-top: 4px;
}

/* ── Breakpoint 640: stack instead of shrinking ──
   Six groups need the full panel width to keep every pip at a ≥24px target, so
   below 640 the panel stops being a side rail and becomes a full-width column
   under the scene. The panel is sized to its content here too, and the scene
   takes whatever is left rather than being pinned to a fixed share — with only
   the run action and the result in it, a fixed share left a tall band of empty
   white below the card. */
@media (max-width: 639px) {
  #stage-panel {
    display: flex;
    flex-direction: column;
  }

  /* A bounded share, not a growing one. The scene is width-limited at these
     sizes, so extra canvas height cannot make it bigger — it only stretches the
     picture's sky and ground around a rig that stays the same size. Any surplus
     is better left as page padding under the card. */
  #sim-canvas {
    flex: 0 1 auto;
    height: 56%;
    min-height: 0;
  }

  #control-panel {
    position: static;
    inset: auto;
    width: auto;
    flex: 0 0 auto;
    max-height: none;
    margin: 8px;
    min-height: 0;
  }

  /* Two columns for the option groups while the width still allows it. */
}

@media (max-width: 479px) {
  .choice-grid { grid-template-columns: 1fr; }
  .choice-btn { font-size: 12px; }
}

/* ── Accessibility ── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .choice-btn, .primary-btn { transition: none; }
}

/* ── Reset confirmation dialog ── */
#reset-dialog {
  border: none;
  border-radius: 12px;
  padding: 20px;
  width: min(400px, calc(100vw - 32px));
  margin: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.22);
  background: #ffffff;
  color: var(--ink);
}

#reset-dialog::backdrop {
  background: rgba(30, 16, 48, 0.55);
}

#reset-dialog h2 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 8px;
}

#reset-dialog p {
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 16px;
}

.reset-dialog-controls {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-btn {
  font-family: Roboto, Arial, sans-serif;
  font-size: 13px;
  font-weight: 700;
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
  border: none;
  background: #5c4738;
  color: #ffffff;
}

.modal-btn:hover { background: #7d6c60; }

.modal-btn.secondary {
  background: #ffffff;
  color: #5c4738;
  border: 1.5px solid #5c4738;
}

.modal-btn.secondary:hover { background: #efedeb; }

.modal-btn:focus-visible {
  outline: 3px solid var(--focus-glow);
  outline-offset: 2px;
}

/* ── Info dialog ──
   The dialog is Tuva Sims "chrome", so its accent is the P1 purple (#5c4738),
   NOT the sim's green var(--accent). The shared toolbar stylesheet also injects
   these purple rules (scoped to #info-dialog) — keep this block in sync with it. */
#info-dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 80px);
  overflow: hidden;
  margin: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.22);
  background: #ffffff;
}

#info-dialog::backdrop {
  background: rgba(30, 16, 48, 0.55);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: #5c4738;
  color: #ffffff;
}

.dialog-header h2 {
  font-size: 16px;
  font-weight: 600;
}

#dialog-close-btn {
  background: transparent;
  border: none;
  color: #ffffff;
  font-size: 18px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

#dialog-close-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

#dialog-close-btn:focus-visible {
  outline: 3px solid var(--focus-glow);
  outline-offset: 2px;
}

.dialog-tabs {
  display: flex;
  border-bottom: 2px solid #E5EAE9;
  background: #F8FBFB;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  padding: 10px 0;
  font-family: Roboto, Arial, sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover {
  color: #5c4738;
}

.tab-btn.active,
.tab-btn[aria-selected="true"] {
  color: #5c4738;
  border-bottom-color: #5c4738;
}

.tab-btn:focus-visible {
  outline: 3px solid var(--focus-glow);
  outline-offset: -3px;
}

.dialog-body {
  padding: 16px 20px;
  overflow-y: auto;
  max-height: calc(100vh - 240px);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
}

.dialog-body h3 {
  font-size: 14px;
  font-weight: 600;
  color: #5c4738;
  margin-top: 14px;
  margin-bottom: 6px;
}

.dialog-body h3:first-child {
  margin-top: 0;
}

.dialog-body p {
  margin-bottom: 8px;
}

.dialog-body ul,
.dialog-body ol {
  padding-left: 20px;
  margin-bottom: 8px;
}

.dialog-body li {
  margin-bottom: 4px;
}

.dialog-body dl {
  margin-bottom: 8px;
}

.dialog-body dt {
  font-weight: 600;
  margin-top: 6px;
}
