/* ==========================================================================
   Chemistry Web Apps - shared stylesheet
   Themes are chosen with <html data-theme="...">  (see theme.js).
   Available: lab-night (default), teal-lagoon, plasma, classroom-light
   ========================================================================== */

/* ---------- Theme tokens ---------- */
:root,
:root[data-theme="lab-night"] {
    --bg: #0b1020;
    --panel: #121933;
    --surface: #0f1733;
    --canvas: #0a1024;
    --ink: #e7ecff;
    --muted: #a9b3d9;
    --accent: #5bd1ff;
    --accent2: #95a4ff;
    --good: #39d98a;
    --bad: #ff6b6b;
    --warn: #ffd166;
    --border: #2d3b6e;
    --panel-border: #23305a;
    --header-bg: linear-gradient(90deg, #15204a, #0f1a3b);
    --header-border: #243059;
    --header-ink: #e7ecff;
    --title-grad: linear-gradient(135deg, #5bd1ff, #95a4ff);
    --shadow: 0 8px 32px rgba(0, 0, 0, .35);
    --btn-ink: #e7ecff;
    --c-primary: #153b6b;
    --c-primary-bd: #2056a6;
    --c-good: #0f3b2d;
    --c-good-bd: #1b6c55;
    --c-warn: #4a370f;
    --c-warn-bd: #8a6a2b;
    --c-bad: #4a1020;
    --c-bad-bd: #8a2b46;
    --seg-add: #1b5f8f;
    --seg-remove: #7a5a10;
    --ok-bg: #0f3b2d;
    --ok-ink: #b8ffd9;
    --err-bg: #4a1020;
    --err-ink: #ffd0d0;
    --dialog-border: #3d4f93;
    --backdrop: rgba(5, 8, 20, .8);
    --pos: #ff9f7a;
    --neg: #7aa8ff;
    --track: #334155;
}

:root[data-theme="teal-lagoon"] {
    --bg: #071a1f;
    --panel: #0d2a31;
    --surface: #0a2228;
    --canvas: #08171c;
    --ink: #e6fbf7;
    --muted: #9cc9c4;
    --accent: #2dd4bf;
    --accent2: #7dd3fc;
    --good: #4ade80;
    --bad: #fb7185;
    --warn: #fcd34d;
    --border: #1f5560;
    --panel-border: #17424b;
    --header-bg: linear-gradient(90deg, #0b3a42, #0a2a33);
    --header-border: #17525c;
    --header-ink: #e6fbf7;
    --title-grad: linear-gradient(135deg, #2dd4bf, #7dd3fc);
    --btn-ink: #e6fbf7;
    --c-primary: #0e5160;
    --c-primary-bd: #1f8aa0;
    --c-good: #0f4a33;
    --c-good-bd: #1f8a5e;
    --seg-add: #0e6a73;
    --ok-bg: #0f4a33;
    --dialog-border: #2a7480;
    --backdrop: rgba(2, 12, 15, .8);
}

:root[data-theme="plasma"] {
    --bg: #130b24;
    --panel: #1d1236;
    --surface: #170e2d;
    --canvas: #110a21;
    --ink: #f3ebff;
    --muted: #bfa9e6;
    --accent: #e879f9;
    --accent2: #a78bfa;
    --good: #5eead4;
    --bad: #ff7a90;
    --warn: #fbbf24;
    --border: #4a2f85;
    --panel-border: #3a2468;
    --header-bg: linear-gradient(90deg, #3b1670, #241046);
    --header-border: #4a2f85;
    --header-ink: #f3ebff;
    --title-grad: linear-gradient(135deg, #e879f9, #a78bfa);
    --btn-ink: #f3ebff;
    --c-primary: #4c1d95;
    --c-primary-bd: #8b5cf6;
    --c-good: #0f4a45;
    --c-good-bd: #1f8a80;
    --seg-add: #7e22ce;
    --ok-bg: #0f4a45;
    --dialog-border: #6b46c1;
    --backdrop: rgba(10, 4, 20, .82);
}

/* Light theme: panels are white, but boards (canvas) stay dark so drawings remain readable */
:root[data-theme="classroom-light"] {
    --bg: #eef4f8;
    --panel: #ffffff;
    --surface: #f3f8fb;
    --canvas: #0a1024;
    --ink: #17324d;
    --muted: #55708a;
    --accent: #0a84c6;
    --accent2: #5b6bd6;
    --good: #12915b;
    --bad: #d6364f;
    --warn: #c47f0a;
    --border: #b8cddd;
    --panel-border: #d0dfea;
    --header-bg: linear-gradient(90deg, #0a84c6, #12a3a8);
    --header-border: #0a6fa8;
    --header-ink: #ffffff;
    --title-grad: none;
    --shadow: 0 6px 20px rgba(23, 50, 77, .12);
    --btn-ink: #ffffff;
    --c-primary: #0a84c6;
    --c-primary-bd: #0a6fa8;
    --c-good: #12915b;
    --c-good-bd: #0d7448;
    --c-warn: #c47f0a;
    --c-warn-bd: #9c6407;
    --c-bad: #d6364f;
    --c-bad-bd: #ac2840;
    --seg-add: #0a84c6;
    --seg-remove: #c47f0a;
    --ok-bg: #dff5ea;
    --ok-ink: #0b5a39;
    --err-bg: #fde4e8;
    --err-ink: #8c1c30;
    --dialog-border: #8fb3cc;
    --backdrop: rgba(23, 50, 77, .55);
    --pos: #d9521f;
    --neg: #2f5fd0;
    --track: #c9d8e4;
}

/* Fixed data colours (not themed) */
:root {
    --red: #ef4444;
    --blue: #3b82f6;
    --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Arial, sans-serif;
}

/* ---------- Base ---------- */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--ink);
}

a {
    color: var(--accent);
}

header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px 20px;
    padding: 14px 20px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
    color: var(--header-ink);
}

header h1 {
    margin: 0;
    font-size: 20px;
}

header p {
    flex: 1;
    margin: 0;
    color: var(--header-ink);
    opacity: .8;
    font-size: 13px;
}

.header-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.header-tools select,
.header-tools a {
    width: auto;
    padding: .35em .8em;
    font-size: .9rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink);
    text-decoration: none;
    cursor: pointer;
}

.header-tools a:hover {
    filter: brightness(1.15);
}

a.btn {
    display: inline-block;
    border: 1px solid var(--c-primary-bd);
    border-radius: 10px;
    text-align: center;
    color: var(--btn-ink);
}

.screen-app a.btn {
    border-width: 2px;
    border-radius: .6rem;
    font-weight: 600;
}

.wrap {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 16px;
    padding: 16px;
}

@media (max-width: 900px) {
    .wrap {
        grid-template-columns: 1fr;
    }
}

.panel {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 14px;
}

.panel h2 {
    margin: 0 0 8px;
    font-size: 16px;
}

label {
    display: block;
    margin: 8px 0 4px;
    color: var(--muted);
    font-size: 12px;
}

select,
button,
input[type="number"],
input[type="text"],
.mode-toggle {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-size: 14px;
}

.row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.row>* {
    flex: 1;
}

.btn {
    cursor: pointer;
}

.btn.primary {
    background: var(--c-primary);
    border-color: var(--c-primary-bd);
    color: var(--btn-ink);
}

.btn.good {
    background: var(--c-good);
    border-color: var(--c-good-bd);
    color: var(--btn-ink);
}

.btn.warn {
    background: var(--c-warn);
    border-color: var(--c-warn-bd);
    color: var(--btn-ink);
}

.btn.bad {
    background: var(--c-bad);
    border-color: var(--c-bad-bd);
    color: var(--btn-ink);
}

.summary {
    margin-top: 10px;
    padding: 10px;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 13px;
}

.summary .ok {
    color: var(--good);
}

.summary .err {
    color: var(--bad);
}

.summary .note {
    color: var(--muted);
}

canvas {
    width: 100%;
    max-width: 840px;
    aspect-ratio: 4/3;
    background: var(--canvas);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
}

.legend {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 12px;
    margin-top: 8px;
}

.legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--ink);
}

.cross {
    position: relative;
    width: 10px;
    height: 10px;
}

.cross::before,
.cross::after {
    content: "";
    position: absolute;
    left: 4px;
    top: 0;
    width: 2px;
    height: 10px;
    background: var(--ink);
}

.cross::before {
    transform: rotate(45deg);
}

.cross::after {
    transform: rotate(-45deg);
}

/* ---------- Shared pop-up dialog (native <dialog>) ---------- */
dialog {
    background: var(--panel);
    color: var(--ink);
    border: 2px solid var(--dialog-border);
    border-radius: 1rem;
    padding: 1.2rem 1.6rem;
    width: min(42rem, 90vw);
    font-size: 1.15rem;
}

dialog::backdrop {
    background: var(--backdrop);
}

dialog h2 {
    margin: 0 0 .6rem;
    font-size: 1.6rem;
}

dialog h3 {
    margin: 1rem 0 .4rem;
    font-size: 1.2rem;
    color: var(--muted);
}

/* ---------- Single-screen "projector" layout (body.screen-app) ----------
   Used by the canvas tools: everything scales with the window. */
html:has(body.screen-app) {
    font-size: clamp(12px, min(2vh, 1.5vw), 24px);
}

body.screen-app {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-size: 1rem;
}

.screen-app header {
    flex-wrap: nowrap;
    gap: 1.2rem;
    padding: .5rem 1.2rem;
}

.screen-app header h1 {
    font-size: 1.7rem;
    white-space: nowrap;
}

.screen-app header p {
    font-size: 1.1rem;
    opacity: 1;
}

.screen-app header .btn,
.screen-app .header-tools select,
.screen-app .header-tools a {
    width: auto;
    padding: .4rem 1.1rem;
    font-size: 1.1rem;
    white-space: nowrap;
}

.screen-app .wrap {
    flex: 1;
    min-height: 0;
    gap: 1rem;
    padding: 1rem;
}

.screen-app .panel {
    padding: 1rem;
    border-radius: .8rem;
    min-height: 0;
    overflow: auto;
}

.screen-app label {
    font-size: .95rem;
    margin: .7rem 0 .3rem;
    color: var(--ink);
    font-weight: 600;
}

.screen-app label:first-child {
    margin-top: 0;
}

.screen-app select,
.screen-app button,
.screen-app input[type="number"],
.screen-app input[type="text"] {
    font-size: 1.05rem;
    padding: .6rem .8rem;
    border-width: 2px;
    border-radius: .6rem;
}

.screen-app button {
    font-weight: 600;
    cursor: pointer;
}

.screen-app button:hover {
    filter: brightness(1.25);
}

.screen-app button:focus-visible,
.screen-app select:focus-visible,
.screen-app input:focus-visible,
.header-tools a:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.screen-app .row {
    gap: .6rem;
    margin-top: .6rem;
}

.seg {
    display: flex;
}

.seg button {
    border-radius: 0;
}

.seg button:first-child {
    border-radius: .6rem 0 0 .6rem;
}

.seg button:last-child {
    border-radius: 0 .6rem .6rem 0;
    margin-left: -2px;
}

.seg button.active[data-mode="add"] {
    background: var(--seg-add);
    border-color: var(--accent);
    color: var(--btn-ink);
}

.seg button.active[data-mode="remove"] {
    background: var(--seg-remove);
    border-color: var(--warn);
    color: var(--btn-ink);
}

.board-panel {
    padding: .5rem;
    overflow: hidden;
}

.board-wrap {
    height: 100%;
    container-type: size;
    display: grid;
    place-items: center;
}

.screen-app canvas {
    display: block;
    max-width: none;
}

.side {
    display: flex;
    flex-direction: column;
    gap: .8rem;
    min-height: 0;
}

.screen-app #task,
.screen-app .summary,
.screen-app #feedback {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: .8rem;
    margin: 0;
}

