:root {
    --bg: #0d0d14;
    --surface: #161622;
    --card: #1c1c2e;
    --border: #2a2a40;
    --turn-lower: #87ceeb;
    --text: #e0e0ec;
    --text-muted: #e0e0ec;
    --accent: #00c9a7;
    --accent-dim: rgba(0, 201, 167, 0.1);
    --danger: #ff4455;
    --warning: #ffaa00;
    --hit: #ff8800;
    --critical: #ff2244;
    --silence: #00c9a7;
    --ui-scale: 1;
    --tab-height: calc(60px * var(--ui-scale));
}

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

html, body {
    height: 100%;
    height: 100dvh;
    min-height: 100%;
    min-height: 100dvh;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

/* ===== Main Content ===== */

main {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior-y: none;
    -webkit-overflow-scrolling: touch;
    background: var(--bg);
}

.tab-content {
    display: none;
    width: 100%;
    padding: calc(24px * var(--ui-scale)) calc(32px * var(--ui-scale));
    min-height: 100%;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.tab-content.tab-flex.active {
    justify-content: flex-start;
}

/* ===== Tab Bar ===== */

#tab-bar {
    flex-shrink: 0;
    margin-top: auto;
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: calc(3px * var(--ui-scale));
    height: var(--tab-height);
    border: none;
    border-right: 1px solid var(--border);
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s;
}

.tab-btn:last-child {
    border-right: none;
}

@media (orientation: landscape) {
    body {
        flex-direction: row;
    }

    main {
        flex: 1;
        min-width: 0;
        order: 1;
    }

    #tab-bar {
        order: -1;
        margin-top: 0;
        align-self: stretch;
        flex-direction: column;
        width: calc(96px * var(--ui-scale));
        border-top: none;
        border-right: 1px solid var(--border);
        padding-bottom: 0;
        padding-left: env(safe-area-inset-left, 0px);
    }

    .tab-btn {
        flex: 1;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .tab-btn:last-child {
        border-bottom: none;
    }
}

.tab-btn.active {
    color: var(--accent);
}

.tab-icon {
    width: calc(22px * var(--ui-scale));
    height: calc(22px * var(--ui-scale));
}

.tab-label {
    font-size: calc(10px * var(--ui-scale));
    font-weight: 600;
    letter-spacing: calc(0.5px * var(--ui-scale));
    text-transform: uppercase;
}

/* ===== Settings Tab ===== */

.tab-title {
    text-align: center;
    margin-bottom: calc(48px * var(--ui-scale));
    padding-top: calc(24px * var(--ui-scale));
}

.tab-title h1 {
    font-size: calc(38px * var(--ui-scale));
    font-weight: 900;
    letter-spacing: calc(10px * var(--ui-scale));
    color: var(--accent);
    text-shadow: 0 0 calc(40px * var(--ui-scale)) rgba(0, 201, 167, 0.25);
}

.tab-title .subtitle {
    display: block;
    font-size: calc(11px * var(--ui-scale));
    letter-spacing: calc(4px * var(--ui-scale));
    color: var(--text-muted);
    text-transform: uppercase;
    margin-top: calc(6px * var(--ui-scale));
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: calc(12px * var(--ui-scale));
    padding: calc(16px * var(--ui-scale)) calc(18px * var(--ui-scale));
    margin-bottom: calc(12px * var(--ui-scale));
}

.card-label {
    display: block;
    font-size: calc(11px * var(--ui-scale));
    font-weight: 700;
    letter-spacing: calc(2px * var(--ui-scale));
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: calc(8px * var(--ui-scale));
}

.player-selector {
    display: flex;
    gap: calc(8px * var(--ui-scale));
}

.player-btn {
    flex: 1;
    height: calc(44px * var(--ui-scale));
    border: 2px solid var(--border);
    border-radius: calc(10px * var(--ui-scale));
    background: var(--surface);
    color: var(--text-muted);
    font-size: calc(18px * var(--ui-scale));
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.player-btn:not(:disabled):active {
    transform: scale(0.9);
}

.player-btn.selected {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-dim);
}

.setup-hint {
    margin-top: calc(14px * var(--ui-scale));
    padding: 0 calc(16px * var(--ui-scale));
    text-align: left;
    font-size: calc(12px * var(--ui-scale));
    line-height: 1.5;
    color: var(--text-muted);
    white-space: pre-line;
}

.settings-footer {
    margin-top: auto;
    text-align: center;
    font-size: calc(12px * var(--ui-scale));
    color: var(--text-muted);
}

.btn-primary {
    display: block;
    width: 100%;
    height: calc(54px * var(--ui-scale));
    border: none;
    border-radius: calc(12px * var(--ui-scale));
    background: var(--accent);
    color: var(--bg);
    font-size: calc(15px * var(--ui-scale));
    font-weight: 800;
    letter-spacing: calc(3px * var(--ui-scale));
    cursor: pointer;
    transition: transform 0.15s, opacity 0.15s;
}

.btn-primary:not(:disabled):active {
    opacity: 0.85;
}

.btn-primary:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
}

