/* ===== 今日血条 - 像素风样式 ===== */

@font-face {
    font-family: 'Zpix';
    src: url('assets/fonts/zpix.ttf') format('truetype');
    font-display: swap;
}

:root {
    --bg-color: #0d0d0d;
    --hp-full: #4caf50;
    --hp-normal: #8bc34a;
    --hp-light: #ffc107;
    --hp-low: #ff7043;
    --hp-critical: #e53935;
    --hp-empty: #1a1a1a;
    --text-color: #e0e0e0;
    --text-dim: #666;
    --text-dimmer: #444;
    --border-color: #2a2a2a;
    --bubble-bg: #f5f0e8;
    --bubble-text: #1a1a1a;
    --bubble-border: #d0c8b8;
    --input-bg: #1a1a1a;
    --input-border: #333;
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-color);
    font-family: 'Zpix', 'Courier New', monospace;
    color: var(--text-color);
    image-rendering: pixelated;
    user-select: none;
    -webkit-user-select: none;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 480px;
    margin: 0 auto;
    position: relative;
}

/* ===== 经典游戏血条 ===== */
#hp-bar-container {
    padding: 16px 20px 0;
    flex-shrink: 0;
    position: relative;
}

#hp-bar-outer {
    width: 100%;
    height: 22px;
    background: #1a0a0a;
    border: 3px solid #0a0a0a;
    box-shadow:
        0 0 0 1px #2a1a1a,
        inset 0 0 6px rgba(0,0,0,0.6);
    position: relative;
    overflow: hidden;
}

#hp-bar-inner {
    height: 100%;
    width: 70%;
    background: linear-gradient(180deg, #e53935 0%, #c62828 50%, #8e0000 100%);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.25);
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1), background 0.5s ease;
    position: relative;
}

/* 光泽高光 */
#hp-bar-inner::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 45%;
    background: linear-gradient(180deg, rgba(255,255,255,0.3), transparent);
}

/* 竖条纹纹理 */
#hp-bar-ticks {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        90deg,
        transparent 0,
        transparent 9px,
        rgba(0,0,0,0.25) 9px,
        rgba(0,0,0,0.25) 10px
    );
    pointer-events: none;
    z-index: 2;
}

/* 颜色分级 */
#hp-bar-inner.hp-green {
    background: linear-gradient(180deg, #66bb6a 0%, #43a047 50%, #2e7d32 100%);
}

#hp-bar-inner.hp-yellow {
    background: linear-gradient(180deg, #ffca28 0%, #ffb300 50%, #ff8f00 100%);
}

#hp-bar-inner.hp-orange {
    background: linear-gradient(180deg, #ff7043 0%, #f4511e 50%, #d84315 100%);
}

#hp-bar-inner.hp-red {
    background: linear-gradient(180deg, #e53935 0%, #c62828 50%, #8e0000 100%);
}

/* 危急闪烁 */
#hp-bar-outer.critical {
    animation: barFlash 0.8s ease infinite;
}

@keyframes barFlash {
    0%, 100% { border-color: #0a0a0a; box-shadow: 0 0 0 1px #2a1a1a; }
    50% { border-color: #e53935; box-shadow: 0 0 0 1px #e53935, 0 0 12px rgba(229,57,53,0.4); }
}

/* 血条标签 */
#hp-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-top: 4px;
}

#hp-text {
    font-size: 16px;
    color: var(--text-color);
    letter-spacing: 1px;
    font-weight: bold;
}

#state-text {
    font-size: 11px;
    color: var(--text-dimmer);
}

/* 今日冒险按钮 */
#adventure-btn {
    font-size: 11px;
    color: var(--text-dimmer);
    cursor: pointer;
    padding: 2px 8px;
    transition: color 0.2s;
    text-decoration: underline;
    text-decoration-color: var(--text-dimmer);
    text-underline-offset: 2px;
}

#adventure-btn:hover {
    color: var(--hp-low);
    text-decoration-color: var(--hp-low);
}

/* BGM 开关 */
#bgm-toggle {
    display: block;
    margin: 8px auto 16px;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-dimmer);
    font-family: 'Zpix', monospace;
    font-size: 14px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.3s ease;
    z-index: 10;
    flex-shrink: 0;
}
#bgm-toggle:hover {
    border-color: var(--hp-normal);
    color: var(--hp-normal);
}
#bgm-toggle:not(.muted) {
    border-color: var(--hp-normal);
    color: var(--hp-normal);
    animation: bgmPulse 2s ease-in-out infinite;
}
@keyframes bgmPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ===== 主区域 ===== */
#main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    position: relative;
    padding-bottom: 20px;
    overflow: hidden;
}

