:root {
    --app-blue: #0078d7;
    --app-blue-dark: #005a9e;
    --app-bg: #f2f2f2;
    --line: #9aa6b8;
    --line-strong: #24364f;
    --cell: #ffffff;
    --fixed: #f4f7fb;
    --related: #eaf4ff;
    --same: #b9dcff;
    --selected: #fff2a8;
    --note-match: #d7ecff;
    --danger: #ffd9d9;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body.sudoku-app-page {
    min-height: 100vh;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--app-bg);
    color: #1f2937;
}

.sudoku-cell.highlight {
    background-color: rgba(255, 0, 0, 0.3); /* Rotes Highlight für aktive Werte */
}

.sudoku-app {
    min-height: 100vh;
    max-width: 640px;
    margin: 0 auto;
    background: #f7f7f7;
    display: flex;
    flex-direction: column;
}

.app-header {
    display: grid;
    grid-template-columns: 44px 44px 1fr 44px 44px;
    align-items: center;
    gap: 6px;
    min-height: 74px;
    padding: 10px 10px 8px;
    background: var(--app-blue);
    color: #fff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}

.icon-button {
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
}

.icon-button.plus {
    font-size: 1.7rem;
    font-weight: 800;
}

.icon-button:active,
.icon-button:focus-visible {
    background: rgba(255, 255, 255, 0.28);
    outline: 2px solid rgba(255, 255, 255, 0.8);
}

.title-block {
    text-align: center;
    min-width: 0;
}

.title-block h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 750;
    line-height: 1.15;
}

.subline {
    margin-top: 3px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.82rem;
    opacity: 0.96;
}

.subline select {
    appearance: none;
    border: 0;
    border-radius: 6px;
    padding: 3px 18px 3px 8px;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    font: inherit;
}

.subline select option {
    color: #111;
}

.status-strip {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    background: #d4dce8;
    border-bottom: 1px solid #c7d0dd;
}

.status-strip span {
    background: #ffffff;
    padding: 8px 4px;
    text-align: center;
    font-size: 0.82rem;
    font-weight: 700;
    color: #475569;
}

.sudoku-status {
    min-height: 28px;
    margin: 0;
    padding: 8px 12px 4px;
    text-align: center;
    color: #475569;
    font-size: 0.9rem;
    font-weight: 650;
}

.sudoku-status[data-type="error"] {
    color: #b91c1c;
}

.sudoku-status[data-type="success"] {
    color: #047857;
}

.build-marker {
    margin: 0;
    padding: 0 12px 8px;
    text-align: center;
    color: #94a3b8;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.board-zone {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 10px 10px;
}

.sudoku-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    width: min(100%, 560px, calc(100vh - 245px));
    aspect-ratio: 1 / 1;
    background: var(--line-strong);
    border: 3px solid var(--line-strong);
    box-shadow: 0 8px 28px rgba(15, 23, 42, 0.18);
}

.sudoku-cell {
    position: relative;
    isolation: isolate;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    border: 1px solid var(--line);
    background: var(--cell);
    color: #111827;
    font-size: clamp(1.08rem, 5vw, 2.08rem);
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    padding: 0;
}

.sudoku-cell:nth-child(3n) {
    border-right-width: 3px;
    border-right-color: var(--line-strong);
}

.sudoku-cell:nth-child(9n) {
    border-right-width: 1px;
    border-right-color: var(--line);
}

.sudoku-cell:nth-child(n+19):nth-child(-n+27),
.sudoku-cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom-width: 3px;
    border-bottom-color: var(--line-strong);
}

.sudoku-cell.fixed {
    background: var(--fixed);
    color: #0f172a;
    font-weight: 800;
    cursor: default;
}

.sudoku-cell.related {
    background: var(--related);
}

.sudoku-cell.same-number {
    background: var(--same);
    color: #052e75;
    font-weight: 900;
}

.sudoku-cell.note-match {
    background: var(--note-match);
}

.sudoku-cell.selected {
    background: var(--selected);
    outline: 3px solid #f59e0b;
    outline-offset: -3px;
    box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.9), 0 0 0 2px rgba(245, 158, 11, 0.45);
    z-index: 2;
}

.sudoku-cell.error {
    background: var(--danger);
    color: #991b1b;
}

