/* ========== 紀念冊檢視頁：懷舊紙本風 ========== */

:root {
    --paper: #F2EADB;
    --card: #FBF7EF;
    --ink: #2E2620;
    --ink-soft: #4E3F2F;
    --muted: #6B5B4A;
    --line: #D9CBB3;
    --line-strong: #B8A68A;
    --rust: #9C4A2F;
    --rust-dark: #7A3824;
    --nav: #EBE0CC;
    --error: #A3261B;
    --stripe-1: #D8C7A8;
    --stripe-2: #CDBA97;

    --serif: 'Noto Serif TC', serif;
    --hand: 'LXGW WenKai TC', 'Noto Serif TC', serif;
    --sans: 'Noto Sans TC', sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
    background: var(--paper);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 18px;
    line-height: 1.6;
    -webkit-text-size-adjust: 100%;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--rust); }
a:hover { color: var(--rust-dark); }
.hidden { display: none !important; }

:focus-visible { outline: 3px solid var(--rust); outline-offset: 2px; }

/* ---------- 頂部列 ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px 8px 20px;
    background: rgba(242, 234, 219, 0.96);
    border-bottom: 1px solid var(--line);
}

.topbar-title {
    font-family: var(--serif);
    font-weight: 700;
    font-size: 17px;
    letter-spacing: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-actions { display: flex; gap: 4px; flex-shrink: 0; }

.icon-btn {
    min-width: 44px;
    height: 44px;
    padding: 0 10px;
    border: 0;
    border-radius: 22px;
    background: transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 15px;
    color: var(--ink);
}
.icon-btn:hover { background: rgba(46, 38, 32, 0.08); }
.icon-btn svg { width: 22px; height: 22px; }
#refreshBtn { min-width: 84px; }   /* 文字變成「更新中」時按鈕不跳動 */
#refreshBtn.is-loading svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 內容區 ---------- */
main {
    max-width: 720px;
    margin: 0 auto;
    padding: 20px 20px 160px;
}

