:root {
    --bg: #f5f4ef;
    --surface: #ffffff;
    --surface-2: #efede6;
    --text: #1c1c1e;
    --muted: #6d6c68;
    --line: #d6d3ca;
    --line-strong: #2a2a2c;
    --accent: #2f5bd3;
    --accent-soft: #e2e9fb;
    --user: #2f5bd3;
    --deduced: #6b4fc9;
    --wrong: #c42b2b;
    --wrong-soft: #fbe3e3;
    --ok: #1d7a4c;
    --ok-soft: #dcf2e5;
    --ref: #f2c230;
    --ref-soft: #fff3c9;
    --peer: #f1efe8;
    --same: #dfe6f8;
    --word: #e9e2fb;
    --lvl-1: #1d7a4c;
    --lvl-2: #2f5bd3;
    --lvl-3: #c56a12;
    --lvl-4: #c42b2b;
    --radius: 10px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #141416;
        --surface: #1d1d20;
        --surface-2: #26262a;
        --text: #ececec;
        --muted: #9a9993;
        --line: #3a3a3f;
        --line-strong: #c9c8c2;
        --accent: #7c9cff;
        --accent-soft: #232c47;
        --user: #8eabff;
        --deduced: #b9a3ff;
        --wrong: #ff7a7a;
        --wrong-soft: #3d2023;
        --ok: #5fd39a;
        --ok-soft: #1b3428;
        --ref: #e3b42a;
        --ref-soft: #3a3218;
        --peer: #232327;
        --same: #26304a;
        --word: #2e2645;
        --lvl-1: #5fd39a;
        --lvl-2: #7c9cff;
        --lvl-3: #f0a35a;
        --lvl-4: #ff7a7a;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; color: inherit; }

button {
    border: 1px solid var(--line);
    background: var(--surface);
    border-radius: 8px;
    padding: 7px 12px;
    cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--line-strong); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
button.accent { border-color: var(--accent); color: var(--accent); }
button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }

kbd {
    font: 12px ui-monospace, monospace;
    border: 1px solid var(--line);
    border-bottom-width: 2px;
    border-radius: 4px;
    padding: 0 4px;
    margin-right: 2px;
    background: var(--surface);
}

/* ---------- Kopfzeile ---------- */

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    justify-content: space-between;
    gap: 12px 24px;
    padding: 16px max(16px, calc((100vw - 1100px) / 2));
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}
.topbar h1 { margin: 0; font-size: 22px; letter-spacing: .02em; }
.topbar h1 span { color: var(--accent); }

.settings { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; }
.settings label { display: grid; gap: 2px; font-size: 12px; color: var(--muted); }
.settings input, .settings select {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px 9px;
    background: var(--bg);
}
.settings input { width: 13ch; text-transform: uppercase; letter-spacing: .08em; }

/* ---------- Layout ---------- */

.layout {
    display: grid;
    grid-template-columns: minmax(0, 560px) minmax(0, 1fr);
    gap: 28px;
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px 16px 40px;
}
@media (max-width: 860px) {
    .layout { grid-template-columns: minmax(0, 1fr); }
}

.board-area { display: grid; gap: 12px; align-content: start; }
.meta { color: var(--muted); font-size: 13px; min-height: 1.4em; }
.meta strong { color: var(--text); }

/* ---------- Spielfeld ---------- */

.board {
    container-type: inline-size;
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    width: 100%;
    aspect-ratio: 1;
    border: 2px solid var(--line-strong);
    border-radius: 4px;
    background: var(--surface);
    user-select: none;
}

.cell {
    position: relative;
    display: grid;
    place-items: center;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    font-size: 6.4cqi;
    cursor: pointer;
    transition: background-color .12s;
}
.cell.c8 { border-right: 0; }
.cell.r8 { border-bottom: 0; }
.cell.bx-r { border-right: 2px solid var(--line-strong); }
.cell.bx-b { border-bottom: 2px solid var(--line-strong); }

