/* Base styles */
:root {
  --bg: #f5f8fa;
  --bg-alt: #ffffff;
  --text: #1d343d;
  --accent: #0d6efd;
  --accent-alt: #0b5ed7;
  --border: #b6c6cf;
  --danger: #b00020;
  --radius: 10px;
  --shadow: 0 2px 4px -1px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.12);
  font-family: system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,sans-serif;
}
:root.dark {
  --bg: #111a1e;
  --bg-alt: #1c282d;
  --text: #f1f5f7;
  --accent: #4dabf7;
  --accent-alt: #329af0;
  --border: #2f3e44;
}
* { box-sizing: border-box; }
html, body { margin:0; padding:0; background: var(--bg); color: var(--text); }
body { line-height:1.45; -webkit-font-smoothing: antialiased; }

.visually-hidden { position:absolute; left:-9999px; width:1px; height:1px; overflow:hidden; }

header.app-header, .app-footer { display:flex; align-items:center; justify-content:space-between; padding:0.75rem 1rem; background:var(--bg-alt); border-bottom:1px solid var(--border); }
.app-footer { flex-direction:column; gap:0.4rem; border-top:1px solid var(--border); box-shadow: var(--shadow); }
header h1 { font-size: clamp(1.2rem, 4vw, 1.8rem); margin:0; }

main { padding: 0.75rem 1rem 2.5rem; max-width:1200px; margin:0 auto; display:grid; gap:1.2rem; }

.experiment { background:var(--bg-alt); border:1px solid var(--border); border-radius:var(--radius); padding:0.8rem; box-shadow:var(--shadow); }
.scene-wrapper { display:flex; flex-wrap:wrap; gap:1rem; }
.scene { flex:1 1 320px; min-width:280px; background:linear-gradient(#edf6fa,#dceef7); border:1px solid var(--border); border-radius:var(--radius); position:relative; overflow:hidden; }
.scene svg { width:100%; height:auto; display:block; }
.controls { flex:1 1 240px; min-width:240px; display:flex; flex-direction:column; gap:0.75rem; }
.controls label { font-weight:600; display:flex; flex-direction:column; gap:0.25rem; font-size:0.9rem; }
.controls input[type=range] { width:100%; }
.step-buttons { display:flex; gap:0.4rem; flex-wrap:wrap; }
.step-buttons button { flex:1 1 48px; }
.readouts p { margin:0.25rem 0; font-size:0.85rem; }
.trial-box { border:1px solid var(--border); border-radius: var(--radius); padding:0.6rem; display:flex; flex-direction:column; gap:0.5rem; background:var(--bg); }
.trial-stats { display:grid; grid-template-columns:repeat(auto-fit,minmax(110px,1fr)); gap:0.4rem; font-size:0.75rem; }
.trial-buttons { display:flex; gap:0.5rem; flex-wrap:wrap; }

.results { background:var(--bg-alt); border:1px solid var(--border); border-radius:var(--radius); padding:0.8rem; box-shadow:var(--shadow); }
.table-wrapper { overflow-x:auto; }
#resultsTable { width:100%; border-collapse:collapse; font-size:0.75rem; }
#resultsTable th,#resultsTable td { padding:0.4rem 0.5rem; border:1px solid var(--border); text-align:center; }
#resultsTable tbody tr:nth-child(even){ background: var(--bg); }

.explanation { background:var(--bg-alt); border:1px solid var(--border); border-radius:var(--radius); padding:0.8rem; box-shadow:var(--shadow); font-size:0.9rem; }
.explanation code { background: var(--bg); padding:0.1rem 0.3rem; border-radius:4px; font-size:0.85rem; }

/* Inline term tooltip */
.term { background: none; border: none; color: var(--accent); text-decoration: underline dotted; padding:0 0.15rem; cursor: pointer; font:inherit; position:relative; font-weight:600; }
.term:hover, .term:focus-visible { color: var(--accent-alt); }
.term:focus-visible { outline:2px solid var(--accent); }
.term-definition { display:inline-block; background: var(--bg-alt); border:1px solid var(--border); padding:0.45rem 0.6rem; border-radius:6px; max-width:320px; font-size:0.75rem; line-height:1.2; box-shadow: var(--shadow); position:relative; margin-left:0.4rem; }
.term-definition[data-show] { animation: fadeIn 120ms ease-out; }
/* Ensure hidden attribute always hides tooltip */
.term-definition[hidden] { display:none !important; }
@keyframes fadeIn { from { opacity:0; transform:translateY(-2px);} to { opacity:1; transform:translateY(0);} }

button, input, select { font: inherit; }
button { cursor:pointer; background:var(--accent); border:none; color:#fff; padding:0.55rem 0.8rem; border-radius:6px; font-size:0.8rem; line-height:1; box-shadow:0 1px 2px rgba(0,0,0,0.2); transition: background .15s; }
button:hover, button:focus-visible { background:var(--accent-alt); }
button:disabled { opacity:0.55; cursor:not-allowed; }
button.ghost-btn { background:transparent; color:var(--accent); border:1px solid var(--accent); }
button.ghost-btn:hover { background:var(--accent); color:#fff; }
button.primary { font-weight:600; }
button.link-btn { background:none; border:none; padding:0; color:var(--accent); text-decoration:underline; }
button[aria-pressed="true"] { box-shadow:0 0 0 2px var(--accent) inset; }

.export-buttons { margin-top:0.6rem; }

#advancedPanel { display:flex; gap:0.6rem; flex-wrap:wrap; }
#advancedPanel label { font-size:0.75rem; font-weight:500; display:flex; flex-direction:column; }
#advancedPanel input { width:6rem; }

/* Dark mode adjustments */
:root.dark .scene { background:linear-gradient(#132126,#0f1a1e); }
:root.dark #resultsTable tbody tr:nth-child(even){ background:#1b262c; }
:root.dark button.ghost-btn { color:var(--accent); border-color:var(--accent); }
:root.dark button.ghost-btn:hover { background:var(--accent); color:#0d1417; }

/* Chart canvas responsive */
#resultsChart { width:100%; height:auto; max-height:340px; background:var(--bg); border:1px solid var(--border); border-radius:var(--radius); }

/* Mobile layout */
@media (max-width: 760px) {
  main { grid-template-columns:1fr; }
  .scene-wrapper { flex-direction:column; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .bubble { animation: none !important; transition:none !important; }
}

/* Bubble animation classes (injected) */
.bubble { fill:#fff; opacity:0.9; }

/* Ruler tick styling via direct elements created dynamically */

/* Accessibility focus outline */
:focus-visible { outline:2px solid var(--accent); outline-offset:2px; }