.screen-app #task {
    padding: .7rem 1rem;
}

.task-main {
    font-size: 1.2rem;
    font-weight: 600;
}

.task-main strong {
    display: block;
    font-size: 2.6rem;
    line-height: 1.1;
    color: var(--accent);
}

.task-sub {
    font-size: 1.05rem;
    color: var(--muted);
    margin-top: .3rem;
}

.screen-app .summary {
    padding: .7rem;
    font-size: 1.05rem;
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .5rem;
    text-align: center;
}

.stat span {
    display: block;
    font-size: .9rem;
    color: var(--muted);
}

.stat b {
    display: block;
    font-size: 2.2rem;
    line-height: 1.15;
}

.stat b.done {
    color: var(--good);
}

.stat b.pos {
    color: var(--pos);
}

.stat b.neg {
    color: var(--neg);
}

.screen-app #feedback {
    flex: 1;
    min-height: 6rem;
    overflow: auto;
    padding: .8rem 1rem;
    font-size: 1.3rem;
    line-height: 1.35;
}

#feedback.info {
    color: var(--ink);
}

#feedback.ok {
    background: var(--ok-bg);
    border-color: var(--good);
    color: var(--ok-ink);
}

#feedback.err {
    background: var(--err-bg);
    border-color: var(--bad);
    color: var(--err-ink);
}

.steps {
    margin: 0;
    padding-left: 1.6rem;
    line-height: 1.5;
}

.legend-list {
    list-style: none;
    margin: 0;
    padding: 0;
    line-height: 1.8;
}

.legend-list li {
    display: flex;
    align-items: center;
    gap: .7rem;
}

#closeHelpBtn {
    margin-top: 1.1rem;
    width: auto;
    padding: .5rem 1.6rem;
}

/* ---------- Page title gradient (non-canvas pages) ---------- */
.page-title {
    background: var(--title-grad);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

:root[data-theme="classroom-light"] .page-title {
    background: none;
    -webkit-text-fill-color: currentColor;
}
