/* ===== 变量 ===== */
:root {
    --bg: #f5f0eb;
    --bg2: #ede7e0;
    --card: #faf8f5;
    --text: #3d3530;
    --text2: #6b5f56;
    --text3: #9a8e84;
    --border: #d9d2ca;
    --border2: #e8e2da;
    --orange: #e8a87c;
    --orange2: #f5d4c0;
    --purple: #c4a8d0;
    --purple2: #e5d8ec;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 4px 24px rgba(60,50,40,0.08);
    --shadow-lg: 0 8px 40px rgba(60,50,40,0.14);
}

* { margin:0; padding:0; box-sizing:border-box; }
html { font-size:16px; }
body {
    font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height:100vh;
    overflow:hidden;
    user-select:none;
    -webkit-user-select:none;
}
img, canvas { -webkit-user-drag:none; pointer-events:none; }

.hidden { display:none !important; }

/* ===== 层系统 ===== */
.layer {
    position:fixed; inset:0;
    display:none; flex-direction:column;
    opacity:0; transition:opacity 0.5s ease;
}
.layer.active { display:flex; opacity:1; }

/* ===== 登录层 ===== */
#login-layer {
    align-items:center; justify-content:center;
    background: linear-gradient(135deg, var(--bg) 0%, var(--bg2) 100%);
}

.login-card {
    background: var(--card);
    padding: 48px 36px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width:90%; max-width:360px;
    text-align:center;
}

.site-title {
    font-size: 2.6rem;
    font-weight: 300;
    letter-spacing: 0.2em;
    margin-bottom: 40px;
    color: var(--text);
}

.input-group { margin-bottom: 16px; }
.input-group input {
    width:100%; padding: 14px 18px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    font-size: 1rem; color: var(--text);
    outline:none; transition: all 0.2s;
}
.input-group input:focus {
    border-color: var(--orange);
    box-shadow: 0 0 0 3px rgba(232,168,124,0.15);
}
.input-group input::placeholder { color: var(--text3); }

.btn-primary {
    width:100%; padding: 14px;
    border:none; border-radius: var(--radius-sm);
    background: var(--text); color: var(--card);
    font-size: 1rem; font-weight: 500;
    cursor:pointer; transition: all 0.2s;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.divider {
    display:flex; align-items:center;
    margin: 20px 0; color: var(--text3);
    font-size: 0.8rem;
}
.divider::before, .divider::after {
    content:""; flex:1; height:1px; background: var(--border2);
}
.divider span { padding: 0 16px; }

.btn-secondary {
    width:100%; padding: 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent; color: var(--text2);
    font-size: 1rem; font-weight: 500;
    cursor:pointer; transition: all 0.2s;
}
.btn-secondary:hover { background: var(--bg2); }

/* 开发端触发区 */
.admin-trigger {
    position:fixed; left:0; top:40%;
    width: 60px; height: 20%;
    cursor: default;
}

/* ===== 弹窗 ===== */
.modal {
    position:fixed; inset:0; z-index:2000;
    display:flex; align-items:center; justify-content:center;
    background: rgba(30,25,20,0.5);
    backdrop-filter: blur(4px);
}
.modal-box {
    background: var(--card);
    padding: 32px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width:90%; max-width: 380px;
    text-align:center;
}
.modal-box input {
    width:100%; margin-bottom: 16px;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    font-size: 0.95rem;
    outline:none;
}
.modal-box .btn-primary, .modal-box .btn-secondary {
    width:auto; min-width: 100px;
    display:inline-block; margin: 0 6px;
}
.modal-wide { max-width: 520px; max-height: 80vh; overflow-y:auto; }

/* ===== 主层 ===== */
#main-layer { background: var(--bg); }

.top-bar {
    display:flex; justify-content:space-between; align-items:center;
    padding: 16px 24px;
    background: rgba(245,240,235,0.9);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border2);
    z-index:100;
}
.brand {
    font-size: 1.2rem; letter-spacing: 0.15em;
    cursor:pointer; transition: opacity 0.2s;
}
.brand:hover { opacity: 0.7; }
.nav-actions {
    display:flex; align-items:center; gap: 12px;
    font-size: 0.85rem; color: var(--text2);
}
.btn-small {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: transparent;
    color: var(--text3);
    font-size: 0.75rem;
    cursor:pointer; transition: all 0.2s;
}
.btn-small:hover { background: var(--bg2); color: var(--text2); }

/* ===== 截面系统 ===== */
.section {
    display:none;
    flex:1; overflow-y:auto;
    padding: 24px;
    animation: fadeIn 0.4s ease;
}
.section.active { display:flex; flex-direction:column; }

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