/* ===== 背景层 ===== */
#bg-layer {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    overflow: hidden;
    z-index: 0;
    background: linear-gradient(180deg, #121218 0%, #1a1a22 40%, #222230 100%);
}

/* 漂浮光粒子（冷色调） */
.particle {
    position: absolute;
    bottom: -10px;
    left: var(--x);
    width: var(--s);
    height: var(--s);
    border-radius: 50%;
    background: rgba(180, 200, 255, 0.5);
    box-shadow: 0 0 6px rgba(160, 180, 230, 0.3);
    animation: floatUp var(--dur) ease-in-out infinite;
    animation-delay: var(--d);
}

@keyframes floatUp {
    0% { transform: translateY(0) translateX(0); opacity: 0; }
    10% { opacity: 0.7; }
    50% { transform: translateY(-50vh) translateX(10px); opacity: 0.4; }
    90% { opacity: 0.15; }
    100% { transform: translateY(-100vh) translateX(-5px); opacity: 0; }
}

/* ===== 对话框（角色上方） ===== */
#dialog-bubble {
    background: var(--bubble-bg);
    border: 2px solid var(--bubble-border);
    padding: 10px 16px;
    max-width: 300px;
    min-width: 120px;
    margin-bottom: 8px;
    position: relative;
    z-index: 2;
    box-shadow: 2px 2px 0 rgba(0,0,0,0.4);
    animation: bubbleIn 0.4s ease;
}

#dialog-bubble.hidden {
    display: none;
}

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

#dialog-text {
    font-size: 13px;
    line-height: 1.7;
    color: var(--bubble-text);
    letter-spacing: 0.5px;
    text-align: center;
    word-break: break-word;
}

#dialog-pointer {
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 8px solid var(--bubble-border);
}

#dialog-pointer::after {
    content: '';
    position: absolute;
    top: -10px;
    left: -4px;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 6px solid var(--bubble-bg);
}

/* ===== 像素角色 Canvas ===== */
#character-area {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    position: relative;
}

#pixel-canvas {
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    width: 160px;
    height: 220px;
    transition: filter 0.5s ease;
}

#character-area.state-sleeping #pixel-canvas {
    filter: brightness(0.4);
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

#character-area.shake #pixel-canvas {
    animation: shake 0.3s ease-in-out 3;
}

/* ===== 急救包建议 ===== */
#suggestions-area {
    margin-top: 12px;
    margin-bottom: 4px;
}

#suggestions-area.hidden {
    display: none;
}

#suggestions-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
}

.suggestion-btn {
    background: transparent;
    border: 1px solid var(--input-border);
    color: var(--text-dim);
    padding: 3px 8px;
    font-family: 'Zpix', monospace;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s;
}

.suggestion-btn:hover {
    border-color: var(--hp-low);
    color: var(--text-color);
}

/* ===== 隐蔽输入区域 ===== */
#input-zone {
    flex-shrink: 0;
    padding: 8px 20px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#input-hint {
    font-size: 11px;
    color: var(--text-dimmer);
    cursor: pointer;
    padding: 4px 12px;
    transition: color 0.2s;
}

#input-hint:hover {
    color: var(--text-dim);
}

#input-panel {
    display: flex;
    gap: 6px;
    width: 100%;
    max-width: 340px;
    animation: panelIn 0.2s ease;
}

#input-panel.hidden {
    display: none;
}

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

#text-input {
    flex: 1;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--text-color);
    padding: 6px 10px;
    font-family: 'Zpix', monospace;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
}

#text-input:focus {
    border-color: var(--hp-low);
}

#text-input::placeholder {
    color: var(--text-dimmer);
}

#send-btn {
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--text-dim);
    padding: 6px 12px;
    font-family: 'Zpix', monospace;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}

#send-btn:hover {
    color: var(--text-color);
    border-color: var(--hp-low);
}

#send-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ===== 黑屏覆盖 ===== */
#black-screen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #000;
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.8s ease;
}

#black-screen-overlay.hidden {
    display: none;
}

