/* Tower of Self-reference — balanced layout */

.selfref-page {
    min-height: 100vh;
    background:
        radial-gradient(ellipse 70% 45% at 15% 0%, rgba(45, 120, 173, 0.16), transparent 55%),
        radial-gradient(ellipse 50% 35% at 90% 8%, rgba(212, 160, 23, 0.1), transparent 50%),
        linear-gradient(180deg, #f4f7fb 0%, #e8eef5 100%);
}

.selfref-shell {
    max-width: 1120px;
    margin: 72px auto 48px;
    padding: 28px 28px 32px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 4px 24px rgba(26, 74, 110, 0.08);
    display: flex;
    flex-direction: column;
    gap: 22px;
}

/* —— Brand —— */
.selfref-brand {
    text-align: center;
}

.selfref-brand .brand-mark {
    font-family: 'TeX Gyre Pagella', Georgia, serif;
    font-size: 2.15em;
    color: #1a4a6e;
    letter-spacing: 0.02em;
    margin: 0;
    line-height: 1.15;
}

.selfref-brand .brand-sub {
    margin: 6px 0 0;
    color: #5a7a94;
    font-size: 0.9em;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
}

.formula-banner {
    margin: 16px auto 0;
    max-width: 920px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: #1a2332;
    color: #e8f0ff;
    border-radius: 10px;
    font-family: ui-monospace, Menlo, monospace;
    font-size: 12px;
    line-height: 1.45;
    text-align: left;
}

.formula-banner .f-label {
    flex: 0 0 auto;
    color: #d4a017;
    font-size: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    opacity: 0.95;
}

.formula-banner .f-eq {
    flex: 1 1 auto;
    overflow-x: auto;
    white-space: nowrap;
}

.help-chip {
    flex: 0 0 auto;
    width: 32px !important;
    height: 32px;
    margin: 0 !important;
    padding: 0 !important;
    border: none;
    border-radius: 50% !important;
    background: rgba(255, 255, 255, 0.12) !important;
    color: #e8f0ff !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.help-chip:hover {
    background: rgba(255, 255, 255, 0.22) !important;
    transform: none !important;
}

/* —— Stage (canvas) —— */
.stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 0 4px;
}

#selfrefCanvas {
    border: 2px solid #2d78ad;
    border-radius: 10px;
    background: #0b1220;
    cursor: crosshair;
    image-rendering: pixelated;
    width: 100%;
    max-width: 1060px;
    height: auto;
    aspect-ratio: 106 / 17;
    box-shadow: 0 8px 28px rgba(26, 74, 110, 0.14);
    transition: box-shadow 0.35s ease;
}

#selfrefCanvas.flash-ok {
    box-shadow: 0 0 0 3px rgba(72, 187, 120, 0.7), 0 8px 28px rgba(26, 74, 110, 0.14);
}

#selfrefCanvas.flash-bad {
    box-shadow: 0 0 0 3px rgba(229, 62, 62, 0.65), 0 8px 28px rgba(26, 74, 110, 0.14);
}

.canvas-hint {
    margin-top: 10px;
    color: #718096;
    font-size: 13px;
    text-align: center;
}

.portrait-hint {
    margin: 12px auto 0;
    max-width: 820px;
    width: 100%;
    padding: 12px 14px;
    background: #fff8e6;
    border: 1px solid #e6d5a8;
    border-radius: 8px;
    color: #5a4a28;
    font-size: 13px;
    line-height: 1.55;
    text-align: left;
}

.portrait-hint code {
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 12px;
}

.ghost-legend {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-top: 8px;
    font-size: 12px;
    color: #5a7a94;
}

.ghost-legend span::before {
    content: '';
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 5px;
    border-radius: 2px;
    vertical-align: -1px;
}

