/* 張家女子宿舍服務中心 — 奶茶色設計系統（所有頁面共用）
   像剛裝潢好的新家：溫暖、乾淨、有生活感。每個動態都在說一件事，不為了動而動。
   夜間（或手機深色模式）由 theme.js 在 <html> 加 data-theme="dark"，換成黑糖色。 */

:root {
  /* 色票 */
  --cream: #FAF6F0;      /* 奶霜：頁面背景 */
  --oat: #F2E8DC;        /* 燕麥：卡片、區塊 */
  --tea: #C8A27A;        /* 奶茶：主色、選取 */
  --caramel: #8B6544;    /* 焦糖：按鈕、強調 */
  --caramel-press: #6B4C32;
  --cocoa: #4A3426;      /* 可可：文字 */
  --cocoa-soft: #6F5440; /* 次要文字（在奶霜上 6.4:1） */
  --peach: #E9A88F;      /* 蜜桃：通知、愛心 */
  --matcha: #8FA876;     /* 抹茶：正常 */
  --redbean: #B5524A;    /* 紅豆：只用在 SOS 與緊急 */
  --brown-sugar: #2B211B;/* 黑糖：夜間背景 */
  --orange: #C46A1E;     /* 低電量 */

  /* 語意 token（深色模式只換這一組） */
  --bg: var(--cream);
  --surface: #FFFFFF;
  --surface-2: var(--oat);
  --surface-3: #EADBC8;
  --text: var(--cocoa);
  --text-soft: var(--cocoa-soft);
  --line: #E5D6C3;
  --line-strong: #D5BFA4;
  --primary: var(--caramel);
  --primary-press: var(--caramel-press);
  --on-primary: var(--cream);
  --accent: var(--tea);
  --ok: #5E7D45;
  --ok-soft: #E3ECD7;
  --warn: #9A5A12;
  --warn-soft: #F7E6CC;
  --danger: var(--redbean);
  --danger-soft: #F6DCD8;
  --shadow-1: 0 4px 12px rgba(139, 101, 68, .10);
  --shadow-2: 0 10px 28px rgba(139, 101, 68, .14);
  --shadow-3: 0 18px 44px rgba(74, 52, 38, .20);
  --focus: 0 0 0 3px rgba(200, 162, 122, .55);

  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 20px;
  --r-xl: 24px;
  --r-2xl: 28px;

  --font-display: "DormRound", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --font-body: "Noto Sans TC", "Source Han Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --ease-pop: cubic-bezier(.34, 1.56, .64, 1);
  --ease-out: cubic-bezier(.22, 1, .36, 1);

  /* 家人代表色（配料系列）：主色、淺底、軌跡淺、軌跡深 */
  --salt: #5B8DB8; --salt-tint: #DCE7F1; --salt-light: #C9DCEC; --salt-deep: #2F5578;
  --peachy: #D9735A; --peachy-tint: #F8DDD3; --peachy-light: #F6D2C6; --peachy-deep: #9B4632;
  --matchag: #7BA05B; --matchag-tint: #E3ECD7; --matchag-light: #D5E4C6; --matchag-deep: #4A6B34;
  --taro: #9A7BB8; --taro-tint: #E9E0F1; --taro-light: #E3D8EE; --taro-deep: #63487F;
  --honey: #C08A1E; --honey-tint: #F5E8C8; --honey-light: #EFDDB0; --honey-deep: #7F5C14;
  --rose: #C46B8A; --rose-tint: #F4DCE5; --rose-light: #EDC7D5; --rose-deep: #873E59;

  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: var(--brown-sugar);
  --surface: #3A2C23;
  --surface-2: #45352A;
  --surface-3: #524033;
  --text: #F5EADC;
  --text-soft: #D6C1A8;
  --line: #5A4636;
  --line-strong: #6E5644;
  --primary: var(--tea);
  --primary-press: #A9845D;
  --on-primary: var(--brown-sugar);
  --ok: #A9C68F;
  --ok-soft: #36412C;
  --warn: #E9B46A;
  --warn-soft: #4A3820;
  --danger: #E28377;
  --danger-soft: #4C2A26;
  --shadow-1: 0 4px 12px rgba(0, 0, 0, .25);
  --shadow-2: 0 10px 28px rgba(0, 0, 0, .32);
  --shadow-3: 0 18px 44px rgba(0, 0, 0, .45);
  --salt-tint: #2E3D4B; --peachy-tint: #4A2F27; --matchag-tint: #33402A; --taro-tint: #3D3248; --honey-tint: #4A3C1C; --rose-tint: #4A2C38;
  color-scheme: dark;
}