/* ===== 首页卡牌 ===== */
.card-deck {
    display:grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 24px;
    max-width: 1000px;
    margin: auto;
    padding: 40px 0;
    align-content: center;
}

.char-card {
    aspect-ratio: 3/4;
    border-radius: var(--radius);
    cursor:pointer;
    perspective: 1000px;
    transition: transform 0.35s ease;
}
.char-card:hover { transform: translateY(-8px); }

.card-inner {
    width:100%; height:100%;
    position:relative;
    transform-style: preserve-3d;
    transition: transform 0.6s ease;
}
.char-card.flipped .card-inner { transform: rotateY(180deg); }

.card-front, .card-back {
    position:absolute; inset:0;
    backface-visibility: hidden;
    border-radius: var(--radius);
    overflow:hidden;
    box-shadow: var(--shadow);
}

.card-front {
    background: linear-gradient(160deg, var(--accent, var(--bg2)) 0%, var(--card) 60%);
    display:flex; align-items:center; justify-content:center;
    padding: 24px;
}

.card-back {
    transform: rotateY(180deg);
    background: var(--card);
    padding: 20px;
}

.card-img-placeholder {
    text-align:center;
    display:flex; flex-direction:column;
    align-items:center; gap: 10px;
}
.card-name {
    font-size: 1.6rem; font-weight: 500;
    color: var(--text);
}
.card-romaji {
    font-size: 0.8rem; color: var(--text3);
    letter-spacing: 0.05em;
}
.card-tag {
    font-size: 0.75rem; color: var(--text3);
    padding: 4px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    margin-top: 8px;
}

.placeholder .card-name { color: var(--text3); font-size: 2rem; }

/* 统计卡片 */
.stats-card { display:flex; flex-direction:column; }
.stats-card h3 {
    font-size: 1rem; font-weight: 500;
    text-align:center; margin-bottom: 12px;
}
.stats-card h4 {
    font-size: 0.8rem; color: var(--text2);
    margin: 10px 0 6px;
}
.stats-scroll {
    flex:1; overflow-y:auto;
    padding-right: 4px;
}
.stat-row {
    display:flex; justify-content:space-between;
    padding: 6px 0;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border2);
}
.stat-row span { color: var(--text2); }
.stat-row b { color: var(--text); font-weight: 500; }
.stats-card hr {
    border:none; height:1px;
    background: var(--border2);
    margin: 10px 0;
}

/* ===== 角色页 ===== */
.char-header {
    display:flex; align-items:center; gap: 16px;
    margin-bottom: 20px;
}
.btn-back {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text2);
    cursor:pointer; transition: all 0.2s;
}
.btn-back:hover { background: var(--bg2); }
.char-header h2 {
    font-size: 1.4rem; font-weight: 400;
}

.char-nav {
    display:flex; gap: 8px;
    margin-bottom: 20px;
    flex-wrap:wrap;
}
.nav-pill {
    padding: 10px 20px;
    border:none; border-radius: 24px;
    background: transparent;
    color: var(--text3);
    font-size: 0.85rem;
    cursor:pointer; transition: all 0.2s;
    white-space:nowrap;
}
.nav-pill:hover { background: var(--bg2); color: var(--text2); }
.nav-pill.active {
    background: var(--text); color: var(--card);
}

/* 标签面板 */
.tab-panel {
    display:none;
    animation: fadeIn 0.35s ease;
}
.tab-panel.active { display:block; }

.panel-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

/* 档案 */
.admin-bar {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border2);
}
.btn-admin {
    padding: 6px 14px;
    border: 1px dashed var(--orange);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--orange);
    font-size: 0.8rem;
    cursor:pointer; transition: all 0.2s;
}
.btn-admin:hover { background: rgba(232,168,124,0.08); }

.profile-layout {
    display:grid;
    grid-template-columns: 280px 1fr;
    gap: 28px;
}
.profile-img-box {
    aspect-ratio: 3/4;
    border-radius: var(--radius-sm);
    background: var(--bg2);
    overflow:hidden;
    display:flex; align-items:center; justify-content:center;
}
.img-placeholder {
    color: var(--text3); font-size: 0.9rem;
}
.profile-text { line-height: 1.8; }
.profile-text h3 {
    font-size: 1rem; font-weight: 500;
    margin: 16px 0 8px;
    color: var(--text);
}
.profile-text h3:first-child { margin-top: 0; }
.profile-text p {
    font-size: 0.9rem; color: var(--text2);
}

