/* ---------- Base ---------- */
:root {
    --cell: 44px;
    --font-pixel: 'Press Start 2P', 'Courier New', monospace;
    --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --green: #5b9d3a;
    --green-light: #9ee06e;
    --green-dark: #2d5a1b;
    --red: #c0392b;
    --gold: #ffd93b;
    --panel-bg: rgba(0, 0, 0, 0.55);
    /* Shared 8x8 pixel-noise texture layered over every block colour. */
    --tex: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' shape-rendering='crispEdges'%3E%3Crect x='0' y='0' width='1' height='1' fill='%23000' fill-opacity='.18'/%3E%3Crect x='3' y='1' width='1' height='1' fill='%23fff' fill-opacity='.14'/%3E%3Crect x='5' y='2' width='1' height='1' fill='%23000' fill-opacity='.15'/%3E%3Crect x='1' y='4' width='1' height='1' fill='%23fff' fill-opacity='.12'/%3E%3Crect x='6' y='5' width='1' height='1' fill='%23000' fill-opacity='.18'/%3E%3Crect x='2' y='6' width='1' height='1' fill='%23000' fill-opacity='.12'/%3E%3Crect x='7' y='7' width='1' height='1' fill='%23fff' fill-opacity='.12'/%3E%3Crect x='4' y='4' width='1' height='1' fill='%23000' fill-opacity='.1'/%3E%3Crect x='6' y='1' width='1' height='1' fill='%23fff' fill-opacity='.1'/%3E%3Crect x='1' y='7' width='1' height='1' fill='%23000' fill-opacity='.14'/%3E%3C/svg%3E");
}

* {
    box-sizing: border-box;
}

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