/* ===== Dice Tab ===== */

#dice-area {
    flex: 1;
    display: grid;
    gap: clamp(calc(24px * var(--ui-scale)), 6vh, calc(64px * var(--ui-scale)));
    align-content: center;
    justify-items: center;
    min-height: calc(220px * var(--ui-scale));
    width: 100%;
}

@media (orientation: landscape) {
    #dice-area {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-content: stretch;
        align-items: stretch;
        min-height: 0;
    }

    .die-block {
        position: relative;
        height: 100%;
        min-height: 0;
        overflow: visible;
    }

    .die-stack {
        position: absolute;
        top: calc(50% - (84px * var(--ui-scale)));
        left: 50%;
        transform: translateX(-50%);
    }

    .die-caption {
        line-height: 1;
    }

    .die-hint {
        position: absolute;
        top: calc(50% + (111px * var(--ui-scale)));
        left: 50%;
        transform: translateX(-50%);
        width: 100%;
        margin-top: 0;
        max-height: calc(50% - (120px * var(--ui-scale)));
        overflow-y: auto;
    }
}

@media (orientation: portrait), (max-width: 700px) {
    #tab-dice {
        overflow: hidden;
    }

    #dice-area {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr) clamp(calc(104px * var(--ui-scale)), 16vh, calc(148px * var(--ui-scale))) minmax(0, 1fr);
        gap: 0;
        align-content: stretch;
        min-height: 0;
    }

    #dice-area .die-block {
        display: contents;
    }

    #dice-area .die-block:nth-child(1) .die-stack {
        grid-row: 1;
        align-self: end;
    }

    #dice-area .die-block:nth-child(2) .die-stack {
        grid-row: 3;
        align-self: start;
    }

    #dice-area .die-hint {
        grid-column: 1;
        grid-row: 2;
        align-self: center;
        min-height: 0;
        max-height: 100%;
        overflow-y: auto;
    }
}

.die-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: calc(560px * var(--ui-scale));
    min-width: 0;
}

.die-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    min-width: 0;
}

.die-caption {
    font-size: calc(11px * var(--ui-scale));
    font-weight: 700;
    letter-spacing: calc(2px * var(--ui-scale));
    color: var(--text-muted);
    margin-bottom: calc(8px * var(--ui-scale));
}