.cell.given { font-weight: 650; }
.cell.user { color: var(--user); }
.cell.deduced { color: var(--deduced); }
.cell.word { background: var(--word); }
.cell.peer { background: var(--peer); }
.cell.same { background: var(--same); }
.cell.selected { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.cell.wrong { color: var(--wrong); background: var(--wrong-soft); }
.cell.ref { background: var(--ref-soft); }
.cell.target { background: var(--ok-soft); box-shadow: inset 0 0 0 2px var(--ok); }
.board.path .cell { cursor: default; }

.notes {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    padding: 6%;
    font-size: 2.5cqi;
    line-height: 1;
    color: var(--muted);
}
.notes span { display: grid; place-items: center; border-radius: 3px; }
.notes .elim { color: var(--wrong); text-decoration: line-through; font-weight: 700; background: var(--wrong-soft); }
.notes .place { color: var(--ok); font-weight: 700; background: var(--ok-soft); }

.board.solved { border-color: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }

/* ---------- Eingabe ---------- */

.pad { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; }
.pad button { padding: 9px 0; font-size: 18px; font-weight: 600; }
.pad button.done { opacity: .35; }
.pad.notes-mode button:not(.erase) { font-size: 13px; color: var(--accent); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.message { margin: 0; min-height: 1.5em; }
.message.error { color: var(--wrong); }
.message.success { color: var(--ok); font-weight: 600; }

/* ---------- Seitenleiste ---------- */

.panel { min-width: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button {
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    background: none;
    padding: 8px 14px;
    color: var(--muted);
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.panel-body { display: grid; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card h2 { font-size: 14px; margin: 0 0 6px; }
.help ul { margin: 0; padding-left: 18px; color: var(--muted); }
.help li + li { margin-top: 4px; }

.badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 99px;
    border: 1px solid currentColor;
    white-space: nowrap;
}
.lvl-1 { color: var(--lvl-1); }
.lvl-2 { color: var(--lvl-2); }
.lvl-3 { color: var(--lvl-3); }
.lvl-4 { color: var(--lvl-4); }

.step-title { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.step-title strong { font-size: 16px; }
.step-detail p, .hint-card p { margin: 6px 0; }
.effects { font-family: ui-monospace, monospace; font-size: 13px; color: var(--ok); }
.technique-info { color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; }
.hint-card .actions { margin-top: 10px; }

.step-nav { display: flex; align-items: center; gap: 10px; }
.step-nav span { flex: 1; text-align: center; font-variant-numeric: tabular-nums; }
.toggle { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }

.player { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.player #btn-play { min-width: 9.5em; }
.player label:not(.toggle) { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.player select { border: 1px solid var(--line); border-radius: 8px; padding: 5px 7px; background: var(--surface); }

.progress { height: 4px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }

/* ---------- Animation des Lösungswegs ---------- */

@keyframes pop {
    0% { transform: scale(.3); opacity: 0; }
    60% { transform: scale(1.18); opacity: 1; }
    100% { transform: scale(1); }
}
@keyframes flash {
    from { background-color: var(--ok-soft); }
}
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.4); }
}

.cell .value { display: inline-block; }
.cell.pop { animation: flash 1.2s ease-out; }
.cell.pop .value { animation: pop .45s ease-out; }
.notes .elim, .notes .place { animation: pulse .5s ease-in-out 2; }

@media (prefers-reduced-motion: reduce) {
    .cell.pop, .cell.pop .value, .notes span { animation: none !important; }
    #progress-bar { transition: none; }
}

.summary { display: flex; flex-wrap: wrap; gap: 6px; }
.summary .chip {
    font-size: 12px;
    padding: 3px 9px;
    border-radius: 99px;
    background: var(--surface-2);
    cursor: help;
}

.step-list {
    position: relative; /* Bezugspunkt für offsetTop der Einträge */
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 340px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}
.step-list li {
    display: grid;
    grid-template-columns: 3ch auto 1fr;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    font-size: 13px;
    cursor: pointer;
    border-bottom: 1px solid var(--line);
}
.step-list li:last-child { border-bottom: 0; }
.step-list li:hover { background: var(--surface-2); }
.step-list li.current { background: var(--accent-soft); }
.step-list li .num { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.step-list.skip-singles li.single { display: none; }
