/* ── Ideal Gas Law Simulator — style.css v=4 ──────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d1117;
  --surface:   #161b27;
  --surface2:  #1f2535;
  --border:    #2a3050;
  --accent:    #9c27b0;
  --accent-lo: rgba(156,39,176,.22);
  --green:     #3ddc84;
  --red:       #ff5555;
  --gold:      #f5c842;
  --text:      #dde3f0;
  --text-dim:  #6b7a99;
  --font:      'Segoe UI', system-ui, sans-serif;
  --mono:      'Courier New', monospace;
  --radius:    12px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  padding: 0 16px 48px;
}

#app {
  max-width: 1020px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── Header ─────────────────────────────────────────────── */
header { text-align: center; padding: 6px 0 2px; }
header h1 {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(120deg, var(--accent) 0%, #ce93d8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.subtitle { color: var(--text-dim); font-size: 0.84rem; margin-top: 4px; }

/* ── Controls bar ────────────────────────────────────────── */
.controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.ctrl-group { display: flex; align-items: center; gap: 8px; }
.ctrl-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-dim);
  white-space: nowrap;
}
.pill-tabs { display: flex; background: var(--bg); border-radius: 8px; padding: 3px; gap: 2px; }
.pill {
  padding: 5px 13px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: background .15s, color .15s, box-shadow .15s;
}
.pill.active { background: var(--accent); color: #fff; box-shadow: 0 0 12px var(--accent-lo); }
.pill:hover:not(.active) { background: var(--surface2); color: var(--text); }

/* ── Formula banner ─────────────────────────────────────── */
.formula-banner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 20px;
  padding: 12px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
}
.formula-highlight {
  font-size: 1.5rem;
  font-weight: 800;
  font-family: var(--mono);
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent-lo);
  white-space: nowrap;
}
.formula-parts { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.fp {
  font-size: 0.88rem;
  color: var(--text-dim);
  padding: 3px 10px;
  border-radius: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  white-space: nowrap;
  transition: border-color .2s, color .2s;
}
.fp strong { color: var(--text); font-weight: 700; }
.fp.solved {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(156,39,176,.12);
}
.fp.solved strong { color: #ce93d8; }
.fp-dot { color: var(--text-dim); }

/* ── Sim canvas ──────────────────────────────────────────── */
.sim-canvas-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  overflow-x: clip;
}
.sim-canvas-wrap canvas { display: block; width: 100%; height: auto; touch-action: pan-y; }

/* ── Variable panel (solve-for + cards) ─────────────────── */
.var-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
/* clip grid cells to follow panel corners */
.var-cards {
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
}

.solve-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.solve-label {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
  white-space: nowrap;
}
.gas-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.var-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.var-card {
  padding: 14px 16px 12px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  transition: background .2s;
  position: relative;
}
.var-card:nth-child(2n) { border-right: none; }
.var-card:nth-last-child(-n+2) { border-bottom: none; }

.var-card.solved-row {
  background: rgba(156,39,176,.07);
  border-color: transparent;
  box-shadow: inset 0 0 0 1.5px var(--accent);
}

.var-card-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.var-symbol {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 800;
  font-family: var(--mono);
  flex-shrink: 0;
}
.var-P { background: rgba(156,39,176,.18); color: #ce93d8; }
.var-V { background: rgba(33,150,243,.18); color: #64b5f6; }
.var-T { background: rgba(255,152,0,.18);  color: #ffb74d; }
.var-n { background: rgba(76,175,80,.18);  color: #81c784; }

.var-name-wrap {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}
.var-name {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.var-unit-hint {
  font-size: 0.66rem;
  color: var(--text-dim);
}

.var-val {
  font-size: 0.85rem;
  font-family: var(--mono);
  font-weight: 700;
  color: var(--text);
  text-align: right;
  white-space: nowrap;
}
.var-card.solved-row .var-val { color: #ce93d8; }

.solved-badge {
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(156,39,176,.18);
  border: 1px solid rgba(156,39,176,.4);
  border-radius: 4px;
  padding: 2px 6px;
  white-space: nowrap;
  flex-shrink: 0;
}

.var-slider-wrap {
  position: relative;
}
input[type="range"] {
  display: block;
  width: 100%;
  height: 4px;
  accent-color: var(--accent);
  cursor: pointer;
}
input[type="range"]:disabled {
  accent-color: var(--border);
  cursor: not-allowed;
  opacity: 0.5;
}

/* Locked toast notification — global, fixed positioned via JS */
#locked-toast {
  position: fixed;
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  pointer-events: none;
  z-index: 9999;
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
  display: none;
}
#locked-toast.visible {
  display: block;
  animation: toastPop .2s ease-out;
}
#locked-toast.blink {
  animation: toastBlink .45s ease-out 2;
}
.locked-toast.blink {
  animation: toastBlink .5s ease-out 2;
}
@keyframes toastPop {
  from { opacity: 0; transform: translateX(-50%) translateY(4px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes toastBlink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* ── Canvas action row (export + hint) ─────────────────── */
.canvas-action-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 4px 2px 0;
}
.canvas-hint {
  font-size: 0.72rem;
  color: var(--text-dim);
  flex: 1;
}
.canvas-hint kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.68rem;
  background: var(--surface2);
  color: var(--text);
}
.btn-sm { padding: 5px 12px; font-size: 0.76rem; }

/* ── Dot hover tooltip ───────────────────────────────────── */
#dot-tooltip {
  position: fixed;
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 4px 11px;
  font-size: 0.78rem;
  font-family: var(--mono);
  font-weight: 600;
  color: #ce93d8;
  pointer-events: none;
  z-index: 200;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,.45);
}

/* ── Formula flash animation ─────────────────────────────── */
@keyframes fpFlash {
  0%   { box-shadow: 0 0 0 2px var(--accent), 0 0 14px rgba(156,39,176,.65); }
  100% { box-shadow: none; }
}
.fp.flashing {
  animation: fpFlash 0.65s ease-out forwards;
}

/* ── Explore mode ────────────────────────────────────────── */
.exp-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.exp-tab {
  padding: 7px 18px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.83rem;
  font-weight: 600;
  transition: background .15s, color .15s;
}
.exp-tab.active { background: var(--accent); color: #fff; }
.exp-tab:hover:not(.active) { background: var(--surface2); color: var(--text); }

.concept-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}
.concept-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color .2s;
}
.concept-card:hover { border-color: var(--accent); }
.cc-name {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
}
.cc-formula {
  font-family: var(--mono);
  font-size: 1rem;
  color: var(--accent);
  font-weight: 700;
}
.cc-unit {
  font-size: 0.74rem;
  color: var(--text-dim);
}
.cc-desc {
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.5;
}
.cc-example {
  font-size: 0.77rem;
  color: var(--text-dim);
  background: var(--surface2);
  border-radius: 6px;
  padding: 8px 10px;
  line-height: 1.5;
  border-left: 3px solid var(--accent);
}
.cc-example strong { color: var(--text); }

/* ── Practice mode ───────────────────────────────────────── */
.practice-bar { justify-content: flex-start; }
.prac-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.prac-question {
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
}
.prac-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.prac-input {
  width: 140px;
  padding: 8px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--mono);
}
.prac-input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.prac-unit {
  color: var(--text-dim);
  font-size: 0.85rem;
}
.feedback { font-size: 0.9rem; font-weight: 600; min-height: 1.2em; }
.feedback.ok  { color: var(--green); }
.feedback.err { color: var(--red); }
.prac-solution-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.7;
  white-space: pre-wrap;
  font-family: var(--mono);
}
.pbar-score { margin-left: auto; font-size: 0.84rem; color: var(--text-dim); }
.pbar-score span { color: var(--text); font-weight: 700; }