.sudoku-cell.hint {
    background: #d1fae5;
    color: #065f46;
}

.cell-value {
    position: relative;
    z-index: 2;
    line-height: 1;
}

.notes-grid {
    position: absolute;
    inset: 0;
    z-index: 4;
    color: #7c8798;
    font-size: clamp(0.42rem, 1.85vw, 0.66rem);
    font-weight: 700;
    line-height: 1;
    pointer-events: none;
}

.note-slot {
    position: absolute;
    display: block;
    width: 20%;
    height: 20%;
    text-align: center;
}

.note-slot.active-note {
    color: #5b6573;
    font-weight: 800;
}

.note-pos-1 { top: 10%; left: 10%; }
.note-pos-2 { top: 10%; left: 40%; }
.note-pos-3 { top: 10%; left: 70%; }
.note-pos-4 { top: 38%; left: 10%; }
.note-pos-5 { top: 38%; left: 40%; }
.note-pos-6 { top: 38%; left: 70%; }
.note-pos-7 { top: 66%; left: 10%; }
.note-pos-8 { top: 66%; left: 40%; }
.note-pos-9 { top: 66%; left: 70%; }

.tool-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 8px 10px 6px;
    background: #f7f7f7;
}

.tool-button {
    border: 0;
    border-radius: 8px;
    background: #ffffff;
    color: #334155;
    min-height: 48px;
    display: grid;
    place-items: center;
    gap: 1px;
    font-size: 0.76rem;
    font-weight: 750;
    box-shadow: 0 2px 7px rgba(15, 23, 42, 0.13);
    cursor: pointer;
}

.tool-button span {
    font-size: 1.12rem;
    line-height: 1;
}

.tool-button.active,
.tool-button[aria-pressed="true"] {
    background: var(--app-blue);
    color: #fff;
}

.number-pad {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 8px;
    padding: 6px 10px 14px;
    background: #f7f7f7;
}

.number-pad button {
    position: relative;
    min-height: 54px;
    border: 0;
    border-radius: 8px;
    background: linear-gradient(#128ee8, #006fc8);
    color: #fff;
    font-weight: 850;
    box-shadow: 0 3px 8px rgba(0, 80, 150, 0.25);
    cursor: pointer;
}

.number-pad button .num {
    font-size: 1.45rem;
    line-height: 1;
}

.number-pad button .remaining {
    position: absolute;
    right: 5px;
    top: 4px;
    min-width: 16px;
    height: 16px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: #005a9e;
    display: grid;
    place-items: center;
    font-size: 0.68rem;
    font-weight: 900;
}

.number-pad button.active {
    background: linear-gradient(#003c7e, #002f68);
    outline: 3px solid #f59e0b;
    outline-offset: -2px;
}

.number-pad button.complete {
    opacity: 0.42;
}

@media (max-width: 520px) {
    .sudoku-app {
        max-width: none;
    }

    .app-header {
        grid-template-columns: 40px 40px 1fr 40px 40px;
        min-height: 68px;
        padding: 8px 8px 7px;
    }

    .icon-button {
        width: 38px;
        height: 38px;
        font-size: 1.18rem;
    }

    .title-block h1 {
        font-size: 1.12rem;
    }

    .sudoku-board {
        width: min(100%, calc(100vh - 250px));
    }

    .tool-row,
    .number-pad {
        gap: 6px;
        padding-left: 8px;
        padding-right: 8px;
    }

    .number-pad button {
        min-height: 50px;
    }

    .number-pad button .num {
        font-size: 1.28rem;
    }
}

@media (max-width: 370px) {
    .status-strip span {
        font-size: 0.72rem;
    }

    .tool-button {
        min-height: 44px;
        font-size: 0.68rem;
    }

    .number-pad button {
        min-height: 46px;
    }

    .notes-grid {
        font-size: clamp(0.48rem, 3.1vw, 0.64rem);
    }
}

/* ═══════════════════════════════════════════════════════
   Eisbrecher-Modus — Eisblöcke
   ═══════════════════════════════════════════════════════ */

/* 3 HP — heil: milchig-blau, Frostglas */
.sudoku-cell.ice-3 {
    background: rgba(180, 220, 255, 0.32);
    box-shadow: inset 0 0 4px rgba(255, 255, 255, 0.45);
    border-color: rgba(255, 255, 255, 0.38);
}

/* 2 HP — Risse: erster Schaden */
.sudoku-cell.ice-2 {
    background: rgba(160, 200, 240, 0.24);
    box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.32);
    border-color: rgba(255, 255, 255, 0.3);
}
.sudoku-cell.ice-2::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background:
        linear-gradient(45deg, transparent 45%, rgba(0, 0, 0, 0.15) 45%, rgba(0, 0, 0, 0.15) 48%, transparent 48%),
        linear-gradient(-30deg, transparent 55%, rgba(0, 0, 0, 0.12) 55%, rgba(0, 0, 0, 0.12) 58%, transparent 58%);
}