body {
    font-family: var(--font-body);
    font-weight: 600;
    color: #fff;
    background-color: #15203a;
    background-image:
        linear-gradient(#5d9e3a 0 10px, #8b5a2b 10px 100%),
        linear-gradient(#15203a 0%, #2b4a7f 55%, #5a8fd0 100%);
    background-size: 100% 56px, 100% 100%;
    background-position: bottom, top;
    background-repeat: no-repeat;
    background-attachment: fixed;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

button {
    font-family: inherit;
    touch-action: manipulation;
}

h1, h2, h3 {
    font-family: var(--font-pixel);
    font-weight: normal;
    line-height: 1.4;
}

h3 {
    font-size: 13px;
    margin: 0 0 12px;
    color: var(--gold);
}

.screen {
    max-width: 920px;
    margin: 0 auto;
    padding: 24px 16px 96px;
    text-align: center;
}

.title {
    font-size: clamp(26px, 6vw, 48px);
    color: var(--gold);
    text-shadow: 4px 4px 0 #7a5a00, 0 0 24px rgba(0, 0, 0, 0.5);
    margin: 12px 0 8px;
}

.title.red {
    color: #ff5b5b;
    text-shadow: 4px 4px 0 #5a0000, 0 0 24px rgba(0, 0, 0, 0.5);
}

.tagline {
    font-size: 18px;
    margin: 0 0 24px;
    text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.6);
}

.hint {
    opacity: 0.8;
    margin-top: 8px;
}

.panel {
    background: var(--panel-bg);
    border: 4px solid #1f1f1f;
    box-shadow: inset 0 0 0 2px #5a5a5a;
    padding: 16px;
}

/* ---------- Minecraft-style buttons ---------- */
.mc-btn {
    font-family: var(--font-pixel);
    font-size: 13px;
    line-height: 1.2;
    color: #fff;
    text-shadow: 2px 2px 0 #3a3a3a;
    background: #8b8b8b;
    border: 3px solid;
    border-color: #e0e0e0 #3a3a3a #3a3a3a #e0e0e0;
    padding: 12px 16px;
    cursor: pointer;
    user-select: none;
    transition: transform 0.05s;
}

.mc-btn:hover:not(:disabled) {
    filter: brightness(1.12);
    outline: 2px solid #fff;
}

.mc-btn:active:not(:disabled) {
    transform: translateY(2px);
    border-color: #3a3a3a #e0e0e0 #e0e0e0 #3a3a3a;
}

.mc-btn.selected,
.mc-btn.primary {
    background: var(--green);
    border-color: var(--green-light) var(--green-dark) var(--green-dark) var(--green-light);
    text-shadow: 2px 2px 0 var(--green-dark);
}

.mc-btn.danger {
    background: #a83a30;
    border-color: #e08078 #5a1a14 #5a1a14 #e08078;
    text-shadow: 2px 2px 0 #5a1a14;
}

.mc-btn:disabled {
    background: #555;
    color: #999;
    border-color: #777 #333 #333 #777;
    text-shadow: none;
    cursor: not-allowed;
}

.mc-btn.small {
    font-size: 10px;
    padding: 8px 10px;
}

.mc-btn.big-btn {
    font-size: 16px;
    padding: 18px 28px;
    margin-top: 16px;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    padding: 4px;
}

/* ---------- Blocks ---------- */
.block {
    display: inline-block;
    width: var(--cell);
    height: var(--cell);
    image-rendering: pixelated;
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.22), inset 3px 3px 0 rgba(255, 255, 255, 0.12);
    background-size: 50% 50%;
}

.b-dirt        { background: var(--tex) 0 0 / 50% 50%, #8b5a2b; }
.b-grass       { background: var(--tex) 0 0 / 50% 50%, linear-gradient(#5d9e3a 0 32%, #8b5a2b 32%); }
.b-stone       { background: var(--tex) 0 0 / 50% 50%, #7f7f7f; }
.b-cobble      { background: radial-gradient(circle at 30% 30%, #8a8a8a 0 22%, transparent 24%), radial-gradient(circle at 72% 68%, #5c5c5c 0 24%, transparent 26%), var(--tex) 0 0 / 50% 50%, #6e6e6e; }
.b-wood        { background: var(--tex) 0 0 / 50% 50%, repeating-linear-gradient(90deg, #6b4a25 0 22%, #563a1c 22% 30%); }
.b-planks      { background: var(--tex) 0 0 / 50% 50%, repeating-linear-gradient(#b8945f 0 42%, #8f6b3c 42% 50%); }
.b-leaves      { background: radial-gradient(circle at 25% 30%, #2f5e1f 0 14%, transparent 16%), radial-gradient(circle at 70% 70%, #2f5e1f 0 14%, transparent 16%), radial-gradient(circle at 75% 25%, #58a03a 0 10%, transparent 12%), var(--tex) 0 0 / 50% 50%, #3f7a2a; }
.b-glass       { background: linear-gradient(135deg, rgba(255, 255, 255, 0.55) 0 18%, transparent 20%), rgba(180, 225, 255, 0.35); box-shadow: inset 0 0 0 3px rgba(230, 245, 255, 0.75); }
.b-brick       { background: linear-gradient(#e8d8c8 0 6%, transparent 6% 47%, #e8d8c8 47% 53%, transparent 53% 94%, #e8d8c8 94%), var(--tex) 0 0 / 50% 50%, #a34a3a; }
.b-obsidian    { background: radial-gradient(circle at 70% 30%, #4a2a6a 0 18%, transparent 20%), var(--tex) 0 0 / 50% 50%, #1b1226; }
.b-portal      { background: linear-gradient(135deg, #6a1fc9, #b06cf5 50%, #6a1fc9); animation: portal 1.6s ease-in-out infinite alternate; box-shadow: 0 0 12px #b06cf5, inset 0 0 0 2px rgba(0, 0, 0, 0.2); }
.b-lava        { background: radial-gradient(circle at 30% 40%, #ffd93b 0 18%, transparent 20%), var(--tex) 0 0 / 50% 50%, linear-gradient(#ff8c1a, #e25822); animation: lava 1.2s ease-in-out infinite alternate; }
.b-water       { background: var(--tex) 0 0 / 50% 50%, #3b6fd6; }
.b-sand        { background: var(--tex) 0 0 / 50% 50%, #dcd3a0; }
.b-tnt         { background: linear-gradient(#c0392b 0 30%, #f0f0f0 30% 62%, #c0392b 62%); }
.b-door        { background: radial-gradient(circle at 78% 52%, #ffd93b 0 8%, transparent 10%), var(--tex) 0 0 / 50% 50%, repeating-linear-gradient(90deg, #5a3a1a 0 45%, #3f2810 45% 55%); }
.b-torch       { background: radial-gradient(circle at 50% 22%, #ffd93b 0 18%, #ff8c1a 18% 24%, transparent 26%), linear-gradient(#6b4a25, #6b4a25) 50% 100% / 22% 66% no-repeat; box-shadow: none; }
.b-creeper     { background: var(--tex) 0 0 / 50% 50%, #3fa83f; }
.b-creeperdark { background: var(--tex) 0 0 / 50% 50%, #1c1c1c; }
.b-snow        { background: var(--tex) 0 0 / 50% 50%, #f0f0f0; }

/* Ores: stone base with coloured specks. */
.b-coal     { --ore: #2a2a2a; }
.b-iron     { --ore: #e0b898; }
.b-gold     { --ore: #f5d24a; }
.b-redstone { --ore: #e0231f; }
.b-diamond  { --ore: #5ee7e0; }
.b-emerald  { --ore: #2ecc71; }

.b-coal, .b-iron, .b-gold, .b-redstone, .b-diamond, .b-emerald {
    background:
        radial-gradient(circle at 25% 30%, var(--ore) 0 12%, transparent 14%),
        radial-gradient(circle at 70% 66%, var(--ore) 0 12%, transparent 14%),
        radial-gradient(circle at 66% 24%, var(--ore) 0 8%, transparent 10%),
        radial-gradient(circle at 30% 74%, var(--ore) 0 8%, transparent 10%),
        var(--tex) 0 0 / 50% 50%,
        #7f7f7f;
}

.b-diamond, .b-emerald {
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.22), 0 0 10px var(--ore);
}

@keyframes portal {
    from { filter: hue-rotate(0deg) brightness(1); }
    to { filter: hue-rotate(30deg) brightness(1.25); }
}

@keyframes lava {
    from { filter: brightness(1); }
    to { filter: brightness(1.3); }
}

/* ---------- Build view ---------- */
.build {
    display: grid;
    gap: 2px;
    padding: 12px;
    margin: 0 auto;
    background: linear-gradient(rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0.3));
    border: 3px solid #2b2b2b;
    width: max-content;
}

.cell.ghost {
    width: var(--cell);
    height: var(--cell);
    outline: 2px dashed rgba(255, 255, 255, 0.18);
    outline-offset: -4px;
}

.cell.pop {
    animation: pop 0.35s ease-out;
}

@keyframes pop {
    0% { transform: scale(0.2) rotate(-12deg); opacity: 0; }
    70% { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); }
}

/* ---------- Creeper face ---------- */
.creeper {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    width: var(--size);
    height: var(--size);
    background: var(--tex) 0 0 / 25% 25%, #3fa83f;
    image-rendering: pixelated;
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.25);
    flex-shrink: 0;
}

.creeper i {
    display: block;
}

.creeper i.d {
    background: #1c1c1c;
}

/* ---------- Start screen ---------- */
.rules {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.rule {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    font-size: 15px;
}

.rule p {
    margin: 0;
}

.rule-icon .block {
    --cell: 40px;
}

.option {
    margin-bottom: 16px;
}

.tables {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.table-btn {
    width: 56px;
    height: 56px;
    padding: 0;
    font-size: 16px;
}

.quick {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
}

.difficulty {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.diff-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 8px;
}

.diff-btn .diff-emoji {
    font-size: 28px;
}

.diff-btn small {
    font-family: var(--font-body);
    font-size: 13px;
    text-shadow: none;
    opacity: 0.9;
}

.toggles {
    display: flex;
    justify-content: center;
    gap: 28px;
    flex-wrap: wrap;
}

.toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    cursor: pointer;
}

.toggle input {
    width: 22px;
    height: 22px;
    accent-color: var(--green);
}

.highscore {
    font-family: var(--font-pixel);
    font-size: 13px;
    color: var(--gold);
    text-shadow: 2px 2px 0 #7a5a00;
}

/* ---------- Game screen ---------- */
.game {
    max-width: 960px;
    margin: 0 auto;
    padding: 12px 12px 96px;
}

.hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    margin-bottom: 14px;
    font-family: var(--font-pixel);
    font-size: 13px;
}

.hearts .heart {
    font-size: 24px;
    color: #ff3b3b;
    text-shadow: 2px 2px 0 #5a0000;
    margin-right: 2px;
}

.hearts .heart.empty {
    color: #3a3a3a;
    text-shadow: 2px 2px 0 #111;
}

.score {
    color: var(--gold);
}

.level small {
    display: block;
    font-size: 9px;
    opacity: 0.8;
    margin-top: 4px;
}

.arena {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 16px;
    align-items: start;
}

.build-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.streak {
    font-family: var(--font-pixel);
    font-size: 12px;
}

.streak.hot {
    color: #ff8c1a;
    text-shadow: 0 0 8px #ff8c1a;
}

.question-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.timer {
    height: 14px;
    background: #222;
    border: 2px solid #555;
}

.timer-fill {
    height: 100%;
    background: var(--green);
    transition: width 0.1s linear;
}

.timer-fill.warn { background: #e0a020; }
.timer-fill.danger { background: var(--red); }

.question {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    flex-wrap: wrap;
    padding: 8px 0;
}

.q-text {
    font-family: var(--font-pixel);
    font-size: clamp(22px, 4.5vw, 36px);
    text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.6);
}

.answer {
    font-family: var(--font-pixel);
    font-size: clamp(22px, 4.5vw, 36px);
    width: 4.5ch;
    text-align: center;
    background: #000;
    color: #fff;
    border: 3px solid #a0a0a0;
    padding: 8px 4px;
    outline: none;
    caret-color: var(--gold);
}

.answer:focus {
    border-color: #fff;
}

.answer.ok {
    border-color: var(--green-light);
    box-shadow: 0 0 12px var(--green-light);
}

.answer.bad {
    border-color: var(--red);
    animation: shake 0.4s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-8px); }
    40%, 80% { transform: translateX(8px); }
}

.feedback {
    min-height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fb-hint {
    opacity: 0.7;
    font-size: 15px;
}

.fb-correct {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
    font-family: var(--font-pixel);
    font-size: 13px;
    color: var(--green-light);
    text-shadow: 2px 2px 0 var(--green-dark);
}

.fb-correct .loot {
    --cell: 40px;
    animation: pop 0.35s ease-out;
}

.fb-correct .bonus {
    color: var(--gold);
    text-shadow: 2px 2px 0 #7a5a00;
}

.fb-wrong {
    display: flex;
    align-items: center;
    gap: 14px;
    color: #ff9090;
    font-size: 20px;
    text-align: left;
}

.fb-wrong strong {
    font-family: var(--font-pixel);
    font-size: 13px;
    color: #ff5b5b;
}

.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    max-width: 320px;
    margin: 0 auto;
    width: 100%;
}

.numpad .key {
    font-size: 22px;
    padding: 14px 0;
}

/* ---------- Hotbar ---------- */
.hotbar {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 16px;
}

.slot {
    width: 52px;
    height: 52px;
    background: rgba(0, 0, 0, 0.65);
    border: 3px solid #8b8b8b;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.slot .block {
    --cell: 36px;
}

.slot .count {
    position: absolute;
    right: 3px;
    bottom: 1px;
    font-family: var(--font-pixel);
    font-size: 11px;
    text-shadow: 2px 2px 0 #000;
}

/* ---------- Overlay / dialog ---------- */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 10;
}

.dialog {
    text-align: center;
    max-width: 420px;
    width: 100%;
    animation: pop 0.35s ease-out;
}

.dialog h2 {
    font-size: 18px;
    color: var(--gold);
    text-shadow: 3px 3px 0 #7a5a00;
}

.dialog-emoji {
    font-size: 64px;
}

/* ---------- Game over ---------- */
.boom {
    display: flex;
    justify-content: center;
    animation: shake 0.6s;
}

.score-box {
    display: inline-block;
    min-width: 260px;
    margin-bottom: 20px;
}

.big-score {
    font-family: var(--font-pixel);
    font-size: 40px;
    color: var(--gold);
    text-shadow: 4px 4px 0 #7a5a00;
}

.score-label {
    opacity: 0.8;
}

.record {
    margin-top: 10px;
    font-family: var(--font-pixel);
    font-size: 12px;
    color: var(--gold);
}

.record.muted {
    color: #ccc;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 6px;
}

.stat-value {
    font-family: var(--font-pixel);
    font-size: 20px;
}

.stat-label {
    font-size: 13px;
    opacity: 0.8;
}

.mistakes {
    margin: 20px auto 0;
    max-width: 480px;
    text-align: left;
}

.mistakes ul {
    columns: 2;
    margin: 0;
    padding-left: 22px;
    font-size: 18px;
}

.actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-top: 24px;
}

/* ---------- Boot loader (before Blazor starts) ---------- */
.boot {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding-top: 30vh;
}

.boot-title {
    font-family: var(--font-pixel);
    font-size: 28px;
    color: var(--gold);
    text-shadow: 4px 4px 0 #7a5a00;
}

.boot-bar {
    width: 260px;
    height: 16px;
    background: #222;
    border: 2px solid #555;
}

.boot-fill {
    height: 100%;
    background: var(--green);
    width: var(--blazor-load-percentage, 0%);
    transition: width 0.2s;
}

.boot-text::after {
    content: var(--blazor-load-percentage-text, "Laden…");
    font-family: var(--font-pixel);
    font-size: 11px;
}

#blazor-error-ui {
    background: #ffd93b;
    color: #222;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
    :root {
        --cell: 30px;
    }

    .arena {
        grid-template-columns: 1fr;
    }

    .rules,
    .difficulty {
        grid-template-columns: 1fr;
    }

    .stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .hud {
        font-size: 10px;
        flex-wrap: wrap;
    }

    .mistakes ul {
        columns: 1;
    }
}

/* ---------- Operation picker ---------- */
.operations {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.op-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 14px 6px;
    font-size: 11px;
}

.op-btn .op-symbol {
    font-size: 28px;
}

.table-btn.wide {
    width: auto;
    min-width: 56px;
    padding: 0 12px;
}

@media (max-width: 760px) {
    .operations {
        grid-template-columns: repeat(2, 1fr);
    }
}
