/* Lalien Companion — Dark Mediterranean Theme */

:root {
    --bg-deep: #020A0A;
    --bg-panel: #0A1929;
    --bg-card: #0F2233;
    --gold: #D4A534;
    --gold-dim: #8B6914;
    --cyan: #3ECFCF;
    --cyan-dim: #1A7A7A;
    --text: #E0E0E0;
    --text-dim: #7A8A9A;
    --danger: #C44040;
    --success: #40C470;
    --mood-happy: #3ECFCF;
    --mood-neutral: #D4A534;
    --mood-sad: #6A7ABA;
    --mood-scared: #C44040;
    --need-kora: #E07030;
    --need-moko: #6A5AAA;
    --need-miska: #40C4C4;
    --need-nashi: #E0C040;
    --need-health: #C04040;
    --need-cognition: #40A0E0;
    --need-affection: #E060A0;
    --need-curiosity: #60E060;
    --need-cosmic: #A060E0;
    --need-security: #80A0B0;
    --font-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-alien: 'Courier New', Courier, monospace;
    --radius: 8px;
    --transition: 0.3s ease;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-main);
    background: var(--bg-deep);
    color: var(--text);
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

/* ---- Status Bar ---- */
#status-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 52px;
    background: linear-gradient(180deg, rgba(5,15,28,0.97) 0%, rgba(10,25,41,0.92) 100%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    z-index: 100;
    border-bottom: 1px solid rgba(62,207,207,0.25);
    box-shadow: 0 2px 12px rgba(0,0,0,0.6), 0 1px 0 rgba(62,207,207,0.1);
    backdrop-filter: blur(10px);
}

#status-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

#status-name {
    font-weight: 700;
    color: var(--gold);
    font-size: 14px;
}

.status-tag {
    font-size: 11px;
    color: var(--cyan);
    background: rgba(62,207,207,0.1);
    padding: 1px 6px;
    border-radius: 4px;
}

#status-needs-dots.needs-chips {
    display: flex;
    gap: 4px;
    align-items: center;
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 0 4px;
    justify-content: center;
}
#status-needs-dots.needs-chips::-webkit-scrollbar { display: none; }

.need-chip {
    position: relative;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: rgba(15, 34, 51, 0.8);
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.15s ease;
}
.need-chip:active { transform: scale(0.88); }
.need-chip-icon {
    position: relative;
    z-index: 1;
    font-size: 17px;
    line-height: 28px;
    display: block;
    filter: saturate(0.8);
}
.need-chip-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: conic-gradient(var(--need-color) var(--level, 100%), rgba(255,255,255,0.06) 0);
    mask: radial-gradient(circle, transparent 11px, black 11px);
    -webkit-mask: radial-gradient(circle, transparent 11px, black 11px);
    opacity: 0.9;
    transition: opacity 0.3s;
}
.need-chip.ok .need-chip-ring      { opacity: 0.45; }
.need-chip.warn .need-chip-ring    { opacity: 0.75; }
.need-chip.bad .need-chip-ring     { opacity: 1.00; }
.need-chip.critical                { animation: chipCritPulse 0.9s infinite; }
.need-chip.critical .need-chip-icon{ filter: drop-shadow(0 0 4px var(--need-color)); }
@keyframes chipCritPulse {
    0%,100% { box-shadow: 0 0 0 0 rgba(196,64,64,0); }
    50%     { box-shadow: 0 0 0 4px rgba(196,64,64,0.35); }
}

#status-right {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-dim);
    flex-shrink: 0;
}

#btn-needs-expand, .btn-status-icon {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    position: relative;
    min-width: 32px;
    min-height: 32px;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.2s, transform 0.15s;
}
#btn-status-settings {
    background: rgba(212, 165, 52, 0.18);
    border: 1.5px solid rgba(212, 165, 52, 0.75);
    border-radius: 8px;
    color: #FFE899;
    font-size: 22px;
    min-width: 40px;
    min-height: 40px;
    padding: 4px 10px;
    box-shadow: 0 0 8px rgba(212, 165, 52, 0.35),
                inset 0 0 6px rgba(255, 232, 153, 0.12);
    animation: settings-pulse 2.6s ease-in-out infinite;
}
#btn-status-settings:hover {
    background: rgba(212, 165, 52, 0.32);
    color: #FFF4B4;
    box-shadow: 0 0 14px rgba(212, 165, 52, 0.6),
                inset 0 0 8px rgba(255, 232, 153, 0.25);
}
@keyframes settings-pulse {
    0%, 100% { box-shadow: 0 0 8px rgba(212,165,52,0.35), inset 0 0 6px rgba(255,232,153,0.12); }
    50%      { box-shadow: 0 0 14px rgba(212,165,52,0.65), inset 0 0 10px rgba(255,232,153,0.25); }
}
.btn-status-icon:active { transform: rotate(20deg) scale(0.9); color: var(--gold); }

/* Bottom action bar is now unified into the status bar chips — hide it.
   Kept in DOM as a legacy drag-to-pet source (still works). */
#action-bar { display: none !important; }

