:root {
    --bg: #1a1a2e;
    --surface: #2a2a4a;
    --accent: #a8e6cf;
    --text: #e0e0e0;
    --text-dim: #888;
    --user-bubble: #3a3a6a;
    --mochi-bubble: #2a2a4a;
    --system-color: #666;
    --bar-bg: #1a1a2e;
    --bar-fill: #a8e6cf;
    --bar-high: #ff8a80;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    max-width: 100vw;
}

html, body {
    height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    font-size: 15px;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: manipulation;
}

body {
    display: flex;
    flex-direction: column;
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* ── Header ── */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--surface);
    flex-shrink: 0;
}

.sprite-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

#creature-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

#sprite {
    width: 96px;
    height: 96px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

#mood-label {
    font-size: 13px;
    color: var(--accent);
    text-transform: capitalize;
}

.llm-status {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #666;
    transition: background 0.3s ease;
}

.llm-status.online {
    background: #4caf50;
    box-shadow: 0 0 4px #4caf5088;
}

.llm-status.offline {
    background: #666;
}

#inner-world-btn {
    background: var(--bg);
    color: var(--text-dim);
    border: 1px solid #444;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    min-height: 44px;
}

#inner-world-btn:active {
    background: #3a3a5a;
    color: var(--accent);
    border-color: var(--accent);
}

/* ── Stats Bar (always visible) ── */
#stats-bar {
    flex-shrink: 0;
    background: var(--surface);
    padding: 4px 16px 8px;
}

.drive-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 3px;
}

.drive-label {
    width: 60px;
    font-size: 11px;
    color: var(--text-dim);
    text-align: right;
}

.drive-bar-bg {
    flex: 1;
    height: 6px;
    background: var(--bar-bg);
    border-radius: 3px;
    overflow: hidden;
}

.drive-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.4s ease, background-color 0.4s ease;
}

.drive-value {
    width: 28px;
    font-size: 11px;
    color: var(--text-dim);
    text-align: right;
}

/* ── Chat Log ── */
main {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}

.msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.msg.user {
    align-self: flex-end;
    background: var(--user-bubble);
    border-bottom-right-radius: 4px;
}

.msg.mochi {
    align-self: flex-start;
    background: var(--mochi-bubble);
    border-bottom-left-radius: 4px;
}

.msg.system {
    align-self: center;
    background: transparent;
    color: var(--system-color);
    font-size: 12px;
    text-align: center;
    max-width: 90%;
}

.msg.autonomous {
    align-self: flex-start;
    background: transparent;
    color: var(--text-dim);
    font-style: italic;
    font-size: 13px;
    padding: 6px 14px;
}

.msg.mood-change {
    align-self: center;
    background: transparent;
    color: var(--accent);
    font-size: 12px;
    text-align: center;
}

.msg.thinking {
    align-self: flex-start;
    background: var(--mochi-bubble);
    color: var(--text-dim);
    font-style: italic;
    border-bottom-left-radius: 4px;
}

.msg.drawing {
    align-self: flex-start;
    background: var(--mochi-bubble);
    border-bottom-left-radius: 4px;
    padding: 10px;
}

.drawing-canvas {
    display: block;
    width: 144px;
    height: 144px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    border-radius: 8px;
    margin-bottom: 6px;
}

.drawing-caption {
    font-size: 13px;
    font-style: italic;
    color: var(--text-dim);
}

/* ── Footer ── */
footer {
    flex-shrink: 0;
    background: var(--surface);
    padding: 10px 16px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

.care-buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.care-buttons button {
    flex: 1;
    min-height: 44px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid #444;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
}

.care-buttons button:active {
    background: #3a3a5a;
}

.care-buttons button:disabled {
    opacity: 0.5;
    cursor: default;
}

.talk-bar {
    display: flex;
    gap: 8px;
}

#talk-input {
    flex: 1;
    min-height: 44px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid #444;
    border-radius: 8px;
    padding: 0 14px;
    font-size: 15px;
    outline: none;
}

#talk-input:focus {
    border-color: var(--accent);
}

#talk-send {
    min-height: 44px;
    min-width: 60px;
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

#talk-send:active {
    opacity: 0.8;
}

#talk-send:disabled {
    opacity: 0.5;
    cursor: default;
}

/* ── Modals ── */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal.open {
    display: flex;
}

.modal-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 28px 24px;
    max-width: 360px;
    width: 100%;
    text-align: center;
}

.modal-card h2 {
    font-size: 20px;
    margin-bottom: 8px;
    color: var(--text);
}

.modal-card p {
    font-size: 14px;
    color: var(--text-dim);
    margin-bottom: 20px;
}

.modal-card input[type="text"] {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid #444;
    border-radius: 8px;
    font-size: 16px;
    outline: none;
    margin-bottom: 16px;
    text-align: center;
}

.modal-card input[type="text"]:focus {
    border-color: var(--accent);
}

.modal-card button {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

.modal-card button:active {
    opacity: 0.8;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none !important;
    border: none !important;
    color: var(--text-dim) !important;
    font-size: 28px !important;
    width: auto !important;
    padding: 4px 8px !important;
    cursor: pointer;
}

/* ── Login Modal Error ── */
.modal-error {
    color: #ff8a80;
    font-size: 13px;
    min-height: 18px;
    margin-bottom: 8px;
}

/* ── Inner World Modal ── */
.inner-world-card {
    position: relative;
    max-width: 420px;
    max-height: 80vh;
    overflow-y: auto;
    text-align: left;
    background: linear-gradient(160deg, #2a2a4a 0%, #1e1e3a 50%, #2a2a4a 100%);
}

.inner-world-loading {
    text-align: center;
    color: var(--text-dim);
    font-style: italic;
    font-size: 15px;
    padding: 32px 0;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

.inner-world-narrative {
    font-size: 16px;
    font-style: italic;
    line-height: 1.7;
    color: var(--text);
    padding: 8px 0 16px;
    display: none;
}

.inner-world-narrative.visible {
    display: block;
    animation: fadeIn 0.6s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.inner-world-detail {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 16px;
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.6;
    display: none;
}

.inner-world-detail.visible {
    display: block;
}

.inner-world-detail .detail-section {
    margin-bottom: 12px;
}

.inner-world-detail .detail-label {
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
}

.interest-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.interest-topic {
    width: 80px;
    text-align: right;
    text-transform: capitalize;
}

.interest-bar-bg {
    flex: 1;
    height: 6px;
    background: var(--bar-bg);
    border-radius: 3px;
    overflow: hidden;
}

.interest-bar-fill {
    height: 100%;
    background: #c9b3ff;
    border-radius: 3px;
    transition: width 0.4s ease;
}

/* ── Like Heart ── */
.like-heart {
    display: inline-block;
    font-size: 12px;
    color: #ff6b6b;
    margin-left: 6px;
    animation: heartPop 0.3s ease;
}

@keyframes heartPop {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.4); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

.msg {
    position: relative;
}

/* ── Photo Button ── */
#photo-btn {
    min-height: 44px;
    min-width: 44px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid #444;
    border-radius: 8px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#photo-btn:active {
    background: #3a3a5a;
}

/* ── Chat Photo ── */
.chat-photo {
    max-width: 200px;
    max-height: 200px;
    border-radius: 12px;
    object-fit: cover;
    display: block;
}

.photo-msg {
    padding: 6px;
}
