:root {
    color-scheme: dark;
    --bg: #0d1117;
    --stage: #05070a;
    --panel: rgba(17, 23, 31, 0.96);
    --panel-solid: #151c26;
    --line: rgba(255, 255, 255, 0.15);
    --text: #f5f7fb;
    --muted: #aab4c3;
    --control: #242c38;
    --control-hover: #303a49;
    --lava: #ff4d5f;
    --floor: #32d39c;
    --life: #f3c64b;
    --finish: #73a7ff;
    --key: #f59e0b;
    --ink: #080b10;
    --shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
}

button,
input {
    font: inherit;
}

button,
input {
    border: 1px solid var(--line);
    background: var(--control);
    color: var(--text);
}

button {
    min-height: 42px;
    border-radius: 7px;
    padding: 0 14px;
    cursor: pointer;
    transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

button:hover:not(:disabled) {
    background: var(--control-hover);
    border-color: rgba(255, 255, 255, 0.28);
}

button:active:not(:disabled) {
    transform: translateY(1px);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.primary,
.primary-action {
    background: var(--life);
    border-color: var(--life);
    color: #171202;
    font-weight: 850;
}

.primary:hover:not(:disabled),
.primary-action:hover:not(:disabled) {
    background: #ffdc74;
    border-color: #ffdc74;
}

.app-shell {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    width: 100vw;
    height: 100vh;
}

.app-shell.is-intro {
    grid-template-columns: 1fr;
}

.app-shell.is-intro .control-panel {
    display: none;
}

.stage {
    position: relative;
    min-width: 0;
    height: 100vh;
    overflow: hidden;
    background: var(--stage);
}

#camera,
#overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

#camera {
    object-fit: contain;
    background: #000;
}

#overlay {
    z-index: 2;
    touch-action: none;
}

.empty-state {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: grid;
    place-items: center;
    background:
        linear-gradient(180deg, rgba(8, 11, 16, 0.12), rgba(8, 11, 16, 0.86)),
        #090d13;
}

.empty-state.is-hidden {
    display: none;
}

.empty-panel {
    width: min(420px, calc(100vw - 40px));
    padding: 30px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(18, 24, 33, 0.9);
    box-shadow: var(--shadow);
    text-align: center;
}

.empty-panel h1 {
    margin: 6px 0 22px;
    font-size: clamp(34px, 4vw, 52px);
    line-height: 1;
    letter-spacing: 0;
}