/* ---------- 按鈕 ---------- */
.btn-primary, .btn-accent {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 58px;
    padding: 0 32px;
    border: 0;
    border-radius: 29px;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 3px;
    text-decoration: none;
}
.btn-primary { background: var(--ink); color: #FBF7EF; }
.btn-accent { background: var(--rust); color: #FFFFFF; }
.btn-primary:hover { background: #45392F; color: #FBF7EF; }
.btn-accent:hover { background: var(--rust-dark); color: #FFFFFF; }
.btn-primary:disabled, .btn-accent:disabled { opacity: 0.6; cursor: wait; }
.btn-primary svg, .btn-accent svg { width: 22px; height: 22px; flex-shrink: 0; }

.btn-outline {
    min-height: 62px;
    border: 2px solid var(--ink);
    border-radius: 14px;
    background: var(--card);
    color: var(--ink);
    font-size: 18px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 12px;
}
.btn-outline svg { width: 24px; height: 24px; flex-shrink: 0; }
.btn-outline[aria-pressed="true"] { background: var(--ink); color: #FBF7EF; }

/* ---------- 拍立得照片（寫留言時的照片預覽；內容頁的樣式在 book.js） ---------- */
.polaroid {
    margin: 0;
    background: #FFFFFF;
    padding: 10px 10px 12px;
    box-shadow: 0 2px 6px rgba(46, 38, 32, 0.18);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.polaroid img {
    display: block;
    width: 100%;
    object-fit: cover;
    background: repeating-linear-gradient(45deg, var(--stripe-1) 0 10px, var(--stripe-2) 10px 20px);
    cursor: zoom-in;
}
.polaroid figcaption {
    font-family: var(--hand);
    font-size: 17px;
    color: var(--ink-soft);
    text-align: center;
    word-break: break-word;
}

/* ---------- 浮動「寫留言」按鈕 ---------- */
.fab {
    position: fixed;
    right: max(20px, calc(50% - 340px));
    bottom: calc(92px + env(safe-area-inset-bottom));
    z-index: 25;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 58px;
    padding: 0 24px 0 20px;
    border: 0;
    border-radius: 29px;
    background: var(--rust);
    color: #FFFFFF;
    font-size: 19px;
    font-weight: 700;
    letter-spacing: 2px;
    box-shadow: 0 4px 12px rgba(46, 38, 32, 0.3);
}
.fab:hover { background: var(--rust-dark); }
.fab svg { width: 22px; height: 22px; }

/* ---------- 底部章節列 ---------- */
.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    background: var(--nav);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav-inner {
    display: flex;
    max-width: 720px;
    margin: 0 auto;
    overflow-x: auto;
    scrollbar-width: none;
}
.bottom-nav-inner::-webkit-scrollbar { display: none; }
.nav-tab {
    flex: 1 0 60px;
    min-height: 70px;
    padding: 8px 2px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    white-space: nowrap;
}
.nav-tab svg { width: 24px; height: 24px; }
.nav-tab[aria-current="page"] { color: var(--rust); font-weight: 700; }

/* ---------- 尚未載入（離線模式） ---------- */
.load-prompt { display: flex; flex-direction: column; align-items: center; gap: 20px; padding: 64px 16px; text-align: center; }
.load-prompt p { margin: 0; font-family: var(--hand); font-size: 22px; color: var(--ink-soft); }

/* ---------- 登入（common.js 產生） ---------- */
.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: var(--paper);
    overflow-y: auto;
    display: flex;
    justify-content: center;
    padding: 64px 24px 32px;
}
.login-box { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 16px; }
.login-box::before {
    content: "1977";
    align-self: center;
    width: 108px;
    height: 108px;
    border-radius: 50%;
    border: 2px solid var(--rust);
    color: var(--rust);
    font-family: var(--serif);
    font-weight: 900;
    font-size: 30px;
    letter-spacing: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 4px;
}
.login-title {
    font-family: var(--serif);
    font-weight: 900;
    font-size: 34px;
    letter-spacing: 4px;
    text-align: center;
}
.login-hint {
    font-family: var(--hand);
    font-size: 20px;
    line-height: 1.7;
    color: var(--ink-soft);
    text-align: center;
    margin-bottom: 8px;
}
.login-error { min-height: 24px; color: var(--error); font-size: 16px; text-align: center; }
.form-btn-submit {
    min-height: 58px;
    border: 0;
    border-radius: 29px;
    background: var(--ink);
    color: #FBF7EF;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 3px;
}
.form-btn-submit:disabled { opacity: 0.6; cursor: wait; }

/* ---------- 表單欄位 ---------- */
.field { display: flex; flex-direction: column; gap: 8px; }
.field label { font-size: 19px; font-weight: 700; }
.form-input {
    width: 100%;
    min-height: 58px;
    border: 2px solid var(--line-strong);
    border-radius: 12px;
    background: var(--card);
    padding: 0 16px;
    font-size: 20px;
}
textarea.form-input {
    min-height: 190px;
    padding: 14px 16px;
    font-family: var(--hand);
    line-height: 1.7;
    resize: vertical;
}

/* ---------- 寫留言（全螢幕表單） ---------- */
.sheet {
    position: fixed;
    inset: 0;
    z-index: 90;
    background: var(--paper);
    overflow-y: auto;
}
.sheet-inner { max-width: 560px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }
.sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 12px 12px 24px;
    border-bottom: 1px solid var(--line);
}
.sheet-head h1 { margin: 0; font-family: var(--serif); font-weight: 900; font-size: 28px; letter-spacing: 4px; }
.sheet-form { flex-grow: 1; display: flex; flex-direction: column; gap: 20px; padding: 22px 24px 28px; }
.media-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.sheet-note { font-size: 16px; color: var(--muted); line-height: 1.6; margin: 0; }
.sheet-status { font-size: 16px; color: var(--ink-soft); min-height: 24px; }
.sheet-preview-photo { width: min(100%, 260px); transform: rotate(-1deg); }
.sheet-preview-photo img { max-height: 260px; cursor: default; }
.sheet-audio { width: 100%; }
.sheet-submit { width: 100%; }

/* ---------- 看大圖 ---------- */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(20, 16, 12, 0.94);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 56px 12px 24px;
}
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 52px;
    height: 52px;
    border: 0;
    border-radius: 26px;
    background: rgba(251, 247, 239, 0.15);
    color: #FBF7EF;
    display: flex;
    align-items: center;
    justify-content: center;
}
.lightbox-close svg { width: 28px; height: 28px; }

/* ---------- 目錄 ---------- */
.toc-heading { margin: 26px 4px 12px; font-family: var(--serif); font-weight: 700; font-size: 21px; letter-spacing: 3px; }
.toc-list { display: flex; flex-direction: column; gap: 10px; }
.toc-item { display: flex; align-items: center; gap: 12px; min-height: 58px; padding: 0 18px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); font-size: 19px; text-align: left; }
.toc-item svg { width: 24px; height: 24px; color: var(--rust); flex-shrink: 0; }
.toc-item:hover, .toc-class:hover { border-color: var(--rust); }
.toc-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 600px) { .toc-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.toc-class { min-height: 64px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); font-family: var(--serif); font-weight: 700; font-size: 19px; letter-spacing: 1px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.toc-class.is-mine { border: 2px solid var(--rust); }
.toc-class.is-empty { color: var(--muted); border-style: dashed; font-weight: 500; }
.toc-class small { font-family: var(--sans); font-weight: 400; font-size: 13px; letter-spacing: 0; }
.toc-mine { font-family: var(--sans); font-weight: 700; font-size: 13px; color: #FFFFFF; background: var(--rust); border-radius: 10px; padding: 0 8px; letter-spacing: 0; }
.toc-submit { width: 100%; margin-top: 28px; }
.toc-footer { margin-top: 36px; padding-top: 16px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.toc-who { margin: 0; color: var(--muted); font-size: 16px; }
.toc-logout { min-height: 44px; padding: 0 20px; border: 1px solid var(--line-strong); border-radius: 22px; background: transparent; font-size: 16px; }

/* ---------- 投稿照片 ---------- */
.photo-picks { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.photo-pick { position: relative; padding: 6px; }
.photo-pick img { aspect-ratio: 1 / 1; cursor: default; }
.photo-pick-remove { position: absolute; top: -10px; right: -10px; width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--error); background: var(--card); color: var(--error); display: flex; align-items: center; justify-content: center; padding: 0; }
.photo-pick-remove svg { width: 16px; height: 16px; }

/* ---------- 同學登入：選班級 ---------- */
select.form-input { appearance: auto; }
.login-switch { align-self: center; min-height: 44px; padding: 0 12px; border: 0; background: transparent; color: var(--muted); font-size: 16px; text-decoration: underline; }

/* ---------- 時光走廊：選擇頁與子頁切換 ---------- */
.hub-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.hub-card {
    display: flex; flex-direction: column; align-items: stretch; gap: 6px;
    padding: 10px 10px 14px; border: 0; border-radius: 4px;
    background: #FFFFFF; color: var(--ink); text-align: center;
    box-shadow: 0 2px 8px rgba(46, 38, 32, 0.16);
}
.hub-card:nth-child(odd) { transform: rotate(-1deg); }
.hub-card:nth-child(even) { transform: rotate(1deg); }
.hub-card img, .hub-empty { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--line); }
.hub-empty { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.hub-empty svg { width: 40px; height: 40px; }
.hub-name { margin-top: 6px; font-family: var(--serif); font-weight: 700; font-size: 20px; letter-spacing: 2px; }
.hub-count { font-size: 16px; color: var(--muted); }
.hub-card:hover { box-shadow: 0 4px 14px rgba(156, 74, 47, 0.3); }

.gallery-switch { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; }
.gallery-chip {
    min-width: 56px; min-height: 44px; padding: 0 16px;
    border: 1px solid var(--line); border-radius: 22px;
    background: var(--card); color: var(--ink); font-size: 18px;
}
.gallery-chip[aria-current="page"] { background: var(--ink); border-color: var(--ink); color: #FFFFFF; font-weight: 700; }
.hub-quote { width: 100%; aspect-ratio: 1; overflow: hidden; display: flex; align-items: center; justify-content: center; padding: 14px; background: var(--card); border: 1px solid var(--line); }
.hub-quote span { font-family: 'LXGW WenKai TC', var(--serif); font-size: 17px; line-height: 1.6; color: var(--ink-soft); text-align: left; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; }
.hub-quote.is-wall { background-color: #8E4129; border: 0;
    background-image: linear-gradient(rgba(255,255,255,0.10) 2px, transparent 2px), linear-gradient(90deg, rgba(255,255,255,0.10) 2px, transparent 2px);
    background-size: 100% 26px, 52px 52px; }
.hub-quote.is-wall span { background: #FBF4DC; padding: 10px 10px 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.3); transform: rotate(-2deg); color: var(--ink); }