.die {
    width: calc(130px * var(--ui-scale));
    height: calc(130px * var(--ui-scale));
    border-radius: calc(20px * var(--ui-scale));
    background: var(--card);
    border: 2px solid var(--border);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.die [id$="-value"] {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(52px * var(--ui-scale));
    font-weight: 900;
    color: var(--text-muted);
    transition: color 0.3s;
    line-height: 1;
}

.die [id$="-value"] svg {
    display: block;
    width: calc(112px * var(--ui-scale));
    height: calc(112px * var(--ui-scale));
}

.die-label {
    margin-top: calc(16px * var(--ui-scale));
    font-size: calc(15px * var(--ui-scale));
    font-weight: 700;
    letter-spacing: calc(3px * var(--ui-scale));
    color: var(--text-muted);
    min-height: calc(22px * var(--ui-scale));
    text-align: center;
}

.die-hint {
    margin-top: calc(8px * var(--ui-scale));
    font-size: calc(13px * var(--ui-scale));
    font-weight: 500;
    color: var(--text-muted);
    min-height: calc(20px * var(--ui-scale));
    text-align: center;
    max-width: 100%;
    white-space: pre-line;
}

/* Die result colors — border and label match value color */
.die.result-number { border-color: #ccaa00; }
.die.result-number [id$="-value"] { color: #ccaa00; }
.die.result-number + .die-label { color: #ccaa00; }

.die.result-silence { border-color: var(--silence); box-shadow: 0 0 calc(24px * var(--ui-scale)) rgba(0, 201, 167, 0.25); }
.die.result-silence [id$="-value"] { color: var(--silence); }
.die.result-silence + .die-label { color: var(--silence); }

.die.result-danger { border-color: var(--danger); box-shadow: 0 0 calc(30px * var(--ui-scale)) rgba(255, 34, 68, 0.4); }
.die.result-danger [id$="-value"] { color: var(--danger); }
.die.result-danger + .die-label { color: var(--danger); }

.die.result-miss { border-color: var(--text-muted); }
.die.result-miss [id$="-value"] { color: var(--text-muted); }
.die.result-miss + .die-label { color: var(--text-muted); }

.die.result-hit { border-color: var(--danger); box-shadow: 0 0 calc(24px * var(--ui-scale)) rgba(255, 68, 85, 0.3); }
.die.result-hit [id$="-value"] { color: var(--danger); }
.die.result-hit + .die-label { color: var(--danger); }

.die.result-double { border-color: var(--critical); box-shadow: 0 0 calc(24px * var(--ui-scale)) rgba(255, 34, 68, 0.4); }
.die.result-double [id$="-value"] { color: var(--critical); }
.die.result-double + .die-label { color: var(--critical); }

.die.result-adult { border-color: var(--hit); }
.die.result-adult [id$="-value"] { color: var(--hit); }
.die.result-adult [id$="-value"] svg { transform: translateY(calc(4px * var(--ui-scale))); }
.die.result-adult + .die-label { color: var(--hit); }

.die.result-creeper { border-color: #ccaa00; }
.die.result-creeper [id$="-value"] { color: #ccaa00; }
.die.result-creeper [id$="-value"] svg { transform: translateY(calc(4px * var(--ui-scale))); }
.die.result-creeper + .die-label { color: #ccaa00; }

.die.rolling {
    animation: shake 0.5s ease infinite;
    border-color: var(--text);
    box-shadow: 0 0 calc(20px * var(--ui-scale)) rgba(0, 201, 167, 0.2);
}

.die.rolling [id$="-value"] {
    color: var(--text);
}

/* ===== Objectives Tab ===== */

.placeholder {
    text-align: center;
    color: var(--text-muted);
    padding: calc(48px * var(--ui-scale)) calc(16px * var(--ui-scale));
    font-size: calc(14px * var(--ui-scale));
    line-height: 1.6;
}

.objective-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: calc(12px * var(--ui-scale));
    padding: calc(16px * var(--ui-scale)) calc(18px * var(--ui-scale));
    margin-bottom: calc(12px * var(--ui-scale));
    animation: fadeSlideIn 0.3s ease both;
    display: grid;
    grid-template-rows: 1fr auto;
}

.objective-card:nth-child(2) { animation-delay: 0.05s; }
.objective-card:nth-child(3) { animation-delay: 0.1s; }
.objective-card:nth-child(4) { animation-delay: 0.15s; }
.objective-card:nth-child(5) { animation-delay: 0.2s; }
.objective-card:nth-child(6) { animation-delay: 0.25s; }

.objective-name {
    font-size: calc(17px * var(--ui-scale));
    font-weight: 700;
    margin-bottom: calc(4px * var(--ui-scale));
    color: var(--accent);
}

.objective-copy {
    display: block;
}

.objective-desc {
    font-size: calc(13px * var(--ui-scale));
    color: var(--text-muted);
    line-height: 1.5;
}

.objectives-hint {
    margin-top: calc(14px * var(--ui-scale));
    padding: 0 calc(16px * var(--ui-scale));
    font-size: calc(12px * var(--ui-scale));
    color: var(--text-muted);
    line-height: 1.5;
}

.objective-flavor {
    font-size: calc(12px * var(--ui-scale));
    font-style: italic;
    color: var(--text-muted);
    margin-top: calc(8px * var(--ui-scale));
    line-height: 1.4;
}

@media (orientation: landscape) {
    #objectives-list.objectives-list--multi {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: calc(12px * var(--ui-scale));
    }
    #objectives-list.objectives-list--multi .objective-card {
        margin-bottom: 0;
    }
}

/* ===== Weakness / Research Tab ===== */

#research-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: calc(10px * var(--ui-scale));
}

@media (orientation: landscape) {
    #research-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.research-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: calc(12px * var(--ui-scale));
    padding: calc(16px * var(--ui-scale)) calc(18px * var(--ui-scale));
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.3s, background 0.3s;
    min-height: calc(150px * var(--ui-scale));
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: calc(6px * var(--ui-scale));
}

.research-card:not(.revealed):active {
    transform: scale(0.9);
}

.research-card.revealed {
    border-color: var(--accent);
    background: rgba(0, 201, 167, 0.06);
    cursor: default;
    animation: revealPop 0.4s ease;
    justify-content: flex-start;
    padding-top: calc(20px * var(--ui-scale));
    text-align: left;
    align-items: flex-start;
    padding: calc(16px * var(--ui-scale)) calc(18px * var(--ui-scale));
}

.research-card.revealed .research-name,
.research-card.revealed .research-status {
    align-self: center;
    text-align: center;
}

.research-name {
    font-size: calc(12px * var(--ui-scale));
    font-weight: 700;
    letter-spacing: calc(1px * var(--ui-scale));
    text-transform: uppercase;
    color: var(--accent);
}

.research-unknown {
    font-size: calc(38px * var(--ui-scale));
    font-weight: 900;
    color: var(--text-muted);
    align-self: center;
}

.research-hint {
    font-size: calc(10px * var(--ui-scale));
    font-weight: 700;
    letter-spacing: calc(2px * var(--ui-scale));
    color: var(--text-muted);
}

.research-status {
    font-size: calc(10px * var(--ui-scale));
    font-weight: 700;
    letter-spacing: calc(2px * var(--ui-scale));
    color: var(--text-muted);
    margin: calc(2px * var(--ui-scale)) 0;
}

.weakness-name {
    font-size: calc(17px * var(--ui-scale));
    font-weight: 700;
    color: var(--accent);
    line-height: 1.3;
}

.weakness-effect {
    font-size: calc(13px * var(--ui-scale));
    color: var(--text-muted);
    line-height: 1.5;
}

/* ===== Intruder Bag Tab ===== */

#bag-result-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(120px * var(--ui-scale));
}

#bag-drawn {
    font-size: calc(48px * var(--ui-scale));
    font-weight: 900;
    color: var(--text-muted);
    transition: color 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#bag-drawn.bag-drawn-unknown {
    animation: bagUnknownFadeIn 2s ease forwards;
}

@keyframes bagUnknownFadeIn {
    from { opacity: 0; color: #000; }
    to { opacity: 1; color: var(--text-muted); }
}

#bag-drawn svg {
    display: block;
    width: calc(80px * var(--ui-scale));
    height: calc(80px * var(--ui-scale));
}

#bag-drawn.type-blank { color: var(--text-muted); }
#bag-drawn.type-larva { color: #88cc44; }
#bag-drawn.type-creeper { color: #ccaa00; }
#bag-drawn.type-adult { color: var(--hit); }
#bag-drawn.type-breeder { color: var(--danger); }
#bag-drawn.type-queen { color: var(--critical); }

#bag-drawn.bag-drawn-timer-end-wrap .bag-drawn-timer-end {
    color: var(--critical);
}