/* 画廊 */
.gallery-toolbar { margin-bottom: 16px; }
.gallery-toolbar select {
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
    outline:none; cursor:pointer;
}
.gallery-grid {
    display:grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 14px;
}
.gallery-item {
    aspect-ratio: 3/4;
    border-radius: var(--radius-sm);
    overflow:hidden;
    cursor:pointer;
    background: var(--bg2);
    position:relative;
    transition: transform 0.2s;
}
.gallery-item:hover { transform: scale(1.03); }
.gallery-item canvas {
    width:100%; height:100%;
    object-fit: cover;
}
.gallery-item-cap {
    position:absolute; bottom:0; left:0; right:0;
    padding: 10px;
    background: linear-gradient(transparent, rgba(30,25,20,0.6));
    color: var(--card);
    font-size: 0.75rem;
    opacity:0; transition: opacity 0.2s;
}
.gallery-item:hover .gallery-item-cap { opacity:1; }

/* 列表 */
.list-box { display:flex; flex-direction:column; gap: 12px; }
.list-item {
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 18px;
    transition: transform 0.2s;
}
.list-item:hover { transform: translateX(4px); }
.list-item h4 {
    font-size: 1rem; font-weight: 500;
    margin-bottom: 4px;
}
.list-item .meta {
    font-size: 0.75rem; color: var(--text3);
    margin-bottom: 8px;
}
.list-item p {
    font-size: 0.85rem; color: var(--text2);
    line-height: 1.6;
}

/* 时间线 */
.timeline-filters { display:flex; gap: 8px; margin-bottom: 16px; }
.filter-chip {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: transparent;
    color: var(--text3);
    font-size: 0.8rem;
    cursor:pointer; transition: all 0.2s;
}
.filter-chip:hover { background: var(--bg2); }
.filter-chip.active { background: var(--text); color: var(--card); border-color: var(--text); }

.timeline-box {
    position:relative;
    padding-left: 28px;
}
.timeline-box::before {
    content:""; position:absolute;
    left: 6px; top:0; bottom:0;
    width: 2px; background: var(--border);
}
.tl-item {
    position:relative;
    margin-bottom: 20px;
    padding: 16px;
    background: var(--bg);
    border-radius: var(--radius-sm);
}
.tl-item::before {
    content:""; position:absolute;
    left: -26px; top: 20px;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--orange);
    border: 3px solid var(--card);
}
.tl-item.major::before {
    background: #d4a5a5;
    width: 14px; height: 14px;
    left: -28px;
}
.tl-date { font-size: 0.75rem; color: var(--text3); margin-bottom: 6px; }
.tl-title { font-size: 1rem; font-weight: 500; margin-bottom: 6px; }
.tl-desc { font-size: 0.85rem; color: var(--text2); line-height: 1.6; }

/* 小剧场 */
.theater-card { min-height: 400px; display:flex; flex-direction:column; }
.theater-intro {
    flex:1; display:flex;
    flex-direction:column;
    align-items:center; justify-content:center;
    gap: 20px;
}
.theater-intro p { color: var(--text2); font-size: 1.05rem; }

.dialogue-box {
    max-width: 600px; width:100%;
    margin: 0 auto;
}
.dg-line {
    margin-bottom: 16px;
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    animation: fadeIn 0.4s ease;
}
.dg-line.oc {
    margin-left: 40px;
    background: var(--orange2);
}
.dg-line.char {
    margin-right: 40px;
    background: var(--purple2);
}
.dg-speaker {
    font-size: 0.75rem; color: var(--text3);
    margin-bottom: 4px;
}
.dg-text { font-size: 0.95rem; line-height: 1.6; }

.dg-next {
    text-align:center; margin-top: 20px;
}

#theater-result {
    text-align:center;
    padding: 20px;
    border-top: 1px solid var(--border2);
    margin-top: auto;
}
#theater-result p { color: var(--text2); margin-bottom: 12px; }
#result-btns { display:flex; gap: 12px; justify-content:center; }
#result-btns .btn-primary, #result-btns .btn-secondary { width:auto; padding: 10px 28px; }
#result-anon { margin-top: 12px; }
#result-anon input {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    font-size: 0.9rem;
    outline:none; margin-bottom: 8px;
}

/* ===== 画廊弹窗 ===== */
.gallery-modal {
    position:fixed; inset:0; z-index:3000;
    display:flex; align-items:center; justify-content:center;
    background: rgba(30,25,20,0.55);
    backdrop-filter: blur(8px);
}
.gallery-viewer {
    position:relative;
    width: 92%; max-width: 900px;
    display:flex; flex-direction:column;
    align-items:center;
}
.gallery-x {
    position:absolute; top: -44px; right: 0;
    width: 36px; height: 36px;
    border:none; border-radius: 50%;
    background: var(--card); color: var(--text);
    font-size: 1.4rem; cursor:pointer;
    display:flex; align-items:center; justify-content:center;
    box-shadow: var(--shadow);
    z-index: 10;
}
.gallery-x:hover { background: var(--text); color: var(--card); }

