/* ══════════════════════════════════════════════════════
   PhysicsForge — Main Stylesheet
   Light theme default (projector-friendly), dark toggle
   ══════════════════════════════════════════════════════ */

/* ── Custom properties ── */
:root {
  --bg:        #f5f7fa;
  --surface:   #ffffff;
  --surface2:  #eef1f6;
  --border:    #d0d7e3;
  --text:      #1a1d24;
  --text2:     #5a6070;
  --accent:    #2563eb;
  --accent2:   #1d4ed8;
  --tab-act:   #2563eb;
  --tab-txt:   #ffffff;
  --header-bg: #1e293b;
  --header-fg: #f1f5f9;
  --danger:    #dc2626;
  --success:   #16a34a;
  --panel-w:   270px;
  --palette-w: 54px;
  --header-h:  48px;
  --timeline-h:34px;
  --footer-h:  26px;
  --radius:    6px;
  --shadow:    0 2px 8px rgba(0,0,0,.12);
  --font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

[data-theme="dark"] {
  --bg:       #0f1117;
  --surface:  #1a1d27;
  --surface2: #252836;
  --border:   #333748;
  --text:     #e8eaf0;
  --text2:    #8892a4;
  --accent:   #60a5fa;
  --accent2:  #3b82f6;
  --header-bg:#090b10;
  --header-fg:#e8eaf0;
}

[data-hc="true"] {
  --bg:#000; --surface:#111; --surface2:#222;
  --border:#fff; --text:#fff; --text2:#ccc;
  --accent:#ff0; --tab-act:#ff0; --tab-txt:#000;
}

/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

[data-dyslexic="true"] { font-family: 'OpenDyslexic', var(--font) !important; }

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ══════════════════════ HEADER ══════════════════════ */
#app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--header-bg);
  color: var(--header-fg);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  z-index: 100;
  user-select: none;
}

.logo {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .5px;
  white-space: nowrap;
  padding-right: 8px;
}

/* ── Lab tabs ── */
#lab-tabs {
  display: flex;
  gap: 2px;
  flex: 0 0 auto;
}

.tab {
  background: transparent;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: var(--radius);
  color: rgba(255,255,255,.7);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 12px;
  transition: background .15s, color .15s;
}
.tab:hover { background: rgba(255,255,255,.1); color: #fff; }
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Playback controls ── */
#playback-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

#playback-controls button {
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 4px 8px;
  transition: background .15s;
}
#playback-controls button:hover { background: rgba(255,255,255,.25); }

.ts-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  color: rgba(255,255,255,.8);
  font-size: 11px;
}
#time-scale { width: 70px; cursor: pointer; accent-color: var(--accent); }

/* ── Header action buttons ── */
#header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}
#header-actions button {
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: var(--radius);
  color: rgba(255,255,255,.85);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 8px;
  transition: background .15s;
  white-space: nowrap;
}
#header-actions button:hover { background: rgba(255,255,255,.2); }

/* ══════════════════════ MAIN LAYOUT ══════════════════════ */
#app-main {
  position: fixed;
  top: var(--header-h);
  bottom: calc(var(--timeline-h) + var(--footer-h));
  left: 0; right: 0;
  display: grid;
  grid-template-columns: var(--palette-w) 1fr var(--panel-w);
  overflow: hidden;
}

/* ── Tool palette ── */
#tool-palette {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 4px;
  gap: 2px;
}

#tool-buttons { display: flex; flex-direction: column; gap: 2px; }

.tool-btn {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  font-size: 10px;
  gap: 2px;
  justify-content: center;
  padding: 6px 2px;
  text-align: center;
  transition: background .12s, border-color .12s;
  width: 100%;
}
.tool-btn span.icon { font-size: 18px; line-height: 1; }
.tool-btn:hover { background: var(--surface2); border-color: var(--border); }
.tool-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tool-sep { height: 1px; background: var(--border); margin: 4px 0; }

/* ── Canvas area ── */
#canvas-area {
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

#sim-canvas, #overlay-canvas, #three-container {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
}

#overlay-canvas { pointer-events: none; z-index: 10; }
#three-container canvas { width: 100% !important; height: 100% !important; }

#canvas-hint {
  position: absolute;
  bottom: 8px; left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.5);
  color: #fff;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 10px;
  pointer-events: none;
  z-index: 20;
  opacity: 0;
  transition: opacity .4s;
}
#canvas-hint.show { opacity: 1; }

/* ── Right panel ── */
#right-panel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

#right-panel section {
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.panel-header {
  align-items: center;
  background: var(--surface2);
  display: flex;
  font-size: 11px;
  font-weight: 600;
  gap: 4px;
  letter-spacing: .5px;
  padding: 6px 8px;
  text-transform: uppercase;
}
.panel-header span { flex: 1; color: var(--text2); }
.panel-header button {
  background: transparent;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0 2px;
  border-radius: 3px;
}
.panel-header button:hover { background: var(--border); color: var(--text); }

.collapse-btn { font-size: 16px !important; }