/* ---------- 基礎 ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; } /* 元件的 display 不能蓋過 hidden */
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  /* 極淡的紙張紋理 */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .55 0 0 0 0 .4 0 0 0 0 .27 0 0 0 .05 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  color: var(--text);
  font: 16px/1.6 var(--font-body);
  -webkit-font-smoothing: antialiased;
  transition: background-color .4s ease, color .4s ease;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 400; line-height: 1.25; margin: 0; letter-spacing: .01em; }
h1 { font-size: clamp(26px, 6vw, 34px); }
h2 { font-size: 22px; }
h3 { font-size: 19px; }
p { margin: 0 0 12px; }
a { color: var(--primary); text-underline-offset: 3px; }
a:hover { color: var(--text); }
code { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: .9em; background: var(--surface-2); padding: .1em .4em; border-radius: 6px; overflow-wrap: anywhere; }
img { max-width: 100%; }
:focus-visible { outline: none; box-shadow: var(--focus); }
::selection { background: var(--tea); color: var(--cocoa); }
.muted { color: var(--text-soft); }
.small { font-size: 14px; }
.display { font-family: var(--font-display); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* ---------- 按鈕：按下往下壓 4px 再彈回 ---------- */
.btn {
  --btn-bg: var(--primary); --btn-fg: var(--on-primary); --btn-edge: var(--primary-press);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 22px; border: 0; border-radius: 999px;
  background: var(--btn-bg); color: var(--btn-fg); box-shadow: 0 4px 0 var(--btn-edge);
  font: 17px/1 var(--font-display); text-decoration: none; cursor: pointer;
  transition: transform .12s var(--ease-out), box-shadow .12s var(--ease-out), background .2s ease;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:hover { color: var(--btn-fg); filter: brightness(1.04); }
.btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--btn-edge); }
.btn:disabled, .btn[aria-busy="true"] { opacity: .6; cursor: wait; transform: none; }
.btn.small { min-height: 40px; padding: 0 16px; font-size: 15px; }
.btn.block { width: 100%; }
.btn.outline { --btn-bg: transparent; --btn-fg: var(--text); --btn-edge: transparent; box-shadow: inset 0 0 0 2px var(--tea); }
.btn.outline:active { transform: translateY(2px); box-shadow: inset 0 0 0 2px var(--tea); }
.btn.soft { --btn-bg: var(--surface-2); --btn-fg: var(--text); --btn-edge: var(--line-strong); }
.btn.danger { --btn-bg: var(--redbean); --btn-fg: #fff; --btn-edge: #8A3A33; }
.btn.ok { --btn-bg: var(--ok-soft); --btn-fg: var(--ok); --btn-edge: #C6D6B4; }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 22px; display: inline-grid; place-items: center;
  background: var(--surface-2); color: var(--text); cursor: pointer; transition: transform .15s var(--ease-pop);
}
.icon-btn:active { transform: scale(.9); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- 卡片與版面 ---------- */
.card { background: var(--surface); border-radius: var(--r-xl); padding: 20px; box-shadow: var(--shadow-1); }
.card.oat { background: var(--surface-2); box-shadow: none; }
.card + .card { margin-top: 16px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: 14px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--text-soft); margin: 18px 0; font-size: 14px; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

/* ---------- 表單 ---------- */
label.field { display: grid; gap: 6px; margin-bottom: 14px; font-weight: 600; }
label.field small { font-weight: 400; color: var(--text-soft); }
.input, input[type=text], input[type=password], input[type=email], input:not([type]), select, textarea {
  font: inherit; width: 100%; min-height: 48px; padding: 10px 14px;
  border: 2px solid var(--line); border-radius: var(--r-md); background: var(--surface); color: var(--text);
  transition: border-color .2s ease, box-shadow .2s ease;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--tea); box-shadow: var(--focus); }
input::placeholder { color: var(--text-soft); opacity: .7; }

/* 開關 */
.switch { position: relative; display: inline-flex; align-items: center; gap: 12px; cursor: pointer; font-weight: 600; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 56px; height: 32px; border-radius: 16px; background: var(--surface-3); position: relative; transition: background .25s ease; flex: none; }
.switch .track::after { content: ""; position: absolute; left: 4px; top: 4px; width: 24px; height: 24px; border-radius: 12px; background: #fff; box-shadow: 0 2px 6px rgba(74, 52, 38, .25); transition: transform .3s var(--ease-pop); }
.switch input:checked + .track { background: var(--matcha); }
.switch input:checked + .track::after { transform: translateX(24px); }
.switch input:focus-visible + .track { box-shadow: var(--focus); }

/* 分頁（藥丸） */
.pills { display: flex; gap: 6px; padding: 6px; border-radius: 999px; background: var(--surface-2); overflow-x: auto; scrollbar-width: none; }
.pills::-webkit-scrollbar { display: none; }
.pills button { flex: 0 0 auto; min-height: 40px; padding: 0 16px; border: 0; border-radius: 999px; background: transparent; color: var(--text-soft); font: 15px/1 var(--font-display); cursor: pointer; transition: background .25s ease, color .25s ease; }
.pills button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

/* 標籤 */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--surface-2); color: var(--text-soft); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.wait { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.tea { background: var(--tea); color: var(--cocoa); }

/* 提示框 */
.note { padding: 12px 16px; border-radius: var(--r-md); background: var(--surface-2); font-size: 15px; }
.note strong { display: block; margin-bottom: 2px; font-family: var(--font-display); font-weight: 400; font-size: 17px; }
.error { color: var(--danger); min-height: 1.4em; margin: 4px 0 10px; font-weight: 600; }

/* ---------- 頭像 ---------- */
.avatar {
  --c: var(--tea); --tint: var(--surface-2); --size: 54px; --border: 3px;
  position: relative; width: var(--size); height: var(--size); flex: none; border-radius: 50%;
  display: grid; place-items: center; background: var(--tint); box-shadow: inset 0 0 0 var(--border) var(--c);
  font: calc(var(--size) * .4)/1 var(--font-display); color: var(--cocoa);
}
:root[data-theme="dark"] .avatar { color: var(--text); }
.avatar img { width: calc(100% - var(--border) * 2); height: calc(100% - var(--border) * 2); border-radius: 50%; object-fit: cover; display: block; }
.avatar .emoji { font-size: calc(var(--size) * .5); line-height: 1; font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; }
.avatar.xs { --size: 28px; --border: 2px; }
.avatar.sm { --size: 40px; --border: 3px; }
.avatar.lg { --size: 72px; --border: 4px; }
.avatar.xl { --size: 96px; --border: 5px; }
/* 電量環：低電量時外框變成進度環，低於 15% 轉焦糖橘 */
.avatar.battery { background: conic-gradient(var(--batt-color, var(--tea)) 0 var(--batt, 100%), var(--surface-3) var(--batt, 100%) 100%); box-shadow: none; }
.avatar.battery::before { content: ""; position: absolute; inset: var(--border); border-radius: 50%; background: var(--tint); }
.avatar.battery > * { position: relative; }
.avatar.battery.critical { --batt-color: var(--orange); }
.avatar.battery.breathe { animation: none; } /* 低電量時電池環優先，不疊呼吸光圈 */
.avatar.paused { filter: grayscale(.85); opacity: .7; }
.avatar.paused::after { content: "⏸"; position: absolute; right: -4px; bottom: -4px; width: 22px; height: 22px; border-radius: 11px; display: grid; place-items: center; background: var(--surface); color: var(--text-soft); font-size: 11px; box-shadow: var(--shadow-1); }
.avatar.stale img, .avatar.stale > span { opacity: .55; }
.avatar .badge-icon {
  position: absolute; right: -5px; bottom: -5px; width: 24px; height: 24px; border-radius: 12px;
  display: grid; place-items: center; background: var(--surface); box-shadow: inset 0 0 0 2px var(--c), var(--shadow-1);
}
.avatar .badge-icon svg { width: 13px; height: 13px; stroke: var(--c); }
/* 靜止：外圈緩慢呼吸 */
.avatar.breathe { animation: milk-breathe 2.8s ease-in-out infinite; }
@keyframes milk-breathe { 0%, 100% { box-shadow: inset 0 0 0 var(--border) var(--c), 0 0 0 0 color-mix(in srgb, var(--c) 45%, transparent); } 50% { box-shadow: inset 0 0 0 var(--border) var(--c), 0 0 0 12px color-mix(in srgb, var(--c) 0%, transparent); } }
/* 到家：輕跳一下 */
.avatar.hop { animation: milk-hop .9s var(--ease-pop); }
@keyframes milk-hop { 0% { transform: translateY(0); } 35% { transform: translateY(-14px) scale(1.06); } 70% { transform: translateY(0) scale(.97); } 100% { transform: none; } }
.avatar.pop { animation: milk-pop .45s var(--ease-pop) both; }
@keyframes milk-pop { 0% { transform: scale(.6); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

/* 家人代表色 */
.c-salt { --c: var(--salt); --tint: var(--salt-tint); --c-light: var(--salt-light); --c-deep: var(--salt-deep); }
.c-peach { --c: var(--peachy); --tint: var(--peachy-tint); --c-light: var(--peachy-light); --c-deep: var(--peachy-deep); }
.c-matcha { --c: var(--matchag); --tint: var(--matchag-tint); --c-light: var(--matchag-light); --c-deep: var(--matchag-deep); }
.c-taro { --c: var(--taro); --tint: var(--taro-tint); --c-light: var(--taro-light); --c-deep: var(--taro-deep); }
.c-honey { --c: var(--honey); --tint: var(--honey-tint); --c-light: var(--honey-light); --c-deep: var(--honey-deep); }
.c-rose { --c: var(--rose); --tint: var(--rose-tint); --c-light: var(--rose-light); --c-deep: var(--rose-deep); }

/* ---------- 進場：卡片依序滑入 ---------- */
.rise > * { animation: milk-rise .55s var(--ease-out) both; }
.rise > *:nth-child(2) { animation-delay: .06s; }
.rise > *:nth-child(3) { animation-delay: .12s; }
.rise > *:nth-child(4) { animation-delay: .18s; }
.rise > *:nth-child(5) { animation-delay: .24s; }
.rise > *:nth-child(n+6) { animation-delay: .3s; }
@keyframes milk-rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.view-enter { animation: milk-slide .38s var(--ease-out) both; }
.view-enter.back { animation-name: milk-slide-back; }
@keyframes milk-slide { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes milk-slide-back { from { opacity: 0; transform: translateX(-24px); } to { opacity: 1; transform: none; } }

/* ---------- 吐司 ---------- */
.toast-host { position: fixed; left: 50%; top: max(16px, env(safe-area-inset-top)); transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; width: min(420px, calc(100% - 32px)); }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-radius: var(--r-lg); background: var(--cocoa); color: var(--cream); font: 16px/1.4 var(--font-display); box-shadow: var(--shadow-3); animation: milk-toast .4s var(--ease-pop) both; pointer-events: auto; }
:root[data-theme="dark"] .toast { background: var(--oat); color: var(--cocoa); }
.toast.out { animation: milk-toast-out .3s ease-in both; }
.toast.bad { background: var(--redbean); color: #fff; }
@keyframes milk-toast { from { opacity: 0; transform: translateY(-16px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes milk-toast-out { to { opacity: 0; transform: translateY(-10px); } }

/* ---------- 愛心、彩帶 ---------- */
.heart-float { position: fixed; z-index: 90; pointer-events: none; color: var(--peach); font-size: 20px; animation: milk-heart 1.6s ease-out both; }
@keyframes milk-heart { 0% { transform: translateY(0) scale(.5); opacity: 0; } 25% { opacity: 1; } 100% { transform: translateY(-70px) scale(1.15); opacity: 0; } }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 95; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 3px; animation: milk-confetti var(--d, 2.4s) cubic-bezier(.3, .6, .5, 1) var(--delay, 0s) both; }
@keyframes milk-confetti { 0% { transform: translate3d(0, 0, 0) rotate(0); opacity: 1; } 100% { transform: translate3d(var(--dx, 0), 105vh, 0) rotate(var(--rot, 540deg)); opacity: .9; } }

/* ---------- 載入動畫：奶茶裡的珍珠慢慢沉下去 ---------- */
.cup-loader { display: grid; place-items: center; gap: 14px; padding: 40px 0; color: var(--text-soft); font-family: var(--font-display); }
.cup { position: relative; width: 64px; height: 76px; }
.cup .straw { position: absolute; left: 38px; top: -8px; width: 7px; height: 34px; border-radius: 4px; background: var(--peach); transform: rotate(12deg); }
.cup .body { position: absolute; left: 4px; top: 14px; width: 56px; height: 60px; border-radius: 6px 6px 20px 20px; background: var(--surface-3); box-shadow: inset 0 0 0 3px var(--caramel); overflow: hidden; }
.cup .tea-fill { position: absolute; left: 3px; right: 3px; bottom: 3px; top: 16px; border-radius: 3px 3px 17px 17px; background: var(--tea); opacity: .55; }
.cup .pearl { position: absolute; top: 18px; width: 10px; height: 10px; border-radius: 5px; background: var(--cocoa); animation: milk-sink 2.6s ease-in infinite; }
.cup .pearl:nth-child(3) { left: 12px; }
.cup .pearl:nth-child(4) { left: 24px; animation-delay: .55s; }
.cup .pearl:nth-child(5) { left: 36px; animation-delay: 1.1s; }
@keyframes milk-sink { 0% { transform: translateY(-6px); opacity: 0; } 18% { opacity: 1; } 100% { transform: translateY(30px); opacity: 1; } }
.steam { position: absolute; top: -2px; width: 4px; height: 10px; border-radius: 2px; background: var(--tea); animation: milk-steam 2.4s ease-in-out infinite; }
.steam.s1 { left: 20px; }
.steam.s2 { left: 32px; animation-delay: .8s; }
@keyframes milk-steam { 0% { transform: translateY(3px); opacity: 0; } 50% { opacity: .75; } 100% { transform: translateY(-9px); opacity: 0; } }

/* ---------- 空白頁：打瞌睡的小貓 ---------- */
.empty { display: grid; justify-items: center; gap: 8px; padding: 26px 12px; text-align: center; color: var(--text-soft); }
.empty svg { width: 120px; height: 84px; }
.empty .z { animation: milk-z 2.6s ease-in-out infinite; transform-box: fill-box; }
.empty .z:nth-of-type(2) { animation-delay: .9s; }
@keyframes milk-z { 0% { opacity: 0; transform: translate(0, 4px); } 40% { opacity: 1; } 100% { opacity: 0; transform: translate(6px, -10px); } }
.empty strong { font-family: var(--font-display); font-weight: 400; font-size: 18px; color: var(--text); }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 11px 10px; border-top: 1px solid var(--line); vertical-align: top; }
th { color: var(--text-soft); font-weight: 600; border-top: 0; font-size: 14px; }

/* ---------- 減少動態：只留淡入淡出 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .rise > *, .view-enter, .toast, .avatar.pop { animation: milk-fade .3s ease both !important; }
  .confetti, .heart-float, .cup .pearl, .steam, .empty .z { display: none; }
}
@keyframes milk-fade { from { opacity: 0; } to { opacity: 1; } }