/* 1 HP — stark beschädigt: fast zerstört */
.sudoku-cell.ice-1 {
    background: rgba(140, 180, 220, 0.16);
    box-shadow: inset 0 0 2px rgba(255, 255, 255, 0.22);
    border-color: rgba(255, 255, 255, 0.24);
}
.sudoku-cell.ice-1::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background:
        linear-gradient(20deg, transparent 30%, rgba(0, 0, 0, 0.2) 30%, rgba(0, 0, 0, 0.2) 33%, transparent 33%),
        linear-gradient(-50deg, transparent 60%, rgba(0, 0, 0, 0.18) 60%, rgba(0, 0, 0, 0.18) 63%, transparent 63%),
        linear-gradient(70deg, transparent 40%, rgba(0, 0, 0, 0.15) 40%, rgba(0, 0, 0, 0.15) 42%, transparent 42%);
}

.sudoku-cell.ice-3 .notes-grid,
.sudoku-cell.ice-2 .notes-grid,
.sudoku-cell.ice-1 .notes-grid {
    color: #16324f;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}

.sudoku-cell.related.ice-3,
.sudoku-cell.related.ice-2,
.sudoku-cell.related.ice-1 {
    background: #dcecff;
    border-color: var(--line);
}

.sudoku-cell.selected.ice-3,
.sudoku-cell.selected.ice-2,
.sudoku-cell.selected.ice-1 {
    background: #fff2a8;
    border-color: #f59e0b;
}

.sudoku-cell.has-notes .notes-grid {
    background: rgba(255, 255, 255, 0.18);
}

.selection-indicator {
    position: absolute;
    inset: 3px;
    z-index: 7;
    border: 3px solid #ff8c00;
    border-radius: 4px;
    box-shadow: inset 0 0 0 2px rgba(255, 245, 157, 0.98), 0 0 0 1px rgba(255, 140, 0, 0.5);
    pointer-events: none;
}

/* Zerstörungsanimation */
@keyframes ice-break {
    0%   { transform: scale(1) rotate(0deg); opacity: 1; }
    30%  { transform: scale(1.15) rotate(3deg); opacity: 0.8; }
    100% { transform: scale(0.4) rotate(10deg); opacity: 0; }
}
.sudoku-cell.ice-breaking {
    animation: ice-break 0.4s ease-out forwards;
}

/* Mode-Selector */
.mode-select {
    font-size: 0.8rem;
    padding: 2px 4px;
    border-radius: 4px;
    border: 1px solid var(--border-color, #555);
    background: var(--bg-color, #1a1a2e);
    color: var(--text-color, #eee);
}

/* ═══════════════════════════════════════════════════════
   Eisbrecher-Modus — Schockwellen
   ═══════════════════════════════════════════════════════ */

@keyframes shockwave-h {
    0%   { transform: scaleX(0); opacity: 0.8; }
    100% { transform: scaleX(1); opacity: 0; }
}
@keyframes shockwave-v {
    0%   { transform: scaleY(0); opacity: 0.8; }
    100% { transform: scaleY(1); opacity: 0; }
}

.shockwave-row,
.shockwave-col {
    position: absolute;
    background: radial-gradient(ellipse, rgba(100, 180, 255, 0.7), transparent);
    pointer-events: none;
    z-index: 10;
}
.shockwave-row {
    transform-origin: left center;
    animation: shockwave-h 0.35s ease-out forwards;
}
.shockwave-col {
    transform-origin: center top;
    animation: shockwave-v 0.35s ease-out forwards;
}

/* Overlay-Container — nie von render() zurückgesetzt */
.overlay-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}