#bag-drawn-name.timer-end {
    color: var(--critical);
}

#bag-drawn-label {
    margin-bottom: calc(8px * var(--ui-scale));
    font-size: calc(11px * var(--ui-scale));
    font-weight: 700;
    letter-spacing: calc(3px * var(--ui-scale));
    color: var(--text-muted);
    min-height: calc(18px * var(--ui-scale));
    text-align: center;
}

#bag-drawn-name {
    margin-top: calc(10px * var(--ui-scale));
    font-size: calc(18px * var(--ui-scale));
    font-weight: 800;
    letter-spacing: calc(3px * var(--ui-scale));
    min-height: calc(26px * var(--ui-scale));
    text-align: center;
    transition: color 0.3s;
}

#bag-drawn-name.type-blank { color: var(--text-muted); }
#bag-drawn-name.type-larva { color: #88cc44; }
#bag-drawn-name.type-creeper { color: #ccaa00; }
#bag-drawn-name.type-adult { color: var(--hit); }
#bag-drawn-name.type-breeder { color: var(--danger); }
#bag-drawn-name.type-queen { color: var(--critical); }

#bag-drawn-effect {
    margin-top: calc(4px * var(--ui-scale));
    font-size: calc(13px * var(--ui-scale));
    font-weight: 500;
    color: var(--text-muted);
    min-height: calc(20px * var(--ui-scale));
    text-align: center;
    white-space: pre-line;
}