/* Properties */
#props-body { padding: 8px; }
#props-content { font-size: 12px; color: var(--text2); }
#props-content .prop-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
}
#props-content .prop-row:last-child { border-bottom: none; }
#props-content .prop-label { color: var(--text2); }
#props-content .prop-val { font-weight: 600; font-variant-numeric: tabular-nums; }
#props-content input[type=range], #props-content input[type=number] {
  accent-color: var(--accent); width: 100%;
}
.prop-slider-row { flex-direction: column; align-items: flex-start !important; gap: 2px; }

/* Graph */
#graph-body { padding: 8px; }
#graph-canvas { width: 100%; border-radius: var(--radius); background: var(--surface2); display: block; }
#graph-legend { font-size: 11px; margin-top: 4px; }
.legend-item {
  display: flex; align-items: center; gap: 6px; padding: 2px 0;
  cursor: pointer;
}
.legend-swatch { width: 12px; height: 3px; border-radius: 2px; }
.legend-name { color: var(--text2); flex: 1; }
.legend-val { font-variant-numeric: tabular-nums; font-weight: 600; }

/* Energy */
#energy-body { padding: 6px 8px; display: flex; flex-direction: column; gap: 4px; }
.e-row { display: flex; align-items: baseline; gap: 4px; font-size: 12px; }
.e-label { color: var(--text2); width: 40px; }
.e-val { font-weight: 700; font-variant-numeric: tabular-nums; flex: 1; text-align: right; }
.e-unit { color: var(--text2); font-size: 10px; }
.e-row.total .e-val { color: var(--accent); font-size: 14px; }

/* Overlays */
#overlay-body { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
#overlay-body label { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 12px; }
.ov-swatch { width: 16px; height: 4px; border-radius: 2px; display: inline-block; }

/* ══════════════════════ TIMELINE ══════════════════════ */
#timeline-bar {
  position: fixed;
  bottom: var(--footer-h);
  left: 0; right: 0;
  height: var(--timeline-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 8px;
  gap: 8px;
  z-index: 90;
}

#timeline-canvas {
  flex: 1;
  height: 22px;
  border-radius: 4px;
  background: var(--surface2);
  cursor: pointer;
  display: block;
}

#sim-time-display {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text2);
  min-width: 48px;
  text-align: right;
}

/* ══════════════════════ FOOTER ══════════════════════ */
#app-footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--footer-h);
  background: var(--header-bg);
  color: rgba(255,255,255,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  letter-spacing: .3px;
  z-index: 90;
}

/* ══════════════════════ MODALS ══════════════════════ */
#modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
}
#modal-backdrop.hidden { display: none; }

.modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  z-index: 300;
  min-width: 280px;
}
.modal.hidden { display: none; }
.modal h2 { margin-bottom: 14px; font-size: 15px; }
.modal label {
  display: flex; flex-direction: column; gap: 4px;
  margin-bottom: 12px; font-size: 12px; color: var(--text2);
}
.modal select, .modal input {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 4px; color: var(--text); font-size: 13px;
  padding: 6px 8px; width: 100%;
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.modal-actions button, .modal-close {
  background: var(--accent); border: none; border-radius: 4px;
  color: #fff; cursor: pointer; font-size: 13px; padding: 6px 16px;
}
.modal-close { background: var(--surface2); color: var(--text); }

/* ══════════════════════ SIDE PANELS ══════════════════════ */
.side-panel {
  position: fixed;
  top: var(--header-h);
  right: 0;
  bottom: calc(var(--timeline-h) + var(--footer-h));
  width: 320px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 16px rgba(0,0,0,.15);
  overflow-y: auto;
  z-index: 150;
  display: flex;
  flex-direction: column;
}
.side-panel.hidden { display: none; }

.side-panel-header {
  align-items: center;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
  padding: 10px 14px;
  position: sticky;
  top: 0;
  z-index: 1;
}
.side-panel-header h2 { flex: 1; font-size: 14px; }
.panel-close {
  background: transparent;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px;
  border-radius: 3px;
}
.panel-close:hover { background: var(--border); color: var(--text); }

.ct-section {
  border-bottom: 1px solid var(--border);
  padding: 12px 14px;
}
.ct-section h3 { font-size: 12px; font-weight: 600; margin-bottom: 10px; color: var(--text2); }
.ct-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.ct-big { font-size: 36px; font-weight: 700; text-align: center; margin: 8px 0; font-variant-numeric: tabular-nums; }

button { font-family: inherit; }
.ct-section button {
  background: var(--accent); border: none; border-radius: 4px;
  color: #fff; cursor: pointer; font-size: 12px; padding: 5px 12px;
  transition: background .15s;
}
.ct-section button:hover { background: var(--accent2); }

.dice-btn { background: var(--surface2) !important; color: var(--text) !important; font-weight: 700; }
.dice-btn:hover { background: var(--border) !important; }

#rg-names {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 4px; color: var(--text); font-family: inherit; font-size: 12px;
  padding: 6px; resize: vertical;
}
#rg-output { font-size: 12px; margin-top: 8px; }
.rg-group { background: var(--surface2); border-radius: 4px; margin-bottom: 6px; padding: 6px 8px; }
.rg-group h4 { color: var(--accent); font-size: 11px; margin-bottom: 4px; }