/* ---- Manual (pixel-art themed help overlay) ---- */
.manual-container {
    width: 100%; height: 100%;
    display: flex; flex-direction: column;
    background: linear-gradient(180deg, #0A1828 0%, #030A14 100%);
    color: #EAFBFB;
}
.manual-header {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 16px; border-bottom: 2px solid #3ECFCF;
    background: rgba(16,48,64,0.85);
}
.manual-header h2 {
    margin: 0; color: #FFE899; font-family: 'Courier New', monospace;
    font-size: 18px; letter-spacing: 1.5px; text-shadow: 1px 1px 0 #000;
}
.manual-body {
    flex: 1; overflow-y: auto;
    padding: 18px 18px 80px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.55;
}
.manual-body section {
    background: rgba(16,48,64,0.6);
    border: 2px solid #3ECFCF;
    padding: 14px 16px;
    margin-bottom: 16px;
    box-shadow:
        inset 2px 2px 0 0 rgba(255,255,255,0.08),
        inset -2px -2px 0 0 rgba(0,0,0,0.35),
        0 3px 0 0 rgba(0,0,0,0.4);
}
.manual-body h3 {
    margin: 0 0 10px;
    color: #FFE899;
    font-size: 15px;
    letter-spacing: 1px;
    text-shadow: 1px 1px 0 #000;
}
.manual-body h4 {
    margin: 0 0 4px;
    color: #3ECFCF;
    font-size: 13px;
    letter-spacing: 1px;
}
.manual-body ul { padding-left: 20px; margin: 8px 0; }
.manual-body li { margin-bottom: 6px; }
.manual-body p { margin: 6px 0; }
.manual-body b { color: #FFE899; }
.manual-note {
    font-size: 12px;
    color: #A0C8C8;
    font-style: italic;
    border-left: 3px solid #D4A534;
    padding-left: 10px;
}
.manual-stages {
    display: grid; grid-template-columns: 1fr; gap: 10px;
}
.manual-stage {
    display: flex; align-items: center; gap: 12px;
    background: rgba(10,25,41,0.6);
    border: 1px solid rgba(62,207,207,0.35);
    padding: 8px;
}
.manual-stage img {
    width: 56px; height: 56px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    border: 1px solid #3ECFCF;
    background: #051220;
}
.manual-stage h4 { margin: 0; }
.manual-stage p { font-size: 12px; margin: 2px 0 0; color: #C0DADA; }
.manual-needs-grid {
    display: grid; grid-template-columns: 1fr; gap: 6px;
}
.manual-need {
    display: flex; gap: 10px; padding: 6px 8px;
    background: rgba(10,25,41,0.6);
    border-left: 3px solid #3ECFCF;
}
.manual-need-icon { font-size: 22px; }
.manual-need strong { color: #FFE899; }
.manual-need span { font-size: 12px; color: #B0C8C8; }

@media (min-width: 600px) {
    .manual-stages { grid-template-columns: 1fr 1fr; }
    .manual-needs-grid { grid-template-columns: 1fr 1fr; }
}

/* ---- Inline chat bar (above hotbar, always on main screen) ---- */
#chat-bar {
    position: fixed;
    bottom: 74px;    /* sits above the hotbar */
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 4px;
    padding: 4px 6px;
    background: linear-gradient(180deg, rgba(10,25,41,0.92) 0%, rgba(3,10,18,0.96) 100%);
    border: 2px solid #3ECFCF;
    border-radius: 2px;
    z-index: 106;
    width: min(92vw, 500px);
    box-shadow:
        0 3px 0 0 rgba(0,0,0,0.4),
        inset 2px 2px 0 0 rgba(255,255,255,0.08),
        inset -2px -2px 0 0 rgba(0,0,0,0.3);
}
#chat-input {
    flex: 1;
    background: rgba(15,34,51,0.9);
    border: 1px solid rgba(62,207,207,0.3);
    border-radius: 2px;
    color: #EAFBFB;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    padding: 8px 10px;
    outline: none;
    min-height: 36px;
}
#chat-input::placeholder { color: #4A6A7A; }
#chat-input:focus { border-color: #3ECFCF; box-shadow: 0 0 6px rgba(62,207,207,0.3); }
.chat-btn {
    width: 40px; height: 40px;
    background: linear-gradient(180deg, #1a3040 0%, #0a1a24 100%);
    border: 2px solid #D4A534;
    border-radius: 2px;
    font-size: 18px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    padding: 0;
    transition: transform 0.1s;
    box-shadow: inset 2px 2px 0 0 rgba(255,255,255,0.12), inset -2px -2px 0 0 rgba(0,0,0,0.35);
}
.chat-btn:active { transform: translateY(1px); }
#chat-mic.recording { border-color: #E05050; animation: pulse 0.8s infinite; }

@media (max-width: 480px) {
    #chat-bar { bottom: 66px; width: 96vw; padding: 3px 4px; }
    #chat-input { font-size: 13px; padding: 6px 8px; min-height: 32px; }
    .chat-btn { width: 36px; height: 36px; font-size: 16px; }
}

/* ---- Hotbar inventory (pixel-art quick-drop slots along bottom) ---- */
#hotbar {
    position: fixed;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    padding: 6px 8px;
    background: linear-gradient(180deg, rgba(10,25,41,0.9) 0%, rgba(3,10,18,0.95) 100%);
    border: 2px solid #D4A534;
    border-radius: 2px;
    box-shadow:
        0 4px 0 0 rgba(0,0,0,0.45),
        inset 2px 2px 0 0 rgba(255,255,255,0.1),
        inset -2px -2px 0 0 rgba(0,0,0,0.4);
    z-index: 105;
    image-rendering: pixelated;
}
.hotbar-slot {
    width: 46px;
    height: 46px;
    background: linear-gradient(180deg, #1a3040 0%, #0a1a24 100%);
    border: 2px solid #3ECFCF;
    border-radius: 2px;
    font-size: 26px;
    line-height: 1;
    cursor: grab;
    user-select: none;
    transition: transform 0.1s, box-shadow 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    box-shadow:
        inset 2px 2px 0 0 rgba(255,255,255,0.15),
        inset -2px -2px 0 0 rgba(0,0,0,0.4);
}
.hotbar-slot:active {
    transform: translateY(1px) scale(0.96);
    box-shadow:
        inset 2px 2px 0 0 rgba(0,0,0,0.3),
        inset -2px -2px 0 0 rgba(255,255,255,0.08);
}
.hotbar-slot.dragging-source { opacity: 0.5; }

@media (max-width: 480px) {
    #hotbar { bottom: 8px; gap: 4px; padding: 4px 6px; }
    .hotbar-slot { width: 42px; height: 42px; font-size: 24px; }
}

/* Make chips bigger and more tappable now that they're the primary controls */
.need-chip.actionable {
    cursor: pointer;
}
.need-chip.actionable:active { transform: scale(0.88); }

/* ---- Need-chip tap popover ---- */
.need-popover {
    position: fixed;
    z-index: 600;
    background: linear-gradient(180deg, rgba(15,34,51,0.98) 0%, rgba(5,21,32,0.98) 100%);
    border: 1px solid var(--gold-dim);
    border-radius: 14px;
    padding: 14px 14px 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.55), 0 0 0 1px rgba(62,207,207,0.1) inset;
    color: var(--text);
    opacity: 0;
    transform: translateY(-6px) scale(0.96);
    transition: opacity 0.15s ease-out, transform 0.18s ease-out;
    backdrop-filter: blur(8px);
}
.need-popover.visible { opacity: 1; transform: translateY(0) scale(1); }
.need-popover::before {
    content: '';
    position: absolute;
    top: -8px;
    left: var(--arrow-x, 50%);
    transform: translateX(-50%) rotate(45deg);
    width: 14px; height: 14px;
    background: rgba(15,34,51,0.98);
    border-left: 1px solid var(--gold-dim);
    border-top: 1px solid var(--gold-dim);
}
.need-popover.state-critical { border-color: var(--danger); box-shadow: 0 10px 30px rgba(0,0,0,0.6), 0 0 16px rgba(224,48,48,0.45); }
.need-popover.state-bad      { border-color: rgba(224,112,48,0.7); }
.need-popover.state-warn     { border-color: rgba(212,165,52,0.6); }

.need-popover-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
.need-popover-icon {
    font-size: 28px;
    line-height: 1;
    filter: drop-shadow(0 0 6px rgba(62,207,207,0.3));
}
.need-popover-title { flex: 1; min-width: 0; }
.need-popover-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--gold);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.need-popover-state {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
}
.need-popover-state.ok       { color: var(--cyan); }
.need-popover-state.warn     { color: #E0C070; }
.need-popover-state.bad      { color: #E07030; }
.need-popover-state.critical { color: var(--danger); animation: pulse 1.2s infinite; }
.need-popover-close {
    background: none; border: none; color: var(--text-dim);
    font-size: 22px; line-height: 1; cursor: pointer;
    padding: 2px 6px;
    min-width: 32px; min-height: 32px;
    border-radius: 6px;
}
.need-popover-close:hover { color: var(--gold); background: rgba(212,165,52,0.08); }

.need-popover-track {
    height: 6px;
    background: rgba(255,255,255,0.08);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 10px;
}
.need-popover-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.4s ease;
}

.need-popover-msg {
    font-size: 13px;
    line-height: 1.4;
    color: var(--text);
    margin: 0 0 10px;
}
.need-popover-note {
    font-size: 12px;
    color: var(--text-dim);
    font-style: italic;
    margin: 0 0 8px;
}
.need-popover-hint {
    font-size: 11px;
    color: var(--text-dim);
    margin: 8px 0 0;
    text-align: center;
    opacity: 0.75;
}

.need-popover-cta {
    width: 100%;
    background: linear-gradient(180deg, var(--gold) 0%, #B88B2B 100%);
    color: #0F2233;
    border: none;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    min-height: 44px;
    transition: transform 0.12s, box-shadow 0.2s;
    box-shadow: 0 3px 10px rgba(212,165,52,0.3);
}
.need-popover-cta:hover  { box-shadow: 0 4px 14px rgba(212,165,52,0.5); }
.need-popover-cta:active { transform: scale(0.97); }

/* ---- Evolution status panel ---- */
#settings-evolution-status {
    font-size: 13px;
    color: var(--text);
    margin-top: 6px;
}
.audio-diag {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
}
.audio-diag-text {
    font-size: 12px;
    color: var(--text-dim);
    font-family: monospace;
}
.volume-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    padding: 4px 2px;
}
.volume-icon {
    font-size: 16px;
    min-width: 22px;
    text-align: center;
}
#settings-volume-slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: rgba(212, 165, 52, 0.25);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}
#settings-volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: #D4A534;
    border: 2px solid rgba(255, 232, 153, 0.9);
    box-shadow: 0 0 6px rgba(212, 165, 52, 0.55);
    cursor: pointer;
}
#settings-volume-slider::-moz-range-thumb {
    width: 16px; height: 16px;
    border-radius: 50%;
    background: #D4A534;
    border: 2px solid rgba(255, 232, 153, 0.9);
    cursor: pointer;
}
.volume-value {
    font-size: 11px;
    color: var(--text-dim);
    font-family: monospace;
    min-width: 44px;
    text-align: right;
}

