/* Mastermind UI — wood-grain skeuomorphic.
   Layout sizes/colors come from gen/generated.css :root variables. */

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    font-size: var(--font-size-base);
    color: #f8eccb;
}

body {
    background:
        repeating-linear-gradient(
            92deg,
            rgba(0,0,0,0.06) 0px,
            rgba(0,0,0,0.06) 1px,
            transparent 1px,
            transparent 4px
        ),
        repeating-linear-gradient(
            88deg,
            rgba(255,255,255,0.04) 0px,
            rgba(255,255,255,0.04) 2px,
            transparent 2px,
            transparent 11px
        ),
        radial-gradient(ellipse at 30% 20%, #8a5a2b 0%, #6b4220 60%, #4a2c14 100%);
    color: inherit;
}

#root {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-rows: auto 1fr auto auto;
    gap: var(--slot-gap);
    padding: var(--board-padding);
}

/* --- Top bar --- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--slot-gap);
    padding: 8px 12px;
    background: linear-gradient(180deg, #b4884f 0%, #8a5a2b 100%);
    border: 2px solid #3b2110;
    border-radius: 10px;
    box-shadow:
        inset 0 1px 0 rgba(255,255,255,0.4),
        inset 0 -2px 4px rgba(0,0,0,0.3),
        0 4px 8px rgba(0,0,0,0.4);
}
.topbar h1 {
    margin: 0;
    font-size: 1.5em;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.5);
    color: #2c1808;
}
.topbar .controls {
    display: flex;
    gap: 8px;
    align-items: center;
}
.round-counter {
    font-weight: 600;
    color: #2c1808;
    background: rgba(255,235,200,0.7);
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid #3b2110;
}
.icon-btn, .text-btn {
    cursor: pointer;
    background: linear-gradient(180deg, #d2a572 0%, #a87841 100%);
    border: 2px solid #3b2110;
    border-radius: 8px;
    padding: 6px 12px;
    font: inherit;
    font-weight: 700;
    color: #2c1808;
    box-shadow:
        inset 0 1px 0 rgba(255,255,255,0.5),
        0 2px 0 #3b2110;
    transition: transform 0.05s ease;
}
.icon-btn:hover, .text-btn:hover { filter: brightness(1.08); }
.icon-btn:active, .text-btn:active { transform: translateY(2px); box-shadow: inset 0 1px 0 rgba(255,255,255,0.5), 0 0 0 #3b2110; }
.icon-btn { min-width: 36px; min-height: 36px; padding: 6px 10px; font-size: 1.1em; }

/* --- Board --- */
.board {
    overflow: auto;
    background:
        repeating-linear-gradient(
            91deg,
            rgba(0,0,0,0.08) 0px,
            rgba(0,0,0,0.08) 1px,
            transparent 1px,
            transparent 5px
        ),
        linear-gradient(180deg, #7c4f24 0%, #5e3a18 100%);
    border: 3px solid #3b2110;
    border-radius: 12px;
    box-shadow:
        inset 0 4px 12px rgba(0,0,0,0.4),
        inset 0 0 0 1px rgba(255,255,255,0.06);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 16px;
    padding: 8px;
    border-radius: 8px;
    background: rgba(0,0,0,0.18);
    border: 1px solid rgba(0,0,0,0.4);
    box-shadow: inset 0 1px 1px rgba(255,255,255,0.05);
}
.row.is-current {
    background: rgba(255,235,200,0.12);
    border-color: rgba(255,235,200,0.5);
    box-shadow: inset 0 0 0 1px rgba(255,235,200,0.3), 0 0 12px rgba(255,200,100,0.15);
}
.row.is-locked { opacity: 0.95; }

.slots {
    display: flex;
    gap: var(--slot-gap);
    align-items: center;
}
.slot {
    width: calc(var(--peg-radius) * 2);
    height: calc(var(--peg-radius) * 2);
    border-radius: 50%;
    background:
        radial-gradient(circle at 50% 65%, rgba(0,0,0,0.6) 0%, rgba(0,0,0,0.3) 50%, rgba(0,0,0,0.05) 100%),
        #3a2110;
    box-shadow:
        inset 0 3px 6px rgba(0,0,0,0.7),
        inset 0 -1px 0 rgba(255,255,255,0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,235,200,0.4);
    font-size: 1.2em;
    border: none;
    cursor: default;
}
.slot.is-button {
    cursor: pointer;
    transition: transform 0.08s ease;
    /* Prevent text selection on double-click/double-tap, and suppress mobile
       browsers' tap highlight / long-press callout / double-tap zoom. */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.slot.is-button:hover { transform: scale(1.04); }
.slot.is-button:active { transform: scale(0.97); }
.slot[data-color]:not([data-color="-1"]) {
    background:
        radial-gradient(circle at 35% 30%, rgba(255,255,255,0.55) 0%, rgba(255,255,255,0) 30%),
        radial-gradient(circle at 50% 65%, rgba(0,0,0,0.4) 0%, rgba(0,0,0,0) 60%),
        var(--peg-color, #888);
    box-shadow:
        inset 0 -3px 6px rgba(0,0,0,0.4),
        0 2px 3px rgba(0,0,0,0.5);
}
.slot .symbol {
    position: relative;
    color: rgba(255,255,255,0.95);
    text-shadow: 0 0 2px rgba(0,0,0,0.7);
    font-size: 1.4em;
    pointer-events: none;
    display: none;
}
body.show-symbols .slot[data-color]:not([data-color="-1"]) .symbol { display: inline; }

@keyframes shake {
    0%,100% { transform: translateX(0); }
    20%,60% { transform: translateX(-6px); }
    40%,80% { transform: translateX(6px); }
}
.slot.shake { animation: shake 0.35s ease-in-out; }

/* --- Score column --- */
.score {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 80px;
}
.score-pegs {
    display: grid;
    grid-template-columns: repeat(2, 14px);
    grid-auto-rows: 14px;
    gap: 4px;
}
.score-peg {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 1px solid #1a0e05;
    box-shadow: inset 0 1px 1px rgba(255,255,255,0.3);
}
.score-peg.right { background: radial-gradient(circle at 35% 30%, #555 0%, #000 80%); }
.score-peg.wrong { background: radial-gradient(circle at 35% 30%, #fff 0%, #ccc 80%); }
.score-peg.empty { background: rgba(0,0,0,0.25); border-style: dashed; }
.score-label {
    font-size: 0.85em;
    color: #f8eccb;
    opacity: 0.85;
    font-variant-numeric: tabular-nums;
}

/* --- Bottom guess + submit --- */
.guess-bar {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 16px;
    padding: 12px;
    background: linear-gradient(180deg, #a87841 0%, #7c4f24 100%);
    border: 3px solid #3b2110;
    border-radius: 12px;
    box-shadow: inset 0 2px 4px rgba(255,255,255,0.15), 0 4px 8px rgba(0,0,0,0.3);
}
.submit-btn {
    cursor: pointer;
    background: linear-gradient(180deg, #4a9c4e 0%, #2f7234 100%);
    border: 2px solid #1a3d1d;
    border-radius: 8px;
    padding: 12px 22px;
    font: inherit;
    font-weight: 800;
    font-size: 1.1em;
    color: #fff;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.5);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.4), 0 3px 0 #1a3d1d;
}
.submit-btn:hover { filter: brightness(1.1); }
.submit-btn:active { transform: translateY(2px); box-shadow: inset 0 1px 0 rgba(255,255,255,0.4), 0 0 0 #1a3d1d; }

.palette-legend {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding: 8px 12px;
    background: rgba(0,0,0,0.25);
    border-radius: 8px;
    align-items: center;
    justify-content: center;
}
.palette-legend .swatch {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid #3b2110;
    box-shadow: inset 0 -2px 3px rgba(0,0,0,0.35), inset 0 2px 2px rgba(255,255,255,0.4);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    text-shadow: 0 0 2px rgba(0,0,0,0.8);
    font-size: 0.95em;
}
.palette-legend .swatch .symbol { display: none; }
body.show-symbols .palette-legend .swatch .symbol { display: inline; }

.inline-error {
    color: #ffd0d0;
    background: rgba(120, 20, 20, 0.7);
    border: 1px solid #5a0e0e;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.9em;
    margin-top: 6px;
    text-align: center;
}

/* --- Modals --- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}
.modal {
    background: linear-gradient(180deg, #c89b6c 0%, #8a5a2b 100%);
    color: #2c1808;
    border: 3px solid #3b2110;
    border-radius: 12px;
    padding: 20px 24px;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow: auto;
    box-shadow: 0 12px 36px rgba(0,0,0,0.5);
    position: relative;
}
.modal h2 { margin-top: 0; }
.modal .close {
    position: absolute;
    top: 8px;
    right: 12px;
    background: transparent;
    border: none;
    font-size: 1.6em;
    cursor: pointer;
    color: #2c1808;
    line-height: 1;
}
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal label { display: block; margin: 12px 0; font-weight: 600; }
.modal input[type=number], .modal input[type=text] {
    width: 100%;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid #3b2110;
    font: inherit;
    margin-top: 4px;
}
.scoring-example {
    background: rgba(0,0,0,0.1);
    padding: 12px;
    border-radius: 8px;
    margin: 12px 0;
    font-family: monospace;
    line-height: 1.6;
}

/* --- Mobile portrait --- */
@media (max-width: 600px) {
    .row {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .score {
        flex-direction: row;
        gap: 12px;
    }
    .palette-legend {
        overflow-x: auto;
        flex-wrap: nowrap;
        justify-content: flex-start;
    }
    .topbar h1 { font-size: 1.2em; }
    .round-counter { font-size: 0.85em; }
}
