/* Plasma Toroid Simulator — styles */
:root {
  --bg: #05060a;
  --card-bg: rgba(12, 14, 24, 0.86);
  --card-border: rgba(160, 170, 220, 0.22);
  --text: #e8eaf6;
  --text-muted: #b4b9d6;
  --accent: #a99bff;
  --safe: #34d399;
  --warm: #fbbf24;
  --danger: #f87171;
  --footer-h: 2.5rem; /* overwritten by ui.js with the measured footer height */
  --panel-w: 340px;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
}

#app {
  position: fixed;
  inset: 0;
  background: var(--bg);
}

#app canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  z-index: 2;
  top: 1rem;
  left: 1rem;
  bottom: calc(var(--footer-h) + 1rem);
  width: min(21rem, calc(100vw - var(--panel-w) - 2rem));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.75rem;
  pointer-events: none; /* let the orbit controls receive drags between the cards */
}

.hud-card {
  pointer-events: auto;
  padding: 0.7rem 0.9rem;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  backdrop-filter: blur(6px);
  font-size: 0.85rem;
}

.hud-card h2 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
  color: var(--accent);
}

.hud-card dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.15rem 0.9rem;
  margin: 0;
}

.hud-card dt {
  color: var(--text-muted);
}

.hud-card dd {
  margin: 0;
  font-family: var(--mono);
  text-align: right;
}

.hud-card dl.temps {
  grid-template-columns: auto 1fr auto;
  align-items: center;
}

.hud-card p {
  margin: 0.4rem 0 0;
}

.hud-note {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.hud-note:empty {
  display: none;
}

.limits {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.ttd-label {
  color: var(--text-muted);
}

.chip {
  display: inline-block;
  min-width: 4.2em;
  padding: 0 0.45rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 600;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

#temp-chart {
  display: block;
  width: 100%;
  height: 130px;
  margin-top: 0.4rem;
}

.level-safe { color: var(--safe); }
.level-warm { color: var(--warm); }
.level-danger { color: var(--danger); }

/* ---------- Danger banner ---------- */
#danger-banner {
  position: fixed;
  z-index: 6;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(30rem, calc(100vw - 2rem));
  padding: 0.7rem 1rem;
  background: #3b0d0d;
  border: 2px solid var(--danger);
  border-radius: var(--radius);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 0 24px rgba(248, 113, 113, 0.35);
}

#danger-banner[hidden] {
  display: none;
}

/* ---------- Control panel ---------- */
#panel {
  position: fixed;
  z-index: 3;
  top: 0;
  right: 0;
  bottom: var(--footer-h);
  width: var(--panel-w);
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border-left: 1px solid var(--card-border);
  backdrop-filter: blur(6px);
}

#panel.collapsed {
  bottom: auto;
  border-bottom: 1px solid var(--card-border);
  border-bottom-left-radius: var(--radius);
}

.panel-toggle {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 1rem;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--card-border);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

#panel.collapsed .panel-toggle {
  border-bottom: 0;
}

.panel-toggle .chev {
  transition: transform 0.15s;
}

#panel.collapsed .panel-toggle .chev {
  transform: rotate(180deg);
}

.panel-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.25rem 1rem 1rem;
}

.panel-body[hidden] {
  display: none;
}

.hint {
  margin: 0.5rem 0 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

fieldset {
  margin: 0.75rem 0 0;
  padding: 0.4rem 0.75rem 0.75rem;
  border: 1px solid var(--card-border);
  border-radius: 8px;
}

legend {
  padding: 0 0.35rem;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9rem;
}

.field {
  margin-top: 0.55rem;
  font-size: 0.88rem;
}

.field.select label {
  display: block;
  margin-bottom: 0.2rem;
}

.field.range {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.1rem 0.5rem;
  align-items: baseline;
}

.field.range input {
  grid-column: 1 / -1;
}

.field output,
.elapsed output {
  font-family: var(--mono);
  color: var(--text-muted);
}

.field.check {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 32px;
}

.field.check input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

select {
  width: 100%;
  min-height: 36px;
  padding: 0.3rem 0.5rem;
  background: #151829;
  color: var(--text);
  border: 1px solid rgba(160, 170, 220, 0.5);
  border-radius: 6px;
}

/* Range inputs: visible track, large thumb, focus ring from :focus-visible */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 26px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: #5a5f8a;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent);
}

input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: #5a5f8a;
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent);
}

.btn {
  min-height: 36px;
  padding: 0.4rem 0.8rem;
  background: #1d2140;
  color: var(--text);
  border: 1px solid rgba(169, 155, 255, 0.6);
  border-radius: 6px;
  cursor: pointer;
}

.btn:hover {
  background: #2a2f5a;
}

.btn.primary {
  background: #5b4bd6;
  border-color: #8f80ff;
  color: #fff;
  font-weight: 600;
}

.btn.primary[aria-pressed="true"] {
  background: #9b1c1c;
  border-color: var(--danger);
}

.preset-buttons {
  display: grid;
  gap: 0.4rem;
  margin-top: 0.3rem;
}

.preset-buttons .btn {
  text-align: left;
}

.sim-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.3rem;
}

.elapsed {
  margin: 0.6rem 0 0;
  font-size: 0.88rem;
}