.gallery-arrow {
    position:absolute; top: 50%; transform: translateY(-50%);
    width: 42px; height: 42px;
    border:none; border-radius: 50%;
    background: var(--card); color: var(--text);
    font-size: 1.5rem; cursor:pointer;
    display:flex; align-items:center; justify-content:center;
    box-shadow: var(--shadow);
    z-index: 10; transition: all 0.2s;
}
.gallery-arrow:hover { background: var(--text); color: var(--card); }
.gallery-left { left: -56px; }
.gallery-right { right: -56px; }

.gallery-canvas-wrap {
    width:100%; max-height: 68vh;
    display:flex; align-items:center; justify-content:center;
    border-radius: var(--radius-sm);
    overflow:hidden;
    background: var(--card);
    box-shadow: var(--shadow-lg);
}
.gallery-canvas-wrap canvas {
    max-width:100%; max-height: 68vh;
    object-fit: contain;
}

.gallery-caption {
    margin-top: 14px;
    color: var(--card);
    font-size: 0.95rem;
    text-shadow: 0 1px 4px rgba(0,0,0,0.3);
    text-align:center;
}

.gallery-dots {
    display:flex; gap: 8px;
    margin-top: 16px;
    padding: 6px;
}
.gallery-dots span {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: rgba(255,255,255,0.35);
    cursor:pointer; transition: all 0.2s;
}
.gallery-dots span.active {
    background: var(--card);
    transform: scale(1.3);
}

/* ===== 表单 ===== */
.form-group { margin-bottom: 14px; text-align:left; }
.form-group label {
    display:block; font-size: 0.8rem;
    color: var(--text2); margin-bottom: 5px;
}
.form-group input,
.form-group textarea,
.form-group select {
    width:100%; padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
    outline:none; font-family: inherit;
}
.form-group textarea { min-height: 80px; resize:vertical; }
.form-btns { margin-top: 20px; display:flex; gap: 10px; justify-content:center; }
.form-btns .btn-primary, .form-btns .btn-secondary { width:auto; min-width: 90px; }

/* ===== 响应式 ===== */
@media (max-width: 768px) {
    .card-deck { grid-template-columns: 1fr; max-width: 300px; }
    .profile-layout { grid-template-columns: 1fr; }
    .profile-img-box { max-width: 220px; margin: 0 auto; }
    .char-nav { gap: 6px; }
    .nav-pill { padding: 8px 14px; font-size: 0.8rem; }
    .gallery-left { left: 8px; }
    .gallery-right { right: 8px; }
    .gallery-arrow { width: 36px; height: 36px; font-size: 1.2rem; }
    .section { padding: 16px; }
    .site-title { font-size: 2rem; }
    .top-bar { padding: 12px 16px; }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .card-deck { grid-template-columns: repeat(2, 1fr); max-width: 600px; }
}

/* 滚动条 */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }


/* ===== 桌面宠物 ===== */
#pet-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 500;
}

.pet-char {
    position: fixed;
    width: 80px;
    height: 120px;
    cursor: grab;
    pointer-events: auto;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    transition: transform 0.1s;
    z-index: 501;
}

.pet-char:active {
    cursor: grabbing;
}

.pet-char img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    -webkit-user-drag: none;
}

/* 占位图样式 */
.pet-placeholder {
    width: 100%;
    height: 100%;
    border-radius: 50% 50% 45% 45%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    color: rgba(255,255,255,0.9);
    text-align: center;
    line-height: 1.3;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.pet-sugizawa .pet-placeholder {
    background: linear-gradient(135deg, #e8a87c 0%, #d4956a 100%);
}

.pet-minazuki .pet-placeholder {
    background: linear-gradient(135deg, #c4a8d0 0%, #b090c0 100%);
}

/* 气泡 */
.pet-bubble {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--card);
    color: var(--text);
    padding: 8px 14px;
    border-radius: 14px;
    font-size: 0.78rem;
    white-space: nowrap;
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    margin-bottom: 8px;
    max-width: 200px;
    white-space: normal;
    text-align: center;
    line-height: 1.4;
}

.pet-bubble::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--card);
}

.pet-bubble.show {
    opacity: 1;
}

/* 爱心动画 */
.pet-heart {
    position: fixed;
    pointer-events: none;
    z-index: 9999;
    font-size: 20px;
    opacity: 0;
    transform: translate(-50%, -50%) scale(0);
    transition: transform 1.2s ease-out, opacity 1.2s ease-out;
}