#bag-contents {
    margin-top: calc(20px * var(--ui-scale));
    margin-bottom: calc(16px * var(--ui-scale));
}

.bag-token-row {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(8px * var(--ui-scale)) calc(10px * var(--ui-scale));
    margin: 0 calc(-10px * var(--ui-scale));
    border-radius: calc(10px * var(--ui-scale));
    isolation: isolate;
}

.bag-token-row::before {
    content: '';
    position: absolute;
    inset: 0;
    border: 2px solid transparent;
    border-radius: inherit;
    background: transparent;
    pointer-events: none;
    z-index: 0;
}

.bag-token-row::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 1px;
    background: var(--border);
    pointer-events: none;
    z-index: 0;
}

.bag-token-row:last-child {
    border-bottom: none;
}

.bag-token-row:last-child::after {
    display: none;
}

.bag-token-row-highlight {
    animation: none;
}

.bag-token-row-highlight::before {
    border-color: var(--accent);
    background-color: var(--accent-dim);
    animation: bagRowHighlightFade 0.5s ease forwards;
}

.bag-token-row-highlight .bag-token-count {
    animation: bagTokenCountHighlightFade 0.5s ease forwards;
}

.bag-token-label,
.bag-token-controls {
    position: relative;
    z-index: 1;
}

.bag-token-row-highlight .bag-btn {
    animation: bagButtonHighlightFade 0.5s ease forwards;
}

.bag-token-label {
    display: flex;
    align-items: center;
    gap: calc(8px * var(--ui-scale));
}

