:root {
  --bg: #FFF6E6;
  --card: #FFFFFF;
  --ink: #5A4332;
  --ink-soft: #8C7563;
  --line: #F1E2CC;
  --sun: #F7B733;
  --sun-deep: #E8833A;
  --sun-pale: #FBE7C2;
  --green: #7FB77E;
  --danger: #C8553D;
  --radius: 18px;
  --font: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.6;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  min-height: 100vh;
}
.hidden { display: none !important; }
.muted { color: var(--ink-soft); }
.tiny { font-size: 13px; }
.center { text-align: center; }

/* 頁首 */
.app-head {
  padding: calc(14px + env(safe-area-inset-top)) 20px 6px;
  max-width: 560px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 22px; margin: 0; letter-spacing: 2px; font-weight: 700; }
.sun-mark {
  width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, #FFD66B, var(--sun) 60%, var(--sun-deep));
  box-shadow: 0 0 0 4px rgba(247,183,51,.18), 0 0 0 8px rgba(247,183,51,.08);
}
.head-sub { margin: 4px 0 0 36px; font-size: 14px; color: var(--ink-soft); min-height: 1em; }

main { max-width: 560px; margin: 0 auto; padding: 8px 16px 16px; }

/* 卡片 */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 18px;
  margin-bottom: 14px;
  box-shadow: 0 2px 0 var(--line), 0 6px 18px rgba(170,120,60,.08);
}
.card h2 { font-size: 18px; margin: 0 0 6px; }
.welcome-title { font-size: 20px; font-weight: 700; margin: 0 0 6px; }