.status-line {
  margin: 0.4rem 0 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ---------- Footer: always visible ---------- */
#footer {
  position: fixed;
  z-index: 4;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: 2.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1rem;
  padding: 0.45rem 1rem;
  background: rgba(5, 6, 10, 0.94);
  border-top: 1px solid var(--card-border);
  font-size: 0.8rem;
}

#footer .credit {
  font-weight: 600;
  color: var(--text);
}

#footer .disclaimer {
  color: var(--text-muted);
}

#footer .about-open {
  min-height: 28px;
  padding: 0.15rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 600;
}

/* ---------- About dialog ---------- */
.about-dialog {
  width: min(48rem, calc(100vw - 2rem));
  max-width: none;
  max-height: calc(100dvh - 2rem);
  padding: 0;
  overflow: hidden;
  background: #0c0e18; /* solid: --card-bg would let the canvas show through */
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: 0 0 40px rgba(169, 155, 255, 0.25);
}

.about-dialog::backdrop {
  background: rgba(5, 6, 10, 0.72);
  backdrop-filter: blur(3px);
}

.about-inner {
  display: flex;
  flex-direction: column;
  max-height: inherit;
}

.about-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem 0.75rem 1.25rem;
  border-bottom: 1px solid var(--card-border);
}

#about-title {
  margin: 0;
  font-size: 1.15rem;
  color: var(--accent);
}

.about-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0.5rem 1.25rem 1.25rem;
  font-size: 0.95rem;
  line-height: 1.55;
}

.about-body h3 {
  margin: 1.4rem 0 0.4rem;
  font-size: 1rem;
  color: var(--accent);
}

.about-body section:first-child h3 {
  margin-top: 0.75rem;
}

.about-body h4 {
  margin: 0.9rem 0 0.3rem;
  font-size: 0.92rem;
  color: var(--text);
}

.about-body p,
.about-body ul,
.about-body ol {
  margin: 0.4rem 0;
}

.about-body ul,
.about-body ol {
  padding-left: 1.3rem;
}

.about-body li + li {
  margin-top: 0.25rem;
}

.about-body code {
  padding: 0.05rem 0.3rem;
  background: #151829;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.88em;
}

.about-body a {
  color: var(--accent);
  text-decoration: underline;
}

.about-note {
  color: var(--text-muted);
  font-style: italic;
}

.about-params dt {
  margin-top: 0.6rem;
  font-weight: 700;
  color: var(--text);
}

.about-params dd {
  margin: 0.1rem 0 0;
  color: var(--text-muted);
}

.table-wrap {
  overflow-x: auto;
  margin: 0.5rem 0;
}

.about-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.about-table caption {
  margin-bottom: 0.3rem;
  color: var(--text-muted);
  text-align: left;
}

.about-table th,
.about-table td {
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--card-border);
  text-align: left;
  vertical-align: top;
}

.about-table thead th {
  color: var(--accent);
}

.about-table tbody th {
  font-weight: 600;
  white-space: nowrap;
}

.swatch {
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  margin-right: 0.25rem;
  vertical-align: -0.1em;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 3px;
}

.about-credit {
  margin: 1.5rem 0 0;
  padding-top: 0.75rem;
  border-top: 1px solid var(--card-border);
  font-weight: 600;
  text-align: center;
}

/* ---------- Fallback message ---------- */
.fallback {
  position: fixed;
  z-index: 5;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 32rem;
  padding: 1.25rem 1.5rem;
  background: var(--card-bg);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
}

.fallback h1 {
  margin: 0 0 0.5rem;
  font-size: 1.2rem;
  color: var(--danger);
}

.fallback[hidden] {
  display: none;
}

/* Focus visibility for every interactive element */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

button,
input,
select {
  font: inherit;
}

/* ---------- Short desktop windows: tighter HUD ---------- */
@media (min-width: 800px) and (max-height: 700px) {
  #temp-chart { height: 90px; }
  .hud-card { padding: 0.5rem 0.7rem; font-size: 0.8rem; }
}

/* ---------- Narrow screens: bottom sheet + stacked HUD ---------- */
@media (max-width: 799px) {
  #hud {
    top: 0.5rem;
    left: 0.5rem;
    right: 0.5rem;
    bottom: auto;
    width: auto;
    justify-content: flex-start;
    gap: 0.5rem;
  }

  .hud-card {
    padding: 0.5rem 0.7rem;
    font-size: 0.8rem;
  }

  .hud-card h2 {
    margin-bottom: 0.25rem;
    font-size: 0.85rem;
  }

  #hud-status dl.readouts {
    grid-template-columns: auto 1fr auto 1fr;
  }

  #temp-chart {
    height: 84px;
  }

  #danger-banner {
    top: 0.5rem;
  }

  #panel {
    top: auto;
    left: 0;
    right: 0;
    width: auto;
    max-height: 55vh;
    border-left: 0;
    border-top: 1px solid var(--card-border);
    border-radius: var(--radius) var(--radius) 0 0;
  }

  #panel.collapsed {
    bottom: var(--footer-h);
    border-bottom: 0;
    border-bottom-left-radius: 0;
  }

  .about-dialog {
    width: calc(100vw - 1rem);
    max-height: calc(100dvh - 1rem);
  }

  .about-header {
    padding: 0.5rem 0.75rem 0.5rem 0.9rem;
  }

  .about-body {
    padding: 0.5rem 0.9rem 1rem;
    font-size: 0.9rem;
  }
}