.grave-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.grave-pdf-btn {
    padding: 4px 10px;
    font-size: 13px;
    line-height: 1;
    flex-shrink: 0;
}
#btn-diary-pdf {
    margin-left: auto;
    padding: 4px 10px;
    font-size: 12px;
}
.diary-header {
    display: flex;
    align-items: center;
    gap: 10px;
}
.settings-weather-row {
    display: flex;
    gap: 8px;
    margin-top: 6px;
    flex-wrap: wrap;
}
#settings-weather-status {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-dim);
    font-family: monospace;
    line-height: 1.5;
}

/* Reliquiario */
.relics-container {
    padding: 16px;
    max-width: 720px;
    margin: 0 auto;
    height: 100%;
    overflow-y: auto;
}
.relics-header {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 12px;
}
.relics-tabs {
    display: flex; gap: 6px;
    border-bottom: 1px solid rgba(212,165,52,0.2);
    margin-bottom: 12px;
    overflow-x: auto;
}
.relics-tab {
    background: transparent;
    border: none;
    color: var(--text-dim);
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}
.relics-tab.active {
    color: #D4A534;
    border-bottom-color: #D4A534;
}
.relics-empty {
    color: var(--text-dim);
    font-style: italic;
    text-align: center;
    padding: 32px 16px;
    line-height: 1.6;
}
.relic-dream {
    background: rgba(10,25,41,0.55);
    border-left: 2px solid #6A5AAA;
    padding: 10px 14px;
    margin-bottom: 12px;
    border-radius: 4px;
}
.relic-dream.special {
    border-left-color: #D4A534;
    background: rgba(45,30,10,0.6);
}
.relic-dream-meta {
    font-size: 11px;
    color: var(--text-dim);
    font-family: monospace;
    margin-bottom: 6px;
}
.relic-dream-text {
    line-height: 1.55;
    color: #E8E2D4;
}
.relics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}
.relic-polaroid {
    background: #F0EADC;
    padding: 6px 6px 10px;
    border-radius: 2px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}