.empty-back-link {
    display: block;
    margin-top: 16px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.empty-back-link:hover {
    color: var(--text);
}

.game-logo {
    display: block;
    width: min(174px, 54vw);
    max-height: 148px;
    margin: 0 auto 12px;
    object-fit: contain;
}

.eyebrow {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.control-panel {
    z-index: 4;
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: 100vh;
    padding: 12px;
    border-left: 1px solid var(--line);
    background: var(--panel);
    backdrop-filter: blur(14px);
    overflow-y: auto;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.panel-header h2 {
    margin: 2px 0 0;
    font-size: 22px;
    line-height: 1.05;
    letter-spacing: 0;
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-button {
    display: grid;
    place-items: center;
    width: 44px;
    min-height: 44px;
    padding: 0;
    font-weight: 900;
}

.fullscreen-icon,
.camera-switch-icon {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.fullscreen-exit-icon,
.icon-button.is-fullscreen .fullscreen-enter-icon {
    display: none;
}

.icon-button.is-fullscreen .fullscreen-exit-icon {
    display: block;
}

.life-board {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 40px;
    padding: 7px;
    border: 1px solid rgba(255, 77, 95, 0.36);
    border-radius: 8px;
    background: rgba(255, 77, 95, 0.09);
}

.life-chip {
    position: relative;
    display: grid;
    place-items: center;
    width: 34px;
    height: 31px;
}

.life-heart {
    position: absolute;
    color: #f0354b;
    font-size: 38px;
    line-height: 1;
    text-shadow: 0 2px 0 rgba(92, 5, 19, 0.82);
}

.life-count {
    position: relative;
    z-index: 1;
    color: #ffffff;
    font-size: 13px;
    font-weight: 950;
    line-height: 1;
    text-shadow: 0 1px 2px rgba(63, 0, 8, 0.95);
}

.life-chip.is-empty {
    opacity: 0.48;
}

.wizard-panel {
    display: grid;
    gap: 9px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.045);
}

.wizard-copy {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.35;
}

  .area-tools,
  .mode-tools,
.paint-tools,
.life-tools {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

  .area-tools[hidden],
  .mode-tools[hidden],
.paint-tools[hidden],
.life-tools[hidden],
.life-board[hidden],
.game-actions[hidden] {
    display: none;
}

  .area-tools .primary-action,
  .mode-tools .primary-action,
.paint-tools .primary-action,
.life-tools .primary-action {
    grid-column: span 1;
}

.area-tools button {
    grid-column: 1 / -1;
}

.tool-label {
    align-self: center;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.grid-dimension {
    display: grid;
    gap: 6px;
}

.grid-dimension .tool-label {
    text-align: center;
}

.paint-grid-size {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.stepper {
    display: grid;
    grid-template-columns: 42px 1fr 42px;
    align-items: center;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 7px;
    overflow: hidden;
}

.stepper button {
    min-height: 42px;
    border: 0;
    border-radius: 0;
    padding: 0;
}

.stepper strong {
    display: grid;
    place-items: center;
    min-height: 42px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.055);
    font-size: 18px;
}

.mode-picker,
.type-picker {
    grid-column: 1 / -1;
    display: grid;
    gap: 8px;
}

.mode-picker {
    grid-template-columns: repeat(3, 1fr);
}

.type-picker {
    grid-template-columns: repeat(auto-fit, minmax(68px, 1fr));
}

.mode-button,
.type-button {
    min-width: 0;
    padding: 0 8px;
    font-size: 13px;
    font-weight: 800;
}

#fillLavaButton {
    grid-column: 1 / -1;
}

.mode-button.is-selected {
    color: #071018;
    background: var(--finish);
    border-color: var(--finish);
}

.game-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.edit-fields-button {
    grid-column: 1 / -1;
}

.type-button[data-type="lava"] {
    border-color: rgba(255, 77, 95, 0.55);
}

.type-button[data-type="life"] {
    border-color: rgba(243, 198, 75, 0.55);
}

.type-button[data-type="floor"] {
    border-color: rgba(50, 211, 156, 0.55);
}

.type-button[data-type="finish"] {
    border-color: rgba(115, 167, 255, 0.55);
}

.type-button[data-type="key"] {
    border-color: rgba(245, 158, 11, 0.65);
}

.type-button[hidden] {
    display: none;
}

.type-button.is-selected {
    color: #071018;
    background: var(--finish);
    border-color: var(--finish);
}

.type-button.is-selected[data-type="lava"] {
    background: var(--lava);
    border-color: var(--lava);
    color: #23070b;
}

.type-button.is-selected[data-type="life"] {
    background: var(--life);
    border-color: var(--life);
    color: #171202;
}

.type-button.is-selected[data-type="floor"] {
    background: var(--floor);
    border-color: var(--floor);
    color: #04150f;
}

.type-button.is-selected[data-type="key"] {
    color: #2b1600;
    border-color: var(--key);
    background: var(--key);
}

.danger {
    border-color: rgba(255, 77, 95, 0.45);
    color: #ffd4da;
    background: rgba(255, 77, 95, 0.12);
}

.danger:hover:not(:disabled) {
    background: rgba(255, 77, 95, 0.2);
}

@media (max-width: 980px) and (orientation: portrait) {
    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1fr) auto;
    }

    .stage {
        height: calc(100vh - 255px);
        min-height: 260px;
    }

    .control-panel {
        height: 255px;
        border-left: 0;
        border-top: 1px solid var(--line);
    }
}

@media (max-width: 980px) and (orientation: landscape) {
    .app-shell {
        grid-template-columns: minmax(0, 1fr) minmax(280px, 38vw);
        grid-template-rows: 1fr;
    }

    .stage {
        height: 100vh;
        min-height: 0;
    }

    .control-panel {
        height: 100vh;
        border-top: 0;
        border-left: 1px solid var(--line);
    }
}

@media (max-width: 620px) and (orientation: portrait) {
    .control-panel {
        padding: 10px;
    }

    .panel-header h2 {
        font-size: 20px;
    }

    .type-button {
        min-height: 38px;
        padding: 0 4px;
        font-size: 12px;
    }
}
