:root {
    color-scheme: light;
    --ink: #192522;
    --ink-soft: #38514a;
    --paper: #eef1e9;
    --panel: #f9faf5;
    --line: #ccd4c9;
    --muted: #68776f;
    --red: #cf503d;
    --red-dark: #a93f31;
    --yellow: #f0c64d;
    --teal: #52b6a8;
    --white: #fffefa;
    --font-display: "Bahnschrift", "Franklin Gothic Medium", "Arial Narrow", sans-serif;
    --font-body: "Trebuchet MS", sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background-color: var(--paper);
    background-image: radial-gradient(#cbd3c8 0.65px, transparent 0.65px);
    background-size: 14px 14px;
    font-family: var(--font-body);
}

button,
input,
select {
    font: inherit;
}

button,
a,
input,
select {
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 3px solid var(--teal);
    outline-offset: 3px;
}

.player-main {
    width: min(1460px, 100%);
    min-height: 100vh;
    margin: 0 auto;
    padding: 20px clamp(16px, 3vw, 40px);
}

.eyebrow {
    margin: 0 0 10px;
    color: var(--muted);
    font-family: var(--font-display);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 1px;
}

h1,
h2,
p {
    margin-top: 0;
}

h1,
h2 {
    font-family: var(--font-display);
    letter-spacing: 0;
}

h1 {
    margin-bottom: 18px;
    font-size: 34px;
    line-height: 1.08;
}

h2 {
    margin-bottom: 24px;
    font-size: 25px;
}

[hidden] {
    display: none !important;
}

.identity-panel {
    width: min(570px, 100%);
    margin: 8vh auto 0;
    padding: 34px;
    border-top: 5px solid var(--red);
    background: var(--panel);
    box-shadow: 0 18px 48px rgb(25 37 34 / 8%);
    animation: panel-enter 340ms ease-out both;
}

label {
    display: block;
    margin-bottom: 9px;
    color: var(--ink-soft);
    font-size: 13px;
    font-weight: 700;
}

.form-row {
    display: flex;
    gap: 10px;
}

input,
select {
    min-width: 0;
    min-height: 48px;
    padding: 0 13px;
    border: 1px solid var(--line);
    border-radius: 2px;
    color: var(--ink);
    background: var(--white);
}

input:focus,
select:focus {
    border-color: var(--teal);
}

.identity-panel input {
    flex: 1;
}

.brand-picker {
    margin: 0 0 18px;
    padding: 0;
    border: 0;
}

.brand-picker legend {
    margin-bottom: 9px;
    color: var(--ink-soft);
    font-size: 13px;
    font-weight: 700;
}

.brand-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.brand-option {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 2px;
    color: var(--ink);
    background: var(--white);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.brand-option:has(input:checked) {
    border-color: var(--teal);
}

.brand-option input {
    flex: none;
    min-height: 0;
    width: 16px;
    height: 16px;
    margin: 0;
    padding: 0;
    accent-color: var(--teal);
}

.brand-swatch {
    display: inline-block;
    width: 18px;
    height: 18px;
    border-radius: 2px;
}

.button {
    display: inline-flex;
    min-height: 46px;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    gap: 9px;
    padding: 0 17px;
    border: 0;
    border-radius: 2px;
    cursor: pointer;
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 800;
    transition: background-color 130ms ease, transform 130ms ease;
}

.button:active {
    transform: translateY(1px);
}

.button-primary {
    color: var(--white);
    background: var(--red);
}

.button-primary:hover {
    background: var(--red-dark);
}

.form-error,
.notice-bar {
    margin: 14px 0 0;
    color: var(--red-dark);
    font-size: 13px;
}

.game-layout {
    display: grid;
    height: calc(100vh - 40px);
    height: calc(100dvh - 40px);
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
        "tools"
        "board"
        "controls"
        "message";
    justify-items: center;
    gap: 12px;
    animation: panel-enter 300ms ease-out both;
}

.game-tools {
    display: flex;
    width: min(100%, 880px);
    align-items: center;
    justify-content: space-between;
    grid-area: tools;
    gap: 16px;
}

.game-tools select {
    width: min(220px, 70%);
    min-height: 38px;
    padding: 0 10px;
}

.move-readout {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.readout-label {
    color: var(--muted);
    font-family: var(--font-display);
    font-size: 11px;
    font-weight: 800;
}

.move-readout strong {
    color: var(--red-dark);
    font-family: var(--font-display);
    font-size: 25px;
}

.game-message {
    display: block;
    min-height: 24px;
    grid-area: message;
    color: var(--ink-soft);
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 800;
}

.next-level {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 3;
    display: flex;
    box-sizing: border-box;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    width: min(90%, 520px);
    padding: 28px 24px;
    background: rgb(25 37 34 / 82%);
    color: var(--white);
    text-align: center;
    transform: translate(-50%, -50%);
    transition: opacity 300ms ease-out, visibility 300ms ease-out;
}

/* Die Frage blendet erst nach dem Siegesbanner ein (Klasse wird nach der Animation entfernt). */
.board-frame.is-celebrating .next-level {
    visibility: hidden;
    opacity: 0;
}

.next-level[hidden] {
    display: none;
}

.next-level-text {
    margin: 0;
    color: var(--white);
    font-family: var(--font-display);
    font-size: clamp(22px, 4vw, 36px);
    font-weight: 800;
}

.next-level-button {
    min-height: 52px;
    padding: 0 28px;
    font-size: 18px;
}

.next-level-button[hidden] {
    display: none;
}

.board-wrap {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    min-height: 0;
    grid-area: board;
}

.button-danger {
    color: var(--red-dark);
    background: var(--panel);
    border: 1px solid var(--red);
}

.button-danger:hover {
    color: var(--white);
    background: var(--red);
}

.button-danger:disabled {
    cursor: wait;
    opacity: 0.55;
}

.button-reset {
    flex: 0 0 auto;
    min-height: 38px;
    padding: 0 14px;
    border: 1px solid var(--line);
    font-size: 14px;
    color: var(--ink);
    background: var(--panel);
}

.button-reset:hover {
    background: var(--yellow);
}

.button-reset:disabled {
    cursor: wait;
    opacity: 0.55;
}

.board-frame {
    position: relative;
    display: grid;
    flex: 1 1 0;
    min-height: 0;
    place-items: center;
    background: rgb(249 250 245 / 55%);
}

.game-board {
    display: grid;
    width: max-content;
    grid-template-columns: repeat(var(--board-columns), var(--tile-size, 38px));
    gap: 0;
    overflow: hidden;
    background: #d7e4dc;
}

.board-cell {
    position: relative;
    width: var(--tile-size, 38px);
    aspect-ratio: 1;
    overflow: hidden;
    background-color: #d7e4dc;
    background-position: center;
    background-size: cover;
    cursor: pointer;
    touch-action: manipulation;
}

.board-cell.is-wall {
    background-image: url("../assets/tiles/wall.png");
}

.board-cell img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    user-select: none;
}

.board-cell .goal-sprite {
    z-index: 1;
}

.board-cell .entity-sprite {
    z-index: 2;
}

.board-cell .entity-sprite.is-on-goal {
    outline: 3px solid #f2c200;
    outline-offset: -3px;
}

.control-rail {
    grid-area: controls;
}

.direction-pad {
    display: grid;
    grid-template-columns: repeat(3, 48px);
    grid-template-rows: repeat(2, 48px);
    gap: 5px;
}

.direction-pad button {
    display: grid;
    width: 48px;
    height: 48px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 2px;
    color: var(--ink);
    background: var(--panel);
    cursor: pointer;
    font-size: 21px;
    touch-action: manipulation;
}

.direction-pad button:hover {
    border-color: var(--ink-soft);
    background: var(--yellow);
}

.direction-pad button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.notice-bar {
    width: fit-content;
    max-width: 100%;
    margin: 20px auto 0;
    padding: 10px 14px;
    border-left: 3px solid var(--red);
    background: var(--panel);
}

@keyframes panel-enter {
    from {
        opacity: 0;
        transform: translateY(9px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 900px) {
    .move-readout {
        display: inline-flex;
        gap: 8px;
    }
}

@media (max-width: 520px) {
    .player-main {
        padding: 12px 12px 20px;
    }

    .identity-panel {
        margin-top: 9vh;
        padding: 25px 21px;
    }

    .form-row {
        flex-direction: column;
    }

    .form-row .button {
        width: 100%;
    }

    .game-layout {
        height: calc(100vh - 32px);
        height: calc(100dvh - 32px);
        gap: 8px;
    }

    .direction-pad {
        width: 100%;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        grid-template-rows: repeat(2, 64px);
        gap: 6px;
    }

    .direction-pad button {
        width: 100%;
        height: 64px;
        font-size: 28px;
    }

    .control-rail {
        width: min(100%, 280px);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

.liveview-main {
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-sizing: border-box;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    padding: 20px clamp(16px, 2vw, 32px);
}

.liveview-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
}

.liveview-header h1 {
    margin: 0;
}

.liveview-header output {
    color: var(--ink-soft);
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 800;
}

.live-empty {
    margin: 0;
    color: var(--muted);
}

.live-grid {
    display: grid;
    grid-template-columns: repeat(var(--live-columns, 1), minmax(0, 1fr));
    grid-template-rows: repeat(var(--live-rows, 1), minmax(0, 1fr));
    flex: 1 1 0;
    gap: 10px;
    min-height: 0;
}

.live-slot {
    position: relative;
    min-width: 0;
    min-height: 0;
}

.live-board {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    background: var(--panel);
    transition: opacity 0.5s ease-in-out;
}

.live-board.is-entering {
    opacity: 0;
}

.live-board.is-leaving {
    opacity: 0;
    pointer-events: none;
}

.live-board .board-frame {
    min-width: 0;
    min-height: 0;
}

.live-canvas {
    position: relative;
    width: max-content;
    height: max-content;
}

.live-overlay {
    position: absolute;
    top: 0;
    left: 0;
    display: grid;
    max-width: 100%;
    gap: 2px;
    padding: 6px 10px 6px 8px;
    border-left: 4px solid var(--brand-color, var(--teal));
    background: rgb(25 37 34 / 82%);
    color: var(--white);
    pointer-events: none;
}

.live-name {
    overflow: hidden;
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.live-level {
    overflow: hidden;
    color: #d7e4dc;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.live-victory {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 2;
    padding: 10px 18px;
    background: var(--brand-color, var(--teal));
    color: var(--white);
    font-family: var(--font-display);
    font-size: clamp(18px, 3vw, 32px);
    font-weight: 800;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(0.6);
}

.live-board.is-celebrating .live-victory,
.board-frame.is-celebrating .live-victory {
    animation: live-victory 2s ease-out both;
}

.live-board.is-celebrating .board-frame,
.board-frame.is-celebrating {
    animation: live-board-flash 2s ease-out;
}

@keyframes live-victory {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.6);
    }
    15% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.08);
    }
    25% {
        transform: translate(-50%, -50%) scale(1);
    }
    75% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1);
    }
}

@keyframes live-board-flash {
    0%,
    100% {
        filter: none;
    }
    20% {
        filter: brightness(1.3) saturate(1.2);
    }
}

.levels-main {
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-sizing: border-box;
    width: 100%;
    min-height: 100vh;
    padding: 20px clamp(16px, 2vw, 32px);
}

.levels-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
}

.levels-header h1 {
    margin: 0;
}

.levels-header output {
    color: var(--ink-soft);
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 800;
}

.levels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 14px;
}

.levels-tile {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.levels-frame {
    width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
    border: 1px solid var(--line);
}

.levels-tile .board-cell {
    cursor: default;
}

.levels-label {
    margin: 0;
    overflow: hidden;
    color: var(--ink-soft);
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.site-footer {
    padding: 16px clamp(16px, 3vw, 40px) 24px;
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}

.site-footer p {
    margin: 0;
}

.site-footer a {
    color: var(--ink-soft);
    overflow-wrap: anywhere;
}