.relic-polaroid img {
    width: 100%;
    image-rendering: pixelated;
    display: block;
    border: 1px solid #3A2614;
}
.relic-polaroid-caption {
    color: #2A1E10;
    font-size: 11px;
    text-align: center;
    margin-top: 4px;
    line-height: 1.3;
}
.relic-polaroid-meta {
    color: #6E5E4A;
    font-size: 9px;
    text-align: center;
    font-family: monospace;
}
.relic-stone {
    background: rgba(20,14,8,0.7);
    padding: 10px;
    border-radius: 6px;
    text-align: center;
}
.relic-stone-svg {
    width: 60px; height: 60px;
    image-rendering: pixelated;
    border: 1px solid #5A4A30;
    border-radius: 2px;
}
.relic-stone-caption {
    font-size: 11px;
    color: #E0D4B8;
    margin-top: 6px;
    line-height: 1.4;
}
.relic-stone-meta {
    font-size: 9px;
    color: var(--text-dim);
    font-family: monospace;
    margin-top: 3px;
}
.relics-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.relic-constellation {
    padding: 10px 14px;
    background: rgba(10,25,41,0.55);
    border-radius: 4px;
    border-left: 2px solid rgba(212,165,52,0.2);
}
.relic-constellation.unlocked {
    border-left-color: #D4A534;
}
.relic-constellation.locked {
    opacity: 0.55;
}
.relic-const-name {
    font-weight: bold;
    color: #D4A534;
    margin-bottom: 4px;
}
.relic-constellation.locked .relic-const-name {
    color: var(--text-dim);
}
.relic-const-myth {
    font-size: 12px;
    color: #E8E2D4;
    font-style: italic;
    line-height: 1.5;
}
.evo-list {
    list-style: none;
    margin: 0; padding: 0;
    border: 1px solid rgba(212,165,52,0.2);
    border-radius: 8px;
    overflow: hidden;
}
.evo-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    font-size: 13px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}
.evo-list li:last-child { border-bottom: none; }
.evo-list li:nth-child(odd) { background: rgba(15,34,51,0.35); }
.evo-label  { color: var(--text-dim); }
.evo-values { color: var(--text); font-family: monospace; }
.evo-values b { color: #E07030; }
.evo-ready { color: var(--cyan); font-weight: 700; }
.evo-done  { color: var(--gold); }
.evo-dead  { color: var(--text-dim); font-style: italic; }
#btn-needs-expand.has-alerts { color: var(--danger); animation: pulse 1.4s infinite; }
#btn-needs-expand.has-alerts::after {
    content: attr(data-critical);
    position: absolute;
    top: 0; right: 0;
    background: var(--danger);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    min-width: 14px;
    height: 14px;
    border-radius: 7px;
    padding: 0 3px;
    display: flex; align-items: center; justify-content: center;
    line-height: 1;
}

/* ---- Canvas ---- */
#game-canvas {
    position: fixed;
    top: 52px;   /* matches status-bar height */
    left: 0;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* ---- Action Bar ---- */
#action-bar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 70px;
    background: linear-gradient(0deg, var(--bg-panel) 0%, rgba(10,25,41,0.9) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0 8px;
    z-index: 100;
    border-top: 1px solid var(--gold-dim);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.btn-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(15,34,51,0.8);
    border: 1px solid var(--gold-dim);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    padding: 6px 10px;
    min-width: 56px;
    transition: transform 0.15s, background var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.btn-action:active {
    transform: scale(0.92);
    background: rgba(212,165,52,0.15);
}

/* Need-based urgency highlight on action buttons */
.btn-action.urgent {
    border-color: #E05050;
    color: #FF9090;
    animation: btnUrgentPulse 1s ease-in-out infinite;
}
.btn-action.urgent .action-icon { filter: drop-shadow(0 0 5px rgba(224,80,80,0.8)); }
.btn-action.urgent .action-label { color: #FF9090; }

.btn-action.low {
    border-color: rgba(212,165,52,0.8);
    box-shadow: 0 0 6px rgba(212,165,52,0.25);
}
.btn-action.low .action-label { color: var(--gold); }

/* ---- Drag-to-pet gesture ghost ---- */
.action-ghost {
    position: fixed;
    left: 0; top: 0;
    transform: translate(-50%, -50%);
    z-index: 9000;
    width: 56px; height: 56px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, rgba(212,165,52,0.9) 0%, rgba(62,207,207,0.55) 60%, rgba(10,25,41,0.8) 100%);
    box-shadow: 0 0 22px rgba(62,207,207,0.55), 0 0 40px rgba(212,165,52,0.35);
    display: flex; align-items: center; justify-content: center;
    font-size: 28px;
    pointer-events: none;
    user-select: none;
    transition: transform 0.08s ease-out, opacity 0.2s, box-shadow 0.15s;
    animation: ghostFloat 1.4s ease-in-out infinite;
}
.action-ghost.on-target {
    transform: translate(-50%, -50%) scale(1.35);
    box-shadow: 0 0 36px #3ECFCF, 0 0 60px rgba(212,165,52,0.6);
}
.action-ghost.delivered {
    transform: translate(-50%, -50%) scale(2.2);
    opacity: 0;
}
.action-ghost.returning {
    transform: translate(-50%, -50%) scale(0.3);
    opacity: 0;
}
@keyframes ghostFloat {
    0%,100% { filter: hue-rotate(0deg); }
    50%     { filter: hue-rotate(20deg); }
}
.btn-action.dragging-source {
    opacity: 0.5;
    transform: scale(0.94);
}

.btn-action.satisfied {
    border-color: rgba(62,207,100,0.35);
}
.btn-action.satisfied .action-icon { filter: drop-shadow(0 0 3px rgba(62,207,100,0.4)); }

@keyframes btnUrgentPulse {
    0%,100% { box-shadow: 0 0 4px rgba(224,80,80,0.3); background: rgba(224,80,80,0.05); }
    50%      { box-shadow: 0 0 16px rgba(224,80,80,0.7); background: rgba(224,80,80,0.12); }
}

.action-icon {
    font-size: 20px;
    line-height: 1;
}

.action-label {
    font-size: 10px;
    margin-top: 2px;
    color: var(--text-dim);
    white-space: nowrap;
}

/* ---- Overlays ---- */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(2,10,10,0.85);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.overlay-content {
    background: var(--bg-panel);
    border: 1px solid var(--gold-dim);
    border-radius: 12px;
    padding: 24px;
    max-width: 90vw;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
}

.btn-close {
    position: absolute;
    top: 8px; right: 12px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 24px;
    cursor: pointer;
}

.hidden { display: none !important; }

/* ---- Screen Overlays ---- */
.screen-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-deep);
    z-index: 150;
    overflow-y: auto;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ---- Needs Panel ---- */
.needs-panel {
    width: 340px;
}

.needs-panel h2 {
    color: var(--gold);
    margin-bottom: 16px;
    font-size: 16px;
}

.needs-panel {
    width: min(420px, calc(100vw - 24px));
    max-height: 80vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px 18px;
}

.need-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
    margin-bottom: 10px;
    background: rgba(15, 34, 51, 0.6);
    border-radius: var(--radius);
    border: 1px solid transparent;
    transition: border-color 0.3s;
}
.need-card.warn     { border-color: rgba(212,165,52,0.35); }
.need-card.bad      { border-color: rgba(224,112,48,0.55); }
.need-card.critical { border-color: var(--danger); animation: cardCritPulse 1.2s infinite; }