.bag-token-icon {
    width: calc(22px * var(--ui-scale));
    height: calc(22px * var(--ui-scale));
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bag-token-icon svg {
    width: calc(22px * var(--ui-scale));
    height: calc(22px * var(--ui-scale));
    display: block;
}

.bag-token-name {
    font-size: calc(14px * var(--ui-scale));
    font-weight: 600;
}

.bag-token-controls {
    display: flex;
    align-items: center;
    gap: calc(12px * var(--ui-scale));
}

.bag-token-count {
    font-size: calc(16px * var(--ui-scale));
    font-weight: 700;
    min-width: calc(24px * var(--ui-scale));
    text-align: center;
}

.bag-btn {
    width: calc(36px * var(--ui-scale));
    height: calc(36px * var(--ui-scale));
    border-radius: calc(8px * var(--ui-scale));
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: calc(18px * var(--ui-scale));
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.bag-btn:active {
    transform: scale(0.9);
}

.bag-total {
    text-align: right;
    font-size: calc(12px * var(--ui-scale));
    color: var(--text-muted);
    padding-top: calc(8px * var(--ui-scale));
}

.turn-tracker {
    display: flex;
    align-items: center;
    gap: calc(12px * var(--ui-scale));
    margin-top: calc(20px * var(--ui-scale));
    padding: calc(12px * var(--ui-scale)) calc(16px * var(--ui-scale));
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: calc(12px * var(--ui-scale));
}

.turn-tracker-icon {
    flex-shrink: 0;
    width: calc(24px * var(--ui-scale));
    height: calc(24px * var(--ui-scale));
    color: var(--text-muted);
}

.turn-tracker-icon-end {
    color: var(--critical);
}

.turn-segments {
    flex: 1;
    display: flex;
    gap: calc(2px * var(--ui-scale));
    min-width: 0;
    min-height: calc(28px * var(--ui-scale));
}

.turn-segment {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: calc(4px * var(--ui-scale));
    font-size: calc(11px * var(--ui-scale));
    font-weight: 700;
    color: var(--text-muted);
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.turn-segment.lower-half {
    border-color: var(--turn-lower);
}

.turn-segment.current {
    background: rgba(0, 201, 167, 0.4);
    border-color: rgba(0, 201, 167, 0.4);
    color: var(--text-muted);
}

.turn-segments.hide-segment-numbers .turn-segment {
    color: transparent;
}

.turn-segment-divider {
    flex: 0 0 calc(14px * var(--ui-scale));
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--turn-lower);
}

.turn-segment-divider-icon {
    width: calc(14px * var(--ui-scale));
    height: calc(21px * var(--ui-scale));
    display: block;
}

.bag-token-label.type-blank { color: var(--text-muted); }
.bag-token-label.type-larva { color: #88cc44; }
.bag-token-label.type-creeper { color: #ccaa00; }
.bag-token-label.type-adult { color: var(--hit); }
.bag-token-label.type-breeder { color: var(--danger); }
.bag-token-label.type-queen { color: var(--critical); }

.btn-secondary {
    display: block;
    width: 100%;
    height: calc(44px * var(--ui-scale));
    border: 1px solid var(--border);
    border-radius: calc(12px * var(--ui-scale));
    background: var(--surface);
    color: var(--text-muted);
    font-size: calc(12px * var(--ui-scale));
    font-weight: 700;
    letter-spacing: calc(2px * var(--ui-scale));
    cursor: pointer;
    transition: transform 0.15s, opacity 0.15s;
}

.btn-secondary:not(:disabled):active {
    opacity: 0.85;
}

button:not(.tab-btn):not(:disabled):active {
    transform: scale(0.9);
}

.bag-buttons {
    display: flex;
    gap: calc(10px * var(--ui-scale));
}

.bag-buttons .btn-primary {
    flex: 1;
}

@media (orientation: portrait) {
    #tab-bag #bag-contents {
        margin-bottom: calc(8px * var(--ui-scale));
    }
    #tab-bag .turn-tracker {
        margin-top: calc(8px * var(--ui-scale));
    }
}

@media (max-width: 600px) {
    .turn-tracker {
        gap: calc(8px * var(--ui-scale));
        padding: calc(10px * var(--ui-scale)) calc(12px * var(--ui-scale));
    }

    .turn-tracker-icon {
        width: calc(20px * var(--ui-scale));
        height: calc(20px * var(--ui-scale));
    }

    .turn-segments {
        gap: max(1px, calc(1px * var(--ui-scale)));
        min-height: calc(24px * var(--ui-scale));
    }

    .turn-segment {
        border-radius: calc(3px * var(--ui-scale));
        font-size: calc(9px * var(--ui-scale));
    }

    .turn-segment-divider {
        flex-basis: calc(12px * var(--ui-scale));
    }

    .turn-segment-divider-icon {
        width: calc(12px * var(--ui-scale));
        height: calc(18px * var(--ui-scale));
    }
}

@media (orientation: landscape) {
    #tab-bag.active {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr auto auto;
        gap: 0 calc(24px * var(--ui-scale));
        min-height: 100%;
    }
    #tab-bag #bag-result-area {
        grid-column: 1;
        grid-row: 1;
    }
    #tab-bag .bag-buttons {
        grid-column: 1;
        grid-row: 2;
    }
    #tab-bag #bag-contents {
        grid-column: 2;
        grid-row: 1 / 3;
        margin-top: 0;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
    #tab-bag .turn-tracker {
        grid-column: 1 / -1;
        grid-row: 3;
        margin-top: calc(16px * var(--ui-scale));
    }
}