.ghost-legend .lg-you::before { background: #5eead4; }
.ghost-legend .lg-target::before { background: rgba(212, 160, 23, 0.55); }
.ghost-legend .lg-match::before { background: #68d391; }

/* —— Control deck —— */
.control-deck {
    display: grid;
    grid-template-columns: 1.15fr 0.85fr 1.2fr;
    gap: 16px;
    align-items: start;
}

.deck-col {
    background: #f7f9fc;
    border: 1px solid #e4ebf2;
    border-radius: 10px;
    padding: 14px;
    min-height: 100%;
}

.deck-col button {
    background-color: #2d78ad;
    border: none;
    color: white;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.deck-col button:hover {
    background-color: #236391;
}

.deck-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #7a92a8;
    margin-bottom: 10px;
}

.panel-blurb {
    font-size: 13px;
    color: #5a6a7a;
    margin: 0 0 10px;
    line-height: 1.45;
}

.mode-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
}

.mode-tabs button {
    flex: 1;
    width: auto !important;
    margin: 0 !important;
    padding: 8px 6px !important;
    font-size: 13px !important;
    background: #fff !important;
    color: #2d78ad !important;
    border: 1px solid #b7d0e3 !important;
    border-radius: 6px !important;
}

.mode-tabs button.active {
    background: #2d78ad !important;
    color: #fff !important;
    border-color: #2d78ad !important;
}

.mode-tabs button:hover {
    transform: none !important;
}

.panel { display: none; }
.panel.active { display: block; }

.tool-row {
    display: flex;
    gap: 6px;
    margin: 0 0 10px;
}

.tool-row button {
    flex: 1;
    width: auto !important;
    margin: 0 !important;
}

.paint-tools button.active-tool {
    background: #1a4a6e !important;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.3);
}

.btn-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.btn-grid.twin {
    margin-top: 4px;
}

.btn-grid button,
.deck-col > button,
.panel button {
    width: 100% !important;
    margin: 0 !important;
    padding: 9px 8px !important;
    font-size: 13px !important;
}

.btn-grid button:hover,
.panel button:hover,
.tool-row button:hover {
    transform: translateY(-1px) !important;
}

.k-box {
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
}

.k-box textarea {
    width: 100%;
    min-height: 118px;
    max-height: 200px;
    resize: vertical;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    font-size: 11px;
    line-height: 1.4;
    border: 1px solid #ced4da;
    border-radius: 6px;
    padding: 10px;
    word-break: break-all;
    background: #fff;
}

.k-meta {
    margin-top: 8px;
    font-size: 12px;
    color: #666;
    line-height: 1.4;
    min-height: 1.4em;
}

.level-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0 0 10px;
    max-height: 220px;
    overflow-y: auto;
    padding-right: 2px;
}

.level-btn {
    text-align: left !important;
    background: #fff !important;
    color: #2d3748 !important;
    border: 1px solid #e2e8f0 !important;
    padding: 8px 10px !important;
}

.level-btn:hover {
    border-color: #2d78ad !important;
    transform: none !important;
}

.level-btn .lv-title {
    display: block;
    font-weight: 600;
    color: #1a4a6e;
    font-size: 13px;
}

.level-btn .lv-desc {
    display: block;
    font-size: 11px;
    color: #718096;
    margin-top: 2px;
}

.level-btn.cleared {
    border-color: #68d391 !important;
    background: #f0fff4 !important;
}

.challenge-hud {
    margin: 10px 0 0;
    padding: 10px;
    background: #fff;
    border-radius: 6px;
    border: 1px solid #e9ecef;
    font-size: 12px;
    color: #4a5568;
}

.challenge-hud .score-line {
    margin-top: 6px;
    font-family: ui-monospace, Menlo, monospace;
    color: #2d78ad;
    font-weight: 600;
}

.toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #1a4a6e;
    color: #fff;
    padding: 10px 18px;
    border-radius: 8px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 1000;
    font-size: 14px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Override game.css sidebar layout leftovers */
.selfref-page .game-container {
    display: none;
}

.selfref-page .game-controls button {
    /* re-assert compact sizing inside deck */
}

@media (max-width: 960px) {
    .selfref-shell {
        margin: 64px 12px 32px;
        padding: 20px 16px 24px;
    }

    .control-deck {
        grid-template-columns: 1fr 1fr;
    }

    .deck-k {
        grid-column: 1 / -1;
    }

    .formula-banner {
        flex-wrap: wrap;
    }

    .formula-banner .f-eq {
        white-space: normal;
        font-size: 11px;
    }
}

@media (max-width: 640px) {
    .selfref-brand .brand-mark {
        font-size: 1.7em;
    }

    .control-deck {
        grid-template-columns: 1fr;
    }

    .deck-k {
        grid-column: auto;
    }

    .back-button {
        top: 12px;
        left: 12px;
        padding: 8px 12px;
        font-size: 14px;
    }
}