/* ── Quiz mode ───────────────────────────────────────────── */
.quiz-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.quiz-q { font-size: 1rem; line-height: 1.6; color: var(--text); }
.quiz-opts { display: flex; flex-direction: column; gap: 8px; }
.quiz-opt {
  padding: 10px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--text);
  text-align: left;
  transition: background .12s, border-color .12s;
}
.quiz-opt:hover:not(:disabled) { background: var(--border); border-color: var(--accent); }
.quiz-opt.correct { border-color: var(--green); background: rgba(61,220,132,.12); color: var(--green); }
.quiz-opt.wrong   { border-color: var(--red);   background: rgba(255,85,85,.12);  color: var(--red); }
.quiz-nav { display: flex; gap: 10px; }
.quiz-result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}
.qr-score { font-size: 2rem; font-weight: 800; }
.qr-score.perfect { color: var(--gold); }
.qr-score.good    { color: var(--green); }
.qr-score.poor    { color: var(--red); }
.qr-stars { font-size: 1.8rem; letter-spacing: 4px; }
.qr-breakdown { width: 100%; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.qr-row {
  padding: 8px 12px;
  border-radius: 6px;
  border-left: 3px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-dim);
  background: var(--surface2);
}
.qr-row.ok  { border-left-color: var(--green); }
.qr-row.err { border-left-color: var(--red); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  padding: 8px 18px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 600;
  transition: filter .15s, box-shadow .15s, opacity .15s;
}
.btn:disabled { opacity: 0.38; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:not(:disabled):hover { filter: brightness(1.15); box-shadow: 0 0 14px var(--accent-lo); }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border); }
.hidden { display: none !important; }

/* ── SEO article ─────────────────────────────────────────── */
.seo-article {
  margin-top: 24px;
  padding: 28px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.seo-article h2 { font-size: 1.15rem; font-weight: 700; color: var(--text); }
.seo-article h3 { font-size: 0.95rem; font-weight: 700; color: var(--accent); margin-top: 6px; }
.seo-article p  { font-size: 0.88rem; color: var(--text-dim); line-height: 1.7; }
.seo-article a  { color: var(--accent); text-decoration: none; }
.seo-article a:hover { text-decoration: underline; }

/* ── Responsive — 768px ──────────────────────────────────── */
@media (max-width: 768px) {
  .var-cards { grid-template-columns: 1fr; }
  .var-card:nth-child(2n) { border-right: 1px solid var(--border); }
  .var-card:nth-last-child(-n+2) { border-bottom: 1px solid var(--border); }
  .var-card:last-child { border-bottom: none; }
  .formula-banner { flex-direction: column; align-items: flex-start; gap: 8px; }
  .concept-grid { grid-template-columns: 1fr 1fr; }
  .gas-inline { margin-left: 0; }
  .solve-header { gap: 8px; }
}

/* ── Responsive — 500px ──────────────────────────────────── */
@media (max-width: 500px) {
  body { padding: 0 10px 32px; }
  header h1 { font-size: 1.45rem; }
  .formula-highlight { font-size: 1.2rem; }
  .concept-grid { grid-template-columns: 1fr; }
  .pill { padding: 5px 10px; font-size: 0.75rem; }
  .prac-input { width: 110px; }
  .controls-bar { padding: 10px 12px; gap: 8px; }
  .locked-toast { font-size: 0.68rem; white-space: normal; width: 180px; text-align: center; }
}