@keyframes cardCritPulse {
    0%,100% { box-shadow: 0 0 0 0 rgba(196,64,64,0); }
    50%     { box-shadow: 0 0 0 2px rgba(196,64,64,0.35); }
}

.need-card-icon {
    font-size: 28px;
    flex-shrink: 0;
    width: 42px;
    text-align: center;
}
.need-card-body {
    flex: 1;
    min-width: 0;
}
.need-card-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 6px;
}
.need-card-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    text-transform: capitalize;
}
.need-card-value {
    font-size: 13px;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}
.need-card-track {
    width: 100%;
    height: 8px;
    background: rgba(255,255,255,0.08);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 6px;
}
.need-card-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}
.need-card-hint {
    font-size: 11px;
    color: var(--text-dim);
    line-height: 1.4;
    margin: 0;
    opacity: 0.85;
}

/* Legacy bars kept for fallback */
.need-bar-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.need-bar-label {
    width: 80px;
    font-size: 12px;
    color: var(--text-dim);
    text-align: right;
}

.need-bar-track {
    flex: 1;
    height: 10px;
    background: rgba(255,255,255,0.06);
    border-radius: 5px;
    overflow: hidden;
}

.need-bar-fill {
    height: 100%;
    border-radius: 5px;
    transition: width 0.5s ease;
}

.need-bar-value {
    width: 30px;
    font-size: 11px;
    color: var(--text-dim);
}

/* ---- Setup Wizard ---- */
.setup-container {
    max-width: 480px;
    margin: 0 auto;
    padding: 40px 24px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.setup-title {
    font-size: 24px;
    text-align: center;
    margin-bottom: 16px;
}

.setup-intro {
    text-align: center;
    color: var(--text-dim);
    margin-bottom: 24px;
    line-height: 1.6;
    font-style: italic;
}

.lore-text {
    color: var(--text-dim);
    font-size: 13px;
    line-height: 1.7;
    margin-bottom: 24px;
    padding: 16px;
    border-left: 2px solid var(--gold-dim);
    background: rgba(212,165,52,0.03);
}

.lore-text p {
    margin-bottom: 12px;
}

.gold-text { color: var(--gold); }

.setup-lang-grid, .setup-provider-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
    margin-bottom: 20px;
}

.btn-lang, .btn-provider {
    padding: 12px;
    background: var(--bg-card);
    border: 1px solid var(--gold-dim);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    font-size: 14px;
    transition: border-color var(--transition), background var(--transition);
}

.btn-lang:hover, .btn-provider:hover,
.btn-lang.selected, .btn-provider.selected {
    border-color: var(--gold);
    background: rgba(212,165,52,0.1);
}

.setup-field {
    margin-bottom: 16px;
}

.setup-field label {
    display: block;
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 4px;
}

.setup-field input, .settings-group input, .settings-group select {
    width: 100%;
    padding: 10px;
    background: var(--bg-card);
    border: 1px solid var(--gold-dim);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    outline: none;
}

.setup-field input:focus, .settings-group input:focus {
    border-color: var(--gold);
}

.setup-hint {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 4px;
    font-style: italic;
}

.setup-step input[type="text"] {
    width: 100%;
    padding: 10px;
    background: var(--bg-card);
    border: 1px solid var(--gold-dim);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    outline: none;
    margin-bottom: 16px;
}

/* ---- Buttons ---- */
.btn-primary {
    display: block;
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--gold-dim), var(--gold));
    border: none;
    border-radius: var(--radius);
    color: var(--bg-deep);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s;
    margin-top: 12px;
}

.btn-primary:active { transform: scale(0.96); }

.btn-secondary {
    padding: 10px 20px;
    background: var(--bg-card);
    border: 1px solid var(--gold-dim);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
}

.btn-small {
    padding: 8px 14px;
    background: var(--bg-card);
    border: 1px solid var(--gold-dim);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    margin-top: 4px;
}

.btn-danger {
    padding: 10px 20px;
    background: rgba(196,64,64,0.2);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    color: var(--danger);
    cursor: pointer;
    font-size: 13px;
    width: 100%;
}

.btn-back {
    background: none;
    border: none;
    color: var(--gold);
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
}

.btn-icon {
    background: var(--bg-card);
    border: 1px solid var(--gold-dim);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    color: var(--text);
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ---- Conversation ---- */
.conversation-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 600px;
    margin: 0 auto;
}

.conversation-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border-bottom: 1px solid var(--gold-dim);
}

.conversation-header h2 {
    color: var(--gold);
    font-size: 16px;
}

#conversation-log {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background:
        linear-gradient(180deg, rgba(10,25,41,0.95) 0%, rgba(5,15,25,0.98) 100%),
        repeating-linear-gradient(0deg, transparent 0 2px, rgba(62,207,207,0.02) 2px 3px);
    image-rendering: pixelated;
}

/* Pixel-art message bubbles with stepped borders (like RPG boxes) */
.msg {
    max-width: 82%;
    padding: 10px 14px 12px;
    font-size: 14px;
    line-height: 1.5;
    animation: msgPop 0.22s ease;
    position: relative;
    font-family: 'Courier New', monospace;
    border-radius: 2px;
    box-shadow:
        0 3px 0 0 rgba(0,0,0,0.3),
        inset 2px 2px 0 0 rgba(255,255,255,0.15),
        inset -2px -2px 0 0 rgba(0,0,0,0.35);
}
@keyframes msgPop {
    from { transform: translateY(6px) scale(0.96); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.msg-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    margin-bottom: 4px;
    opacity: 0.75;
    font-family: 'Courier New', monospace;
}
.msg-body {
    line-height: 1.55;
    font-size: 15px;
}

.msg-user {
    align-self: flex-end;
    background: linear-gradient(180deg, #3B2B0A 0%, #1E1605 100%);
    border: 2px solid #D4A534;
    color: #FFE899;
    text-shadow: 1px 1px 0 #000;
}
.msg-user .msg-label { color: #FFE899; }

.msg-pet {
    align-self: flex-start;
    background: linear-gradient(180deg, #103040 0%, #051A24 100%);
    border: 2px solid #3ECFCF;
    color: #BFF5F5;
    text-shadow: 1px 1px 0 #000;
    font-family: 'Courier New', monospace;
}
.msg-pet .msg-label {
    color: #3ECFCF;
    font-family: 'Courier New', monospace;
    letter-spacing: 2px;
}
.msg-pet .msg-body { font-family: 'Courier New', monospace; }

/* Karaoke: words glow as they're spoken, dim after */
.karaoke-word {
    display: inline-block;
    transition: color 0.12s, text-shadow 0.12s, transform 0.12s;
    color: #6AA8AC;  /* unspoken = dim */
}
.karaoke-word.spoken {
    color: #FFFFFF;
    text-shadow: 0 0 8px #3ECFCF, 0 0 14px #3ECFCF, 1px 1px 0 #000;
    transform: translateY(-1px) scale(1.03);
}
.karaoke-word.past {
    color: #BFF5F5;
    text-shadow: 1px 1px 0 #000;
    transform: none;
}

.msg-system {
    align-self: center;
    color: var(--text-dim);
    font-size: 12px;
    font-style: italic;
}

.conversation-input {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--gold-dim);
    background: var(--bg-panel);
}

#conv-input {
    flex: 1;
    padding: 10px;
    background: var(--bg-card);
    border: 1px solid var(--gold-dim);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    outline: none;
}

#conv-input:focus {
    border-color: var(--gold);
}

.btn-mic {
    position: relative;
}

.btn-mic.recording {
    background: var(--danger);
    border-color: var(--danger);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(196,64,64,0.4); }
    50% { box-shadow: 0 0 0 8px rgba(196,64,64,0); }
}