/* ===== Toast ===== */

#toast {
    position: fixed;
    top: calc(20px * var(--ui-scale));
    left: 50%;
    transform: translateX(-50%) translateY(calc(-80px * var(--ui-scale)));
    background: var(--accent);
    color: var(--bg);
    padding: calc(10px * var(--ui-scale)) calc(24px * var(--ui-scale));
    border-radius: calc(8px * var(--ui-scale));
    font-size: calc(14px * var(--ui-scale));
    font-weight: 700;
    letter-spacing: calc(0.5px * var(--ui-scale));
    z-index: 200;
    transition: transform 0.3s ease;
    pointer-events: none;
    white-space: nowrap;
}

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

/* ===== Animations ===== */

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(calc(12px * var(--ui-scale)));
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes shake {
    0%, 100% { transform: translate(0); }
    10% { transform: translate(calc(-4px * var(--ui-scale)), calc(-3px * var(--ui-scale))); }
    20% { transform: translate(calc(4px * var(--ui-scale)), calc(-3px * var(--ui-scale))); }
    30% { transform: translate(calc(-4px * var(--ui-scale)), calc(3px * var(--ui-scale))); }
    40% { transform: translate(calc(4px * var(--ui-scale)), calc(3px * var(--ui-scale))); }
    50% { transform: translate(calc(-3px * var(--ui-scale)), calc(-4px * var(--ui-scale))); }
    60% { transform: translate(calc(3px * var(--ui-scale)), calc(-4px * var(--ui-scale))); }
    70% { transform: translate(calc(-3px * var(--ui-scale)), calc(4px * var(--ui-scale))); }
    80% { transform: translate(calc(3px * var(--ui-scale)), calc(4px * var(--ui-scale))); }
    90% { transform: translate(calc(-4px * var(--ui-scale)), calc(-3px * var(--ui-scale))); }
}

@keyframes revealPop {
    0% { transform: scale(0.85); opacity: 0; }
    60% { transform: scale(1.04); }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes bagRowHighlightFade {
    from {
        border-color: var(--accent);
        background-color: var(--accent-dim);
    }
    to {
        border-color: transparent;
        background-color: transparent;
    }
}

@keyframes bagTokenCountHighlightFade {
    from {
        color: var(--accent);
    }
    to {
        color: var(--text);
    }
}

@keyframes bagButtonHighlightFade {
    from {
        border-color: var(--accent);
        color: var(--accent);
        background: var(--accent-dim);
    }
    to {
        border-color: var(--border);
        color: var(--text);
        background: var(--surface);
    }
}
