:root {
  --ink: #17303f;
  --ink-soft: #4b6474;
  --paper: rgba(255, 255, 255, 0.86);
  --line: rgba(23, 48, 63, 0.12);
  --teal: #0f8f7e;
  --teal-deep: #0b6e61;
  --coral: #ff6b5b;
  --amber: #ffb83d;
  --shadow: 0 12px 30px rgba(23, 48, 63, 0.18);
  --radius: 16px;
  --bg: #d9e9f2;
}

/* La escena es siempre clara: la interfaz no cambia con el tema del sistema. */

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hud, .card, .dock { position: fixed; z-index: 2; }

.top {
  top: 14px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}
.top > * { pointer-events: auto; }
.brand { display: flex; flex-direction: column; gap: 6px; }
.brand h1 {
  margin: 0;
  font-size: clamp(18px, 2.4vw, 24px);
  font-weight: 800;
  letter-spacing: -0.01em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}
.chip {
  align-self: flex-start;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--teal);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.right { display: flex; align-items: center; gap: 10px; }
.steps { display: flex; gap: 6px; }
.steps i {
  width: 14px; height: 14px; border-radius: 50%;
  background: rgba(23, 48, 63, 0.15);
  transition: transform 0.3s ease, background 0.3s ease;
}
.steps i.now { background: var(--amber); transform: scale(1.25); }
.steps i.done { background: var(--teal); }

.card {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.left {
  position: fixed; z-index: 2; top: 84px; left: 16px; width: 262px;
  display: flex; flex-direction: column; gap: 10px; max-height: calc(100vh - 100px); overflow: auto;
}
.left .readout { position: static; }
.readout {
  width: 100%;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
}
.ph-block { display: grid; grid-template-columns: auto 1fr; align-items: baseline; gap: 2px 10px; }
.label { color: var(--ink-soft); font-weight: 600; }
.ph-value {
  grid-column: 1 / -1;
  font-size: 40px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
}
.ph-scale {
  grid-column: 1 / -1;
  position: relative;
  height: 10px;
  margin-top: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff4a3d, #ffd23f 35%, #38d39f 50%, #2f7bff 75%, #7b3fe4);
}
.ph-scale i {
  position: absolute;
  top: -4px;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: left 0.2s ease, background 0.2s ease;
}
.row { display: flex; justify-content: space-between; gap: 8px; }
.row span { color: var(--ink-soft); }
.row b { font-variant-numeric: tabular-nums; }
.row.flask { font-size: 12px; color: var(--ink-soft); white-space: pre-line; line-height: 1.5; }

.curve-panel {
  top: 84px;
  right: 16px;
  width: min(360px, calc(100vw - 32px));
  padding: 12px 14px;
}
.curve-panel h3, .card h2 { margin: 0 0 8px; font-size: 16px; }
.curve-panel canvas, .curve-canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 420 / 220;
  border-radius: 10px;
  background: #fff;
  display: block;
}
.note { margin: 8px 0 0; font-size: 12px; color: var(--ink-soft); line-height: 1.4; }

.dock {
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: min(640px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.panel {
  padding: 12px 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.panel label { font-weight: 700; font-size: 14px; }
.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; }
.inline input {
  width: 110px;
  padding: 9px 10px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: 700 16px system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
.inline input:focus { outline: 3px solid rgba(15, 143, 126, 0.35); border-color: var(--teal); }
.msg { margin: 6px 0 0; font-size: 14px; color: var(--ink-soft); line-height: 1.4; }
.ind-choices { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 8px; }
.ind-choice {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  padding: 10px; border-radius: 12px; border: 2px solid var(--line);
  background: #fff; color: var(--ink); cursor: pointer; text-align: left;
  font: inherit; font-size: 13px; transition: transform 0.15s ease, border-color 0.15s ease;
}
.ind-choice:hover { transform: translateY(-2px); }
.ind-choice.picked { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(15, 143, 126, 0.25); }
.ind-choice small { color: var(--ink-soft); font-size: 11px; }
.swatch { display: block; width: 100%; height: 12px; border-radius: 999px; }

.controls { display: grid; grid-template-columns: 1.6fr 1fr 1fr auto; gap: 8px; }
.howto {
  margin: 0; padding: 6px 12px; font-size: 12px; color: var(--ink); text-align: center; line-height: 1.4;
  background: var(--paper); border-radius: 12px;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 14px;
  padding: 13px 14px;
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 4px 0 rgba(23, 48, 63, 0.14), 0 8px 18px rgba(23, 48, 63, 0.12);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease, opacity 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 rgba(23, 48, 63, 0.14); }
.btn:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, #1fb59b, var(--teal)); color: #fff; }
.btn.accent { background: linear-gradient(180deg, #ff8a7c, var(--coral)); color: #fff; }
.btn.ghost { background: rgba(255, 255, 255, 0.7); }
.btn.small { padding: 9px 12px; font-size: 13px; border-radius: 12px; }
.btn.big { font-size: 17px; padding: 16px 14px; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 26, 36, 0.28);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.modal {
  width: min(520px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 22px 22px 18px;
  animation: pop-in 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.card-body { margin: 0 0 12px; line-height: 1.5; font-size: 15px; color: var(--ink); }
.formula {
  margin: 0 0 12px; padding: 10px 12px; border-radius: 12px;
  background: rgba(15, 143, 126, 0.12); font-weight: 800; font-size: 18px; text-align: center;
}
.card-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.card-actions .btn { min-width: 150px; }
.stars { display: flex; gap: 6px; font-size: 30px; margin: 4px 0 4px; }
.stars span { color: rgba(23, 48, 63, 0.2); }
.stars span.on { color: var(--amber); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.08); animation: twinkle 0.6s ease both; }
.stars span:nth-child(2).on { animation-delay: 0.1s; }
.stars span:nth-child(3).on { animation-delay: 0.2s; }

@keyframes pop-in {
  from { transform: scale(0.92) translateY(10px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes twinkle {
  from { transform: scale(0.4) rotate(-30deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.overlay.dim { opacity: 0.4; }

@media (max-width: 760px) {
  .top { top: 10px; left: 12px; right: 12px; }
  .brand h1 { font-size: 17px; }
  .steps i { width: 10px; height: 10px; }
  .left { top: 62px; left: 12px; right: 12px; width: auto; gap: 6px; }
  .readout {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 14px;
    padding: 10px 12px;
  }
  .ph-block { display: flex; align-items: center; gap: 10px; flex: 1 1 100%; }
  .ph-value { font-size: 30px; }
  .ph-scale { flex: 1; margin-top: 0; }
  .row { flex: 1 1 40%; font-size: 13px; }
  .row.flask { flex: 1 1 100%; font-size: 11px; line-height: 1.35; }
  .curve-panel { display: none; }
  .dock { bottom: 10px; left: 12px; right: 12px; width: auto; transform: none; }
  .ind-choices { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .ind-choice { padding: 7px; font-size: 12px; }
  .ind-choice small { font-size: 10px; }
  .controls { grid-template-columns: 1fr 1fr; }
  .controls .big { grid-column: 1 / -1; }
  .howto { display: none; }
  .btn { padding: 12px 10px; font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