label { display: block; font-weight: 600; font-size: 15px; margin: 14px 0 6px; }
input[type=text], input[type=date], input[type=month], textarea, .happy-input {
  width: 100%;
  font: inherit; font-size: 16px; color: var(--ink);
  background: #FFFCF6;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  outline: none;
  -webkit-appearance: none; appearance: none;
  min-height: 44px;
}
input:focus, textarea:focus { border-color: var(--sun); background: #fff; }
textarea { resize: vertical; min-height: 96px; }

/* 按鈕 */
button { font: inherit; cursor: pointer; }
.btn-primary {
  display: block; width: 100%;
  margin-top: 16px;
  padding: 13px 16px;
  border: 0; border-radius: 14px;
  background: linear-gradient(180deg, #F9C24E, var(--sun-deep));
  color: #fff; font-weight: 700; font-size: 16px; letter-spacing: 1px;
  box-shadow: 0 3px 0 #C96C2C;
}
.btn-primary:active { transform: translateY(2px); box-shadow: 0 1px 0 #C96C2C; }
.btn-primary:disabled { opacity: .55; }
.btn-ghost {
  display: block; width: 100%; margin-top: 10px;
  padding: 12px 16px; border-radius: 14px;
  border: 1.5px solid var(--sun); background: #fff; color: var(--sun-deep); font-weight: 700;
}
.btn-text { background: none; border: 0; color: var(--ink-soft); padding: 12px 0 0; font-size: 14px; }
.btn-text.danger { color: var(--danger); }
.pill {
  border: 0; border-radius: 999px; padding: 6px 14px;
  background: var(--sun-deep); color: #fff; font-weight: 700; font-size: 14px; white-space: nowrap;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: var(--sun-pale); color: var(--ink); font-size: 22px; line-height: 1;
}

/* 寫日記 */
.entry-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.age-line { font-size: 17px; font-weight: 700; }
.age-line #w-name { display: block; font-size: 15px; color: var(--sun-deep); }
.age-line .dot { display: none; }
.dot { color: var(--sun-deep); }
.date-line { color: var(--ink-soft); font-size: 14px; }
.date-pick { width: auto !important; max-width: 150px; font-size: 14px !important; padding: 6px 8px !important; min-height: 36px !important; }
.field { margin-top: 18px; }
.field > label { margin-top: 0; }

.suns { display: flex; gap: 8px; }
.sun-btn {
  width: 48px; height: 48px; border: 0; padding: 0; background: none; border-radius: 50%;
  transition: transform .15s;
}
.sun-btn:active { transform: scale(.9); }
.sun-btn svg { width: 100%; height: 100%; display: block; }

.happy-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.happy-num {
  flex: 0 0 28px; height: 28px; border-radius: 50%;
  background: var(--sun-pale); color: var(--sun-deep);
  font-weight: 700; display: grid; place-items: center; font-size: 14px;
}

.photo-zone { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.photo-item, .photo-add {
  width: 92px; height: 92px; border-radius: 14px; position: relative; overflow: hidden;
}
.photo-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-del {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%;
  border: 0; background: rgba(90,67,50,.75); color: #fff; font-size: 15px; line-height: 1;
}
.photo-add {
  border: 2px dashed var(--sun); background: #FFFBF2; color: var(--sun-deep);
  font-size: 30px; display: grid; place-items: center;
}

.save-row { display: flex; flex-direction: column; }
.status { min-height: 1.4em; font-size: 14px; color: var(--green); margin: 8px 0 0; text-align: center; }
.status.err { color: var(--danger); }

.notice {
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
  background: #FFF0D2; border: 1.5px solid #F6D28E; border-radius: 14px;
  padding: 10px 12px; margin-bottom: 14px; font-size: 14px;
}

/* 回顧：月曆 */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-title { font-size: 18px; font-weight: 700; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal-week span { font-size: 12px; color: var(--ink-soft); padding: 4px 0; }
.cal-day {
  aspect-ratio: 1 / 1; border: 0; background: none; border-radius: 12px;
  font-size: 14px; color: var(--ink); position: relative; padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.cal-day.empty { visibility: hidden; }
.cal-day.today { box-shadow: inset 0 0 0 2px var(--sun); }
.cal-day.has { background: var(--sun-pale); font-weight: 700; }
.cal-day .mini-sun { width: 16px; height: 16px; margin-top: 1px; }
.cal-day.future { color: #CDBFB2; }

.entry-card { cursor: pointer; }
.entry-card .ec-top { display: flex; justify-content: space-between; align-items: center; }
.entry-card .ec-date { font-weight: 700; }
.entry-card .ec-age { font-size: 13px; color: var(--ink-soft); }
.entry-card .ec-suns { display: flex; gap: 2px; }
.entry-card .ec-suns svg { width: 18px; height: 18px; }
.entry-card .ec-note { margin: 8px 0 0; white-space: pre-wrap; }
.entry-card ul { margin: 6px 0 0; padding-left: 20px; color: var(--ink-soft); font-size: 14px; }
.ec-photos { display: flex; gap: 6px; margin-top: 8px; }
.ec-photos img { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; }
.stats { text-align: center; color: var(--ink-soft); font-size: 14px; }
.empty-hint { text-align: center; color: var(--ink-soft); padding: 16px 0; }

/* 設定 */
.seg { display: flex; background: var(--sun-pale); border-radius: 12px; padding: 4px; margin: 12px 0 2px; }
.seg-btn { flex: 1; border: 0; background: none; padding: 8px 4px; border-radius: 9px; color: var(--ink); font-size: 14px; }
.seg-btn.active { background: #fff; font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.version { text-align: center; color: var(--ink-soft); font-size: 13px; }

/* 底部分頁 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center;
  background: rgba(255,252,246,.96);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  z-index: 10;
}
.tab {
  flex: 1; max-width: 180px; border: 0; background: none;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  font-size: 12px; color: var(--ink-soft); padding: 4px 0;
}
.tab-ico { font-size: 20px; line-height: 1.2; }
.tab.active { color: var(--sun-deep); font-weight: 700; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; justify-content: center; align-items: center; gap: 12px;
  background: #5A4332; color: #fff; font-size: 14px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
}

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(90,67,50,.94); color: #fff;
  padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 30;
  max-width: 88vw; text-align: center;
}