/* ---- Diary ---- */
.diary-container, .lexicon-container, .graveyard-container, .settings-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 0 16px 80px;
}

.diary-header, .lexicon-header, .graveyard-header, .settings-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 0;
    border-bottom: 1px solid var(--gold-dim);
    margin-bottom: 16px;
    position: sticky;
    top: 0;
    background: var(--bg-deep);
    z-index: 10;
}

.diary-header h2, .lexicon-header h2, .graveyard-header h2, .settings-header h2 {
    color: var(--gold);
    font-size: 16px;
}

.diary-entry {
    background: var(--bg-card);
    border: 1px solid var(--gold-dim);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 12px;
}

.diary-entry-day {
    font-size: 11px;
    color: var(--gold);
    margin-bottom: 6px;
}

.diary-entry-text {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-dim);
}

/* ---- Lexicon ---- */
#lexicon-filters {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.lexicon-filter-btn {
    padding: 4px 10px;
    background: var(--bg-card);
    border: 1px solid var(--gold-dim);
    border-radius: 12px;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 11px;
}

.lexicon-filter-btn.active {
    border-color: var(--gold);
    color: var(--gold);
}

.lexicon-word {
    background: var(--bg-card);
    border: 1px solid var(--gold-dim);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 8px;
}

.lexicon-word-name {
    font-family: var(--font-alien);
    color: var(--cyan);
    font-size: 16px;
    font-weight: 700;
}

.lexicon-word-ipa {
    font-size: 11px;
    color: var(--text-dim);
    margin-left: 8px;
}

.lexicon-word-meaning {
    font-size: 13px;
    color: var(--text);
    margin-top: 4px;
}

.lexicon-word-undiscovered {
    opacity: 0.3;
}

.lexicon-word-undiscovered .lexicon-word-name {
    color: var(--text-dim);
}

.lexicon-word-undiscovered .lexicon-word-meaning {
    font-style: italic;
    color: var(--text-dim);
}

/* ---- Graveyard ---- */
.grave-entry {
    background: var(--bg-card);
    border: 1px solid var(--gold-dim);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.grave-name {
    color: var(--gold);
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 4px;
}

.grave-details {
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.6;
}

.grave-last-words {
    font-style: italic;
    color: var(--cyan-dim);
    margin-top: 8px;
    padding: 8px;
    border-left: 2px solid var(--cyan-dim);
    font-family: var(--font-alien);
    font-size: 13px;
}

.grave-transcended {
    border-color: var(--gold);
}

.grave-transcended .grave-name {
    color: var(--gold);
    text-shadow: 0 0 10px rgba(212,165,52,0.4);
}

/* ---- Settings ---- */
.settings-group {
    margin-bottom: 16px;
}

.settings-group label {
    display: block;
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 4px;
}

.settings-group select {
    width: 100%;
    padding: 10px;
    background: var(--bg-card);
    border: 1px solid var(--gold-dim);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
}

/* ---- Speech Bubble ---- */
#speech-bubble {
    position: fixed;
    bottom: 138px;  /* above chat-bar + hotbar */
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(180deg, rgba(10,25,41,0.98) 0%, rgba(5,18,28,0.98) 100%);
    border: 2px solid var(--cyan);
    border-radius: 18px;
    padding: 16px 24px;
    min-width: 180px;
    max-width: 86vw;
    z-index: 110;
    box-shadow: 0 10px 34px rgba(0,0,0,0.6), 0 0 22px rgba(62,207,207,0.35), 0 0 0 1px rgba(62,207,207,0.15) inset;
    backdrop-filter: blur(6px);
    animation: bubbleIn 0.4s ease;
}
#speech-bubble::after {
    /* Pointer tail toward the pet (upward) */
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 18px; height: 18px;
    background: rgba(5,18,28,0.98);
    border-right: 2px solid var(--cyan);
    border-bottom: 2px solid var(--cyan);
    box-shadow: 6px 6px 14px rgba(62,207,207,0.25);
}

@keyframes bubbleIn {
    from { opacity: 0; transform: translateX(-50%) translateY(14px) scale(0.9); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

#speech-text {
    font-family: var(--font-alien);
    color: #EAFBFB;
    font-size: 19px;
    font-weight: 600;
    line-height: 1.45;
    text-align: center;
    text-shadow: 0 0 8px rgba(62,207,207,0.45), 0 2px 4px rgba(0,0,0,0.8);
    letter-spacing: 0.3px;
}

#speech-bubble.mood-happy { border-color: var(--mood-happy); }
#speech-bubble.mood-happy #speech-text { color: var(--mood-happy); }
#speech-bubble.mood-sad { border-color: var(--mood-sad); }
#speech-bubble.mood-sad #speech-text { color: var(--mood-sad); }
#speech-bubble.mood-scared { border-color: var(--mood-scared); }
#speech-bubble.mood-scared #speech-text { color: var(--mood-scared); }
#speech-bubble.mood-neutral { border-color: var(--mood-neutral); }
#speech-bubble.mood-neutral #speech-text { color: var(--mood-neutral); }

/* ---- Minigame ---- */
.minigame-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.minigame-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--gold-dim);
}

