/* Science Club Academy - Cambridge IGCSE Virtual Labs & Paper 6 Simulator */
:root {
  --navy: #16325c;
  --navy-dark: #0f2342;
  --orange: #e8832a;
  --orange-hover: #d1701b;
  --bg: #f4f7fb;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --physics: #2563eb;
  --chemistry: #0891b2;
  --biology: #16a34a;
}
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; }
body { background: var(--bg); color: var(--text); line-height: 1.5; padding-bottom: 85px; }

/* Header */
header {
  background: var(--card);
  border-bottom: 3px solid var(--orange);
  box-shadow: 0 2px 12px rgba(22,50,92,0.08);
  position: sticky; top: 0; z-index: 100;
}
.header-inner {
  max-width: 1400px; margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 15px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--navy); }
.brand-logo { width: 62px; height: 62px; object-fit: contain; border-radius: 8px; }
.brand-title h1 { font-size: 1.25rem; font-weight: 800; color: var(--navy); letter-spacing: 0.3px; }
.brand-title p { font-size: 0.88rem; color: var(--orange); font-weight: 700; }
.brand-title span { font-size: 0.76rem; color: var(--muted); display: block; }
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 15px;
  border-radius: 8px; font-weight: 600; font-size: 0.88rem; cursor: pointer;
  text-decoration: none; border: 1px solid transparent; transition: 0.2s;
}
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-dark); }
.btn-orange { background: var(--orange); color: #fff; }
.btn-orange:hover { background: var(--orange-hover); }
.btn-outline { background: #fff; color: var(--navy); border-color: var(--navy); }
.btn-outline:hover { background: #f1f5f9; }
.btn-success { background: var(--success); color: #fff; }

/* Layout */
.container { max-width: 1400px; margin: 20px auto; padding: 0 20px; }

/* Hero & Filters */
.hero {
  background: linear-gradient(135deg, var(--navy) 0%, #1e457a 100%);
  color: #fff; border-radius: 14px; padding: 24px; margin-bottom: 22px;
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 20px;
}
.hero-text h2 { font-size: 1.6rem; margin-bottom: 6px; }
.hero-text p { color: #cbd5e1; font-size: 0.95rem; max-width: 720px; }
.stats-bar { display: flex; gap: 14px; flex-wrap: wrap; }
.stat-box {
  background: rgba(255,255,255,0.12); padding: 10px 16px; border-radius: 10px;
  text-align: center; min-width: 110px; backdrop-filter: blur(4px);
}
.stat-box strong { display: block; font-size: 1.35rem; color: #ffb067; }
.stat-box span { font-size: 0.78rem; color: #e2e8f0; }

/* Subject Tabs */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tab-btn {
  padding: 9px 18px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); font-weight: 700; cursor: pointer; transition: 0.2s;
}
.tab-btn.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.search-box {
  padding: 9px 14px; border-radius: 8px; border: 1px solid var(--border);
  min-width: 260px; font-size: 0.9rem;
}

/* Grid of 30 Labs */
/* Phase 5: a card may shrink below 310px when the screen is narrower than that (320px phones), so the page never scrolls sideways */
.lab-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(310px, 100%), 1fr)); gap: 18px; }
.lab-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; display: flex; flex-direction: column; justify-content: space-between;
  transition: transform 0.2s, box-shadow 0.2s; position: relative; overflow: hidden;
}
.lab-card:hover { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(0,0,0,0.07); }
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 6px; font-size: 0.75rem;
  font-weight: 700; color: #fff; margin-bottom: 10px;
}
.badge-physics { background: var(--physics); }
.badge-chemistry { background: var(--chemistry); }
.badge-biology { background: var(--biology); }
.lab-card h3 { font-size: 1.05rem; color: var(--navy); margin-bottom: 6px; }
.lab-card p { font-size: 0.85rem; color: var(--muted); margin-bottom: 14px; }
.lab-meta { font-size: 0.78rem; color: var(--muted); border-top: 1px solid var(--border); padding-top: 10px; display: flex; justify-content: space-between; align-items: center; }
.done-pill { background: #dcfce7; color: #166534; font-weight: 700; padding: 2px 8px; border-radius: 12px; font-size: 0.72rem; }

/* Active Lab Workspace */
#labView { display: none; }
.lab-header-bar {
  background: var(--card); padding: 14px 20px; border-radius: 12px; border: 1px solid var(--border);
  margin-bottom: 18px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px;
}
.workspace-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 18px; }
/* Grid columns must be allowed to shrink below the canvas's 640px drawing width (prevents sideways scrolling on phones) */
.workspace-grid > * { min-width: 0; }
@media (max-width: 980px) { .workspace-grid { grid-template-columns: 1fr; } }
.panel {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; margin-bottom: 18px;
}
.panel h3 {
  font-size: 1.05rem; color: var(--navy); margin-bottom: 12px;
  padding-bottom: 8px; border-bottom: 2px solid #f1f5f9; display: flex; justify-content: space-between; align-items: center;
}

/* Interactive Canvas & Controls */
.sim-canvas-wrap {
  background: #0f172a; border-radius: 10px; overflow: hidden; position: relative;
  margin-bottom: 14px;
}
/* Keep the drawing's own 640:300 proportions at every screen width (no squashing) */
canvas#simCanvas { width: 100%; height: auto; aspect-ratio: 640 / 300; display: block; }
.controls-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
@media (max-width: 600px) { .controls-grid { grid-template-columns: 1fr; } }
.control-item { background: #f8fafc; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); }
.control-item label { display: flex; justify-content: space-between; font-size: 0.84rem; font-weight: 700; color: var(--navy); margin-bottom: 5px; }
.control-item input[type=range] { width: 100%; accent-color: var(--orange); cursor: pointer; }

/* ===== Phase 6 final fixes ===== */
/* QA-08: the shown value never wraps; app.js reserves the width of its widest value, so the name beside it keeps its lines. */
.control-item label { gap: 8px; align-items: flex-start; }
.control-item label > span:first-child { min-width: 0; }
#var1Val, #var2Val { flex: none; white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
/* QA-02: a 44 px tall touch area, a 28 px orange thumb with a white ring, an 8 px track whose orange part ends
   at the thumb centre (--fill is set by app.js). Values and the value-to-position mapping are the browser's own. */
.control-item input[type=range] {
  -webkit-appearance: none; appearance: none; display: block; height: 44px; margin: 0; padding: 0;
  background: transparent; touch-action: auto;
}
.control-item input[type=range]::-webkit-slider-runnable-track {
  height: 8px; border-radius: 4px; border: none;
  background: linear-gradient(to right, var(--orange) 0, var(--orange) var(--fill, 50%), #cbd5e1 var(--fill, 50%), #cbd5e1 100%);
}
.control-item input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; box-sizing: border-box; width: 28px; height: 28px; margin-top: -10px; border-radius: 50%;
  background: var(--orange); border: 3px solid #fff; box-shadow: 0 0 0 1px #c2410c, 0 1px 4px rgba(15, 23, 42, 0.35);
}
.control-item input[type=range]::-moz-range-track { height: 8px; border-radius: 4px; background: #cbd5e1; border: none; }
.control-item input[type=range]::-moz-range-progress { height: 8px; border-radius: 4px; background: var(--orange); }
.control-item input[type=range]::-moz-range-thumb {
  box-sizing: border-box; width: 28px; height: 28px; border-radius: 50%;
  background: var(--orange); border: 3px solid #fff; box-shadow: 0 0 0 1px #c2410c, 0 1px 4px rgba(15, 23, 42, 0.35);
}
.control-item input[type=range]:focus { outline: none; }
.control-item input[type=range]:focus-visible { outline: 3px solid var(--navy); outline-offset: 2px; border-radius: 8px; }
/* QA-07: touch targets of at least 44 px for the lab tabs, the lab header buttons and Record / Clear. */
.sub-tab, .lab-header-bar .btn, .live-readout .btn, .clear-confirm .btn { min-height: 44px; }
/* QA-04: in-page confirmation before "Clear Table" deletes readings. */
.btn-danger { background: #b91c1c; color: #fff; }
.btn-danger:hover { background: #991b1b; }
.clear-confirm { background: #fef2f2; border: 2px solid #dc2626; border-radius: 8px; padding: 10px 14px; margin: -4px 0 12px; color: #7f1d1d; font-weight: 600; font-size: 0.88rem; }
.clear-confirm[hidden] { display: none; }
.clear-confirm p { margin-bottom: 8px; }
.clear-confirm-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.live-readout {
  background: #fff7ed; border: 1px solid #fed7aa; border-radius: 8px; padding: 10px 14px;
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; font-weight: 700; color: #9a3412;
}

/* Data Table & Graph */
table.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-bottom: 12px; }
table.data-table th, table.data-table td { border: 1px solid var(--border); padding: 7px 9px; text-align: center; }
table.data-table th { background: #f1f5f9; color: var(--navy); }
.graph-wrap { background: #ffffff; border: 1px solid var(--border); border-radius: 8px; padding: 6px; }
/* Keep the graph's own 520:230 proportions at every screen width (no squashing) */
canvas#graphCanvas { width: 100%; height: auto; aspect-ratio: 520 / 230; display: block; }

/* Sub-tabs inside Lab */
.sub-tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.sub-tab {
  padding: 6px 12px; border-radius: 6px; font-size: 0.82rem; font-weight: 700;
  background: #f1f5f9; color: var(--muted); border: none; cursor: pointer;
}
.sub-tab.active { background: var(--orange); color: #fff; }
.sub-content { display: none; font-size: 0.9rem; }
.sub-content.active { display: block; }
.list-styled { padding-left: 18px; }
.list-styled li { margin-bottom: 6px; }
.formula-box { background: #f8fafc; border-left: 4px solid var(--navy); padding: 10px 12px; margin: 10px 0; font-family: monospace; font-size: 0.92rem; }

/* Quiz & AI Examiner */
.quiz-item { margin-bottom: 14px; padding: 12px; background: #f8fafc; border-radius: 8px; border: 1px solid var(--border); }
.quiz-item p { font-weight: 600; margin-bottom: 8px; }
.quiz-item label { display: block; font-size: 0.86rem; margin-bottom: 4px; cursor: pointer; }
textarea.p6-input { width: 100%; min-height: 90px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.88rem; margin: 8px 0; }
.feedback-box { padding: 12px; border-radius: 8px; background: #eff6ff; border: 1px solid #bfdbfe; color: #1e3a8a; font-size: 0.86rem; margin-top: 8px; display: none; }

/* Floating WhatsApp Button (Phase 5)
   A compact round button at every screen size (the full text stays in the tooltip, and is shown
   when a mouse user hovers it or a keyboard user focuses it on wide screens).
   - It sits below the report window (z-index 400 < 500), so it never covers the QA/report window.
   - It hides itself while it would cover a control, the apparatus, the graph, the table or the
     analysis box, and while the on-screen keyboard is open (see app.js, "Phase 5: help button").
   - The page keeps room at the bottom (and scrolling keeps a margin) so nothing ends up under it. */
.whatsapp-float {
  position: fixed; z-index: 400;
  right: calc(14px + env(safe-area-inset-right, 0px)); bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  width: 52px; height: 52px; padding: 0; border-radius: 26px; overflow: hidden; white-space: nowrap;
  background: #25D366; color: #fff; text-decoration: none; font-weight: 700; font-size: 0.92rem;
  display: flex; align-items: center; justify-content: center; gap: 0;
  box-shadow: 0 6px 20px rgba(37, 211, 102, 0.4);
  transition: opacity 0.15s, box-shadow 0.2s;
}
.whatsapp-float svg { width: 28px; height: 28px; fill: currentColor; flex: none; }
.whatsapp-float span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); }
.whatsapp-float:hover { box-shadow: 0 8px 25px rgba(37, 211, 102, 0.55); }
.whatsapp-float:focus-visible { outline: 3px solid var(--navy); outline-offset: 3px; }
/* Hidden by fading only, so a keyboard user can still reach it with Tab: when it has keyboard focus it shows again. */
.whatsapp-float.wa-hidden:not(:focus-visible) { opacity: 0; pointer-events: none; }
@media (hover: hover) and (min-width: 1200px) {
  .whatsapp-float:hover, .whatsapp-float:focus-visible { width: auto; padding: 0 18px 0 12px; gap: 10px; }
  .whatsapp-float:hover svg, .whatsapp-float:focus-visible svg { width: 22px; height: 22px; }
  .whatsapp-float:hover span, .whatsapp-float:focus-visible span { position: static; width: auto; height: auto; clip: auto; clip-path: none; }
}
/* Room at the end of the page and a scrolling margin, so content can always be scrolled clear of the button.
   scroll-padding-top follows the pinned header (set from app.js; 0 when the header is not pinned). */
body { padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
html { scroll-padding-top: var(--pinned-header-h, 0px); scroll-padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
/* Phones and small tablets: the header scrolls away instead of staying pinned (it is 180–200px tall on phones). */
@media (max-width: 768px) {
  header { position: static; }
}

/* Modal Report */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,0.65); z-index: 500;
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--card); max-width: 820px; width: 100%; border-radius: 14px;
  padding: 24px; max-height: 85vh; overflow-y: auto;
}

/* Phase 3: warning text for saved readings that are kept but not used.
   On narrow screens the data table can be slightly wider than its box (it scrolls sideways inside it),
   so the note is limited to the visible width and stays in view if the table is scrolled. */
.reading-note { position: sticky; left: 8px; max-width: min(100%, calc(100vw - 96px)); white-space: normal; }

/* Phase 4: graph analysis notes, readings with a different control value, taller graph on phones */
.analysis-notes { margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--border); color: var(--muted); font-size: 0.8rem; }
tr.reading-other-control td { color: #94a3b8; background: #f8fafc; }
@media (max-width: 600px) { canvas#graphCanvas { aspect-ratio: 4 / 3; } }

/* Phase 4: data-type labels (simulated reading / calculated / model value / reference value) */
.col-tag { display: block; font-size: 0.68rem; font-weight: 600; color: var(--muted); margin-top: 2px; }
.data-tag { display: inline-block; font-size: 0.7rem; font-weight: 700; padding: 0 6px; border-radius: 10px; border: 1px solid; white-space: nowrap; }
.tag-sim { color: #9a3412; border-color: #fdba74; background: #fff7ed; }
.tag-calc { color: #1e40af; border-color: #93c5fd; background: #eff6ff; }
.tag-model { color: #6b21a8; border-color: #d8b4fe; background: #faf5ff; }
.tag-ref { color: #166534; border-color: #86efac; background: #f0fdf4; }

/* ===== Phase 5: responsive layout ===== */
/* Short screens (phones turned sideways): the header scrolls away instead of staying pinned,
   so the experiment has the whole screen height. */
@media (max-height: 500px) {
  header { position: static; }
}
/* Short screens: the apparatus drawing and the graph are limited to the visible height,
   so each can be seen whole (they keep their proportions and are centred). */
@media (max-height: 500px) and (min-width: 560px) {
  canvas#simCanvas { width: min(100%, calc((100vh - 56px) * 640 / 300)); width: min(100%, calc((100svh - 56px) * 640 / 300)); margin: 0 auto; }
  canvas#graphCanvas { width: min(100%, calc((100vh - 56px) * 520 / 230)); width: min(100%, calc((100svh - 56px) * 520 / 230)); margin: 0 auto; }
}
@media (max-height: 500px) and (min-width: 560px) and (max-width: 600px) {
  canvas#graphCanvas { width: min(100%, calc((100vh - 56px) * 4 / 3)); width: min(100%, calc((100svh - 56px) * 4 / 3)); }
}
/* Small phones: a more compact header (smaller logo, the four header buttons in two rows of two). */
@media (max-width: 480px) {
  .header-inner { padding: 8px 12px; gap: 8px; }
  .brand { gap: 10px; }
  .brand-logo { width: 44px; height: 44px; }
  .brand-title h1 { font-size: 1.05rem; }
  .brand-title p { font-size: 0.8rem; }
  .brand-title span { font-size: 0.68rem; line-height: 1.35; }
  .header-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; width: 100%; }
  .header-actions .btn { justify-content: center; text-align: center; padding: 6px 8px; font-size: 0.78rem; min-height: 44px; }
}
@media (max-width: 360px) {
  .container { padding: 0 12px; }
}

/* ===== Phase 4 batch 4: reference value of an unknown sample, shown after the student's own result ===== */
.reference-reveal { margin: 6px 0 2px; padding: 8px 10px; border: 1px dashed #16a34a; border-left: 4px solid #16a34a; border-radius: 8px; background: #f0fdf4; color: #14532d; }
.reference-reveal .sample-reference { font-weight: 700; }

/* ===== Phase 4 batch 4.3: data table on phones ===== */
/* A fade at the right edge and a short hint appear only when the table is wider than its box
   (set by updateTableOverflow in app.js). The fade disappears when the last column is reached. */
.table-scroll-outer { position: relative; }
.table-scroll-outer::after {
  content: ""; position: absolute; top: 0; right: 0; bottom: 12px; width: 28px; pointer-events: none;
  background: linear-gradient(to right, rgba(255,255,255,0), rgba(255,255,255,0.95));
  opacity: 0; transition: opacity 0.2s;
}
.table-scroll-outer.has-overflow::after { opacity: 1; }
.table-scroll-outer.has-overflow.at-end::after { opacity: 0; }
.table-swipe-hint { margin: 0 0 6px; font-size: 0.78rem; font-weight: 600; color: var(--navy); text-align: right; }
.table-swipe-hint[hidden] { display: none; }
/* The "#" column stays in view while the other columns scroll (main data table only; full-width note rows are not affected). */
#dataTableScroll table.data-table th:first-child,
#dataTableScroll table.data-table td:first-child:not([colspan]) {
  position: sticky; left: 0; z-index: 1; background: var(--card); box-shadow: inset -1px 0 0 var(--border);
}
#dataTableScroll table.data-table th:first-child { background: #f1f5f9; }
#dataTableScroll table.data-table tr.reading-not-used td:first-child { background: #fff7ed; }
#dataTableScroll table.data-table tr.reading-other-control td:first-child { background: #f8fafc; }
/* Short column tags on screens up to 430 px; the full tags stay on larger screens. */
.col-tag .tag-short { display: none; }
.table-tag-key { display: none; }
@media (max-width: 430px) {
  .col-tag .tag-full { display: none; }
  .col-tag .tag-short { display: inline; }
  .table-tag-key { display: block; margin: 0 0 4px; font-size: 0.72rem; line-height: 1.4; color: var(--muted); }
  #dataTableScroll table.data-table th, #dataTableScroll table.data-table td { padding: 6px 6px; }
}