/* Lessons panel */
#lessons-list { padding: 8px; }
.lesson-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 6px;
  padding: 10px 12px;
  transition: background .12s, border-color .12s;
}
.lesson-item:hover { background: var(--surface2); border-color: var(--accent); }
.lesson-item.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.lesson-item h4 { font-size: 12px; margin-bottom: 2px; }
.lesson-item p { font-size: 11px; opacity: .7; }
.lesson-lab-badge {
  display: inline-block; font-size: 10px; background: var(--surface2);
  border-radius: 10px; padding: 1px 6px; margin-bottom: 4px; color: var(--text2);
}
.lesson-item.active .lesson-lab-badge { background: rgba(255,255,255,.2); color: rgba(255,255,255,.8); }

/* Lesson overlay */
#lesson-overlay {
  position: fixed;
  bottom: calc(var(--timeline-h) + var(--footer-h) + 10px);
  left: calc(var(--palette-w) + 10px);
  z-index: 140;
}
#lesson-overlay.hidden { display: none; }

#lesson-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 380px;
  padding: 14px;
  width: 380px;
}

#lesson-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
#lesson-step-num {
  background: var(--accent);
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  height: 22px;
  line-height: 22px;
  min-width: 22px;
  text-align: center;
}
#lesson-title { flex: 1; font-size: 14px; font-weight: 600; }
#lesson-close {
  background: transparent; border: none; color: var(--text2);
  cursor: pointer; font-size: 16px; padding: 0 2px;
}

#lesson-text { font-size: 13px; line-height: 1.5; color: var(--text2); margin-bottom: 10px; }
#lesson-success { color: var(--success); font-size: 12px; font-weight: 600; margin-bottom: 8px; }
#lesson-hint-text {
  background: var(--surface2); border-radius: 4px; font-size: 12px;
  margin-top: 8px; padding: 8px; color: var(--text2);
}

#lesson-footer {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
#lesson-footer button {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 4px; color: var(--text); cursor: pointer;
  font-size: 12px; padding: 4px 10px;
  transition: background .12s;
}
#lesson-footer button:hover { background: var(--border); }
#lesson-next { background: var(--accent) !important; border-color: var(--accent) !important; color: #fff !important; }
#lesson-next:hover { background: var(--accent2) !important; }

/* Settings */
.toggle-row {
  display: flex; align-items: center; gap: 10px;
  cursor: pointer; padding: 6px 0; font-size: 13px;
}
.toggle-row input { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }

/* Share */
#share-url-box {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 4px; color: var(--text); font-family: monospace;
  font-size: 11px; padding: 6px; resize: none;
}
#saved-scenes { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.save-item {
  align-items: center; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 4px; cursor: pointer; display: flex; gap: 8px; padding: 8px;
}
.save-item:hover { border-color: var(--accent); }
.save-thumb { width: 48px; height: 36px; border-radius: 3px; object-fit: cover; background: var(--border); }
.save-info { flex: 1; }
.save-name { font-size: 12px; font-weight: 600; }
.save-date { font-size: 10px; color: var(--text2); }
.save-del {
  background: transparent; border: none; color: var(--text2);
  cursor: pointer; font-size: 14px; padding: 0 4px;
}
.save-del:hover { color: var(--danger); }

#export-status { font-size: 11px; color: var(--text2); margin-top: 6px; }

/* ══════════════════════ INPUTS / SHARED ══════════════════════ */
input[type=range] { cursor: pointer; }

input[type=number] {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 4px; color: var(--text); font-size: 12px;
  padding: 3px 6px; text-align: center;
}

/* ══════════════════════ RESPONSIVE ══════════════════════ */
@media (max-width: 768px) {
  :root { --panel-w: 0px; }
  #right-panel { display: none; }
  #lab-tabs .tab { padding: 4px 7px; font-size: 11px; }
  .logo { font-size: 13px; }
  #header-actions button { font-size: 11px; padding: 4px 6px; }
  #lesson-card { width: calc(100vw - 80px); max-width: none; }
}

@media (max-width: 480px) {
  #playback-controls .ts-wrap { display: none; }
  #lab-tabs { gap: 1px; }
  .tab { padding: 4px 5px; }
}

/* ══════════════════════ PRINT ══════════════════════ */
@media print {
  #app-header, #tool-palette, #right-panel,
  #timeline-bar, #app-footer, .side-panel,
  #lesson-overlay, #modal-backdrop { display: none !important; }
  #app-main { top: 0; bottom: 0; grid-template-columns: 0 1fr 0; }
  #canvas-area { position: static; }
  .worksheet-page { display: block !important; }
}

/* ══════════════════════ GRID OVERLAY ══════════════════════ */
.grid-canvas {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none; z-index: 5;
  opacity: .15;
}