.minigame-header h2 {
    flex: 1;
    color: var(--gold);
    font-size: 14px;
}

#minigame-score {
    color: var(--cyan);
    font-size: 16px;
    font-weight: 700;
}

#minigame-canvas {
    flex: 1;
    width: 100%;
    background: var(--bg-deep);
    image-rendering: pixelated;
}

#minigame-message {
    position: absolute;
    bottom: 20%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(10,25,41,0.95);
    border: 1px solid var(--gold);
    border-radius: 12px;
    padding: 16px 24px;
    color: var(--gold);
    font-size: 16px;
    text-align: center;
    z-index: 10;
}

.minigame-select-container {
    max-width: 480px;
    margin: 0 auto;
    padding: 0 16px;
}

.minigame-select-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 0;
    border-bottom: 1px solid var(--gold-dim);
    margin-bottom: 20px;
}

.minigame-select-header h2 {
    color: var(--gold);
    font-size: 16px;
}

.minigame-select-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-game-select {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    background: var(--bg-card);
    border: 1px solid var(--gold-dim);
    border-radius: 12px;
    color: var(--text);
    cursor: pointer;
    transition: border-color var(--transition), transform 0.15s;
}

.btn-game-select:active {
    transform: scale(0.97);
}

.btn-game-select:hover {
    border-color: var(--gold);
}

.game-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.game-name {
    color: var(--gold);
    font-size: 16px;
    font-weight: 700;
    font-family: var(--font-alien);
}

.game-desc {
    color: var(--text-dim);
    font-size: 12px;
    margin-top: 4px;
}

/* ---- Login Screen ---- */
.login-container {
    max-width: 400px;
    margin: 0 auto;
    padding: 48px 28px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.login-container h1 {
    font-size: 28px;
    margin-bottom: 10px;
    letter-spacing: 2px;
}

.login-subtitle {
    color: var(--text-dim);
    font-size: 14px;
    margin-bottom: 36px;
    line-height: 1.5;
}

.login-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    text-align: left;
}

.login-field label {
    font-size: 12px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.login-field input {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--cyan-dim);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 22px;
    text-align: center;
    letter-spacing: 8px;
    padding: 14px 16px;
    outline: none;
    transition: border-color var(--transition);
    -webkit-user-select: text;
    user-select: text;
}

.login-field input[type="text"] {
    font-size: 16px;
    letter-spacing: 1px;
    text-align: left;
}

.login-field input:focus {
    border-color: var(--cyan);
}

.login-error {
    background: rgba(196, 64, 64, 0.15);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    color: var(--danger);
    font-size: 13px;
    padding: 10px 14px;
    text-align: center;
}

.login-hint {
    color: var(--text-dim);
    font-size: 12px;
    line-height: 1.5;
    margin-top: 4px;
}

.btn-link {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 12px;
    cursor: pointer;
    text-decoration: underline;
    padding: 4px;
    margin-top: 8px;
}

.btn-link:hover { color: var(--text); }

.login-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    color: var(--text-dim);
    font-size: 14px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--bg-card);
    border-top-color: var(--cyan);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* cloud sync indicator in status bar */
#status-cloud {
    font-size: 11px;
    margin-left: 6px;
    opacity: 0.6;
}
#status-cloud.synced  { color: var(--success); }
#status-cloud.syncing { color: var(--gold); }
#status-cloud.offline { color: var(--text-dim); }

/* ---- Rebirth Screen ---- */
.rebirth-container {
    max-width: 440px;
    margin: 0 auto;
    padding: 48px 28px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}
.rebirth-container h2 {
    font-size: 24px;
    margin-bottom: 20px;
    letter-spacing: 1px;
}
.rebirth-epitaph {
    color: var(--text-dim);
    font-style: italic;
    font-size: 13px;
    margin-bottom: 20px;
    padding: 12px 14px;
    border-left: 2px solid var(--gold-dim);
    line-height: 1.6;
    text-align: left;
    width: 100%;
}
.rebirth-text {
    color: var(--text-dim);
    font-size: 14px;
    margin-bottom: 24px;
    line-height: 1.6;
    font-style: italic;
}
.rebirth-field {
    width: 100%;
    margin-bottom: 20px;
    text-align: left;
}
.rebirth-field label {
    display: block;
    font-size: 12px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 6px;
}
.rebirth-field input {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--cyan-dim);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 16px;
    padding: 12px 14px;
    outline: none;
    -webkit-user-select: text;
    user-select: text;
}
.rebirth-field input:focus { border-color: var(--cyan); }
.rebirth-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    margin-bottom: 16px;
}
.rebirth-note {
    font-size: 11px;
    color: var(--text-dim);
    opacity: 0.7;
    line-height: 1.5;
}

/* ---- Account row in settings ---- */
.settings-account-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: rgba(15,34,51,0.5);
    border-radius: var(--radius);
    border: 1px solid var(--cyan-dim);
}
.settings-account-name {
    flex: 1;
    font-size: 14px;
    color: var(--cyan);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.btn-logout {
    background: var(--danger);
    color: #fff;
    border: none;
    min-width: 90px;
}
.btn-logout:hover { background: #D05050; }

/* ---- Toggle Row (checkbox + label) ---- */
.toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
}
.toggle-row input[type="checkbox"] {
    width: 22px;
    height: 22px;
    accent-color: var(--cyan);
    cursor: pointer;
    margin: 0;
}

/* ---- Tutorial Tooltip ---- */
.tutorial-tip {
    position: fixed;
    max-width: 280px;
    min-width: 200px;
    background: var(--bg-panel);
    border: 1px solid var(--gold-dim);
    border-radius: var(--radius);
    padding: 12px 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), 0 0 12px rgba(212, 165, 52, 0.15);
    z-index: 400;
    animation: tipFadeIn 0.25s ease-out;
    color: var(--text);
    font-size: 13px;
    line-height: 1.45;
}

.tutorial-tip.hidden { display: none; }

.tutorial-tip-text {
    margin-bottom: 10px;
}

.tutorial-tip-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    align-items: center;
}

.tutorial-tip-close {
    background: var(--gold);
    border: none;
    border-radius: 4px;
    color: #000;
    font-size: 12px;
    padding: 5px 10px;
    cursor: pointer;
    font-weight: 600;
}