#black-screen-text {
    color: #fff;
    font-size: 16px;
    text-align: center;
    line-height: 1.8;
    letter-spacing: 1px;
    padding: 0 32px;
    max-width: 320px;
    opacity: 0;
    animation: textFadeIn 1.5s ease 0.5s forwards;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* ===== 加载动画 ===== */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-color);
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease;
}

#loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-dots {
    display: flex;
    gap: 6px;
}

.loading-dots span {
    width: 6px;
    height: 6px;
    background: var(--text-dim);
    animation: dot-bounce 1.4s ease-in-out infinite;
}

.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-bounce {
    0%, 80%, 100% { transform: scale(0.5); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}

/* ===== 响应式 ===== */
@media (max-height: 600px) {
    #pixel-canvas { width: 120px; height: 160px; }
}

@media (max-width: 360px) {
    #hp-text { font-size: 12px; }
    #dialog-text { font-size: 12px; }
    #pixel-canvas { width: 128px; height: 170px; }
}

/* ===== 冒险回顾面板 ===== */
#adventure-overlay, #history-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.85);
    z-index: 150;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    animation: overlayIn 0.3s ease;
}

#adventure-overlay.hidden, #history-overlay.hidden {
    display: none;
}

@keyframes overlayIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

#adventure-panel, #history-panel {
    width: 100%;
    max-width: 480px;
    max-height: 80vh;
    background: #111;
    border-top: 1px solid #2a2a2a;
    border-radius: 12px 12px 0 0;
    display: flex;
    flex-direction: column;
    animation: panelSlideUp 0.3s ease;
    overflow: hidden;
}

@keyframes panelSlideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

#adventure-header, #history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px 10px;
    border-bottom: 1px solid #1a1a1a;
    flex-shrink: 0;
}

#adventure-title, #history-title {
    font-size: 14px;
    color: var(--text-color);
    letter-spacing: 1px;
}

#adventure-close, #history-back {
    font-size: 18px;
    color: var(--text-dim);
    cursor: pointer;
    padding: 4px 8px;
    transition: color 0.2s;
}

#adventure-close:hover, #history-back:hover {
    color: var(--hp-low);
}

#adventure-summary {
    padding: 8px 20px;
    font-size: 11px;
    color: var(--text-dimmer);
    border-bottom: 1px solid #111;
    flex-shrink: 0;
}

#adventure-list, #history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 16px 16px;
    -webkit-overflow-scrolling: touch;
}

/* 单条记录卡片 */
.record-card {
    background: #1a1a1a;
    border: 1px solid #222;
    border-radius: 6px;
    padding: 10px 14px;
    margin-bottom: 8px;
    animation: cardIn 0.3s ease;
}

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

.record-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 6px;
}

.record-time {
    font-size: 10px;
    color: var(--text-dimmer);
}

.record-delta {
    font-size: 12px;
    font-weight: bold;
    padding: 1px 6px;
    border-radius: 3px;
}

.record-delta.neg {
    color: #e53935;
    background: rgba(229,57,53,0.1);
}

.record-delta.pos {
    color: #4caf50;
    background: rgba(76,175,80,0.1);
}

.record-delta.zero {
    color: var(--text-dimmer);
    background: rgba(255,255,255,0.05);
}

.record-text {
    font-size: 13px;
    color: var(--text-color);
    line-height: 1.6;
    word-break: break-word;
}

.record-emotions {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-top: 6px;
}

.record-emotion-tag {
    font-size: 9px;
    padding: 1px 5px;
    border-radius: 2px;
    background: #2a2a2a;
    color: var(--text-dim);
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-dimmer);
    font-size: 13px;
    line-height: 1.8;
}

/* 底部往日冒险入口 */
#adventure-footer {
    padding: 10px 20px 14px;
    border-top: 1px solid #1a1a1a;
    flex-shrink: 0;
    text-align: center;
}

#history-btn {
    font-size: 12px;
    color: var(--text-dim);
    cursor: pointer;
    transition: color 0.2s;
}

#history-btn:hover {
    color: var(--hp-low);
}

/* 往日冒险日期分组 */
.history-date-group {
    margin-bottom: 16px;
}

.history-date-header {
    font-size: 12px;
    color: var(--text-dim);
    padding: 8px 4px 6px;
    border-bottom: 1px solid #1a1a1a;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.history-date-delta {
    font-size: 11px;
}

.history-date-delta.neg { color: #e53935; }
.history-date-delta.pos { color: #4caf50; }