.tutorial-tip-close:hover { background: #E5B840; }

.tutorial-tip-disable {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 11px;
    cursor: pointer;
    text-decoration: underline;
    padding: 4px;
}

.tutorial-tip-disable:hover { color: var(--text); }

/* Pointer arrow (depending on anchor side) */
.tutorial-tip::before {
    content: "";
    position: absolute;
    width: 0; height: 0;
    border: 6px solid transparent;
}
.tutorial-tip[data-pos="top"]::before {
    bottom: -12px; left: 50%; transform: translateX(-50%);
    border-top-color: var(--gold-dim);
}
.tutorial-tip[data-pos="bottom"]::before {
    top: -12px; left: 50%; transform: translateX(-50%);
    border-bottom-color: var(--gold-dim);
}
.tutorial-tip[data-pos="left"]::before {
    right: -12px; top: 50%; transform: translateY(-50%);
    border-left-color: var(--gold-dim);
}
.tutorial-tip[data-pos="right"]::before {
    left: -12px; top: 50%; transform: translateY(-50%);
    border-right-color: var(--gold-dim);
}

@keyframes tipFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---- Toast ---- */
#toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-panel);
    border: 1px solid var(--gold-dim);
    border-radius: var(--radius);
    padding: 10px 20px;
    color: var(--text);
    font-size: 13px;
    z-index: 300;
    animation: fadeIn 0.3s ease;
}

/* ---- Confirm Dialog ---- */
.confirm-panel {
    width: 300px;
    text-align: center;
}

.confirm-panel p {
    margin-bottom: 16px;
    line-height: 1.5;
}

.confirm-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.confirm-buttons .btn-primary {
    width: auto;
    padding: 10px 24px;
}

/* ---- Idle Breathing Animation ---- */
@keyframes breathe {
    0%, 100% { transform: translateX(-50%) scale(1); }
    50% { transform: translateX(-50%) scale(1.02); }
}

/* ---- Responsive — Mobile / Tablet ---- */

/* iOS safe-area insets — respect notch and home indicator */
@supports (padding: env(safe-area-inset-top)) {
    #status-bar  { padding-top: max(6px, env(safe-area-inset-top)); padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
    #action-bar  { padding-bottom: max(6px, env(safe-area-inset-bottom)); padding-left: max(6px, env(safe-area-inset-left)); padding-right: max(6px, env(safe-area-inset-right)); }
    .screen-overlay { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
    .conversation-input { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
}

/* Allow text selection inside inputs / textareas on mobile (override global no-select) */
input, textarea, select, [contenteditable="true"] {
    -webkit-user-select: text;
    user-select: text;
}

@media (max-width: 480px) {
    /* Action bar: 4 columns, 2 rows, bigger tap area */
    #action-bar {
        height: auto;
        padding: 6px 4px;
        gap: 4px;
        flex-wrap: wrap;
        justify-content: center;
    }
    .btn-action {
        padding: 8px 4px;
        min-width: 0;
        min-height: 48px;
        flex: 0 0 calc(25% - 4px);
    }
    .action-label { font-size: 9px; }
    .action-icon  { font-size: 20px; }

    /* Status bar: two-row layout on mobile — meta on top, chips below */
    #status-bar {
        flex-wrap: wrap;
        height: auto;
        min-height: 84px;
        row-gap: 2px;
        padding: 4px 10px;
        font-size: 12px;
        align-items: center;
    }
    #status-left, #status-right {
        flex: 0 0 auto;
        order: 1;
    }
    #status-needs-dots.needs-chips {
        order: 3;
        flex-basis: 100%;
        width: 100%;
        justify-content: space-around;
        padding: 2px 0 4px;
        gap: 2px;
    }
    #status-name { font-size: 13px; }
    #status-age  { font-size: 11px; }
    #status-cloud { font-size: 13px; }
    #btn-needs-expand, .btn-status-icon {
        width: 36px; height: 36px;
        min-width: 36px; min-height: 36px;
        font-size: 18px;
        padding: 2px 4px;
    }
    .need-chip {
        width: 34px; height: 34px;
        flex: 0 0 auto;
    }
    .need-chip-icon { font-size: 17px; }

    /* Speech bubble */
    #speech-bubble { max-width: 94vw; bottom: 16px; padding: 14px 18px; }
    #speech-text   { font-size: 18px; }

    /* Setup wizard */
    .setup-container { padding: 20px 16px; }
    .setup-title     { font-size: 20px; }

    /* Login screen */
    .login-container { padding: 32px 20px; }
    .login-container h1 { font-size: 22px; }

    /* Conversation input: bigger for mobile keyboard */
    #conv-input {
        font-size: 16px; /* prevents iOS auto-zoom on focus */
        padding: 12px;
        min-height: 44px;
    }
    #btn-conv-send, #btn-conv-mic {
        min-width: 44px; min-height: 44px;
    }

    /* Settings screen: larger touch targets */
    .settings-container { padding: 16px; }
    .settings-group input[type="text"],
    .settings-group input[type="password"],
    .settings-group select {
        font-size: 16px;
        padding: 10px;
        min-height: 44px;
    }
    .btn-small, .btn-primary, .btn-danger {
        min-height: 44px;
        font-size: 14px;
    }

    /* Tutorial tooltip: smaller on mobile, avoid overflow */
    .tutorial-tip {
        max-width: min(300px, calc(100vw - 20px));
        font-size: 12px;
        padding: 10px 12px;
    }
    .tutorial-tip-close { padding: 8px 12px; font-size: 13px; min-height: 36px; }

    /* Needs overlay: mobile-optimized */
    .needs-panel { width: min(320px, calc(100vw - 24px)); padding: 16px; }

    /* Confirm dialog: mobile width */
    .confirm-panel { width: min(320px, calc(100vw - 32px)); }

    /* Screen overlays scroll correctly */
    .screen-overlay { overflow-y: auto; -webkit-overflow-scrolling: touch; }

    /* Login PIN input: visible touch target */
    .login-field input { min-height: 52px; font-size: 24px; }
    .login-field input[type="text"] { font-size: 16px; }

    /* Toggle rows a bit bigger */
    .toggle-row { padding: 12px 0; font-size: 15px; }
    .toggle-row input[type="checkbox"] { width: 26px; height: 26px; }
}

/* Portrait mode tweaks */
@media (max-width: 480px) and (orientation: portrait) {
    /* Canvas fills space above action bar minus status */
    #game-canvas { touch-action: none; }
}

/* Prevent pull-to-refresh inside the app */
body { overscroll-behavior: none; }

@media (min-width: 800px) {
    .btn-action {
        padding: 8px 16px;
        min-width: 70px;
    }
    .action-label { font-size: 11px; }
}
