/* =====================================================================
 *  app.css — 星露谷风像素田园 UI
 *  调色板与 art-assets/palette 一致（31 色低饱和）
 * ===================================================================== */

:root {
  --ink: #2B2A26;
  --shadow: #4A4A44;
  --grass-deep: #3C6349;
  --grass: #5A8C57;
  --grass-lt: #7FAF6C;
  --grass-pale: #A5C88B;
  --moss: #C7DCA6;
  --sky-deep: #7FA9C8;
  --sky: #A9CBE2;
  --sky-lt: #CFE3F0;
  --cream: #F6EED9;
  --cream-lt: #FFFBF0;
  --sand: #E6D3AE;
  --warm: #F3C963;
  --amber: #DDA24B;
  --amber-deep: #B87C3C;
  --wood: #8C6244;
  --wood-deep: #6B4A33;
  --wood-lt: #B08765;
  --rose: #E3A6A2;
  --rose-deep: #C67277;
  --lav: #B7A4D4;
  --teal: #6FBFB0;

  /* 语义色 */
  --text: #2B2A26;
  --text-dim: #8C6244;
  --card: #FFFBF0;
  --card-2: #F6EED9;
  --line: #6B4A33;
  --nav-bg: rgba(246, 238, 217, 0.94);
  --sheet-bg: #FFFBF0;

  --r: 14px;
  --pad: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

html[data-theme="night"] {
  --text: #F6EED9;
  --text-dim: #A9B6CE;
  --card: #33405E;
  --card-2: #2A3550;
  --line: #6A6A93;
  --nav-bg: rgba(46, 59, 85, 0.94);
  --sheet-bg: #2E3B55;
  --warm: #F3C963;
}

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

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
  background: #A9CBE2 url("../assets/bg/day.png") center top / cover no-repeat;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

html[data-theme="night"] body {
  background-color: #2E3B55;
  background-image: url("../assets/bg/night.png");
}

img { display: block; image-rendering: pixelated; }
body.no-scroll { overflow: hidden; }

/* ------------------------------------------------------------------ 启动页 */
#splash {
  position: fixed; inset: 0; z-index: 90;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
  background: var(--cream);
  transition: opacity .45s ease;
}
#splash.gone { opacity: 0; pointer-events: none; }
#splash img { width: 112px; height: 112px; }
.splash__title { font-size: 26px; letter-spacing: .3em; font-weight: 700; color: var(--ink); }
.splash__sub { font-size: 12px; letter-spacing: .2em; color: var(--wood); }

/* ------------------------------------------------------------------ 主区域 */
#view {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) var(--pad)
           calc(84px + var(--safe-b));
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
}

/* ------------------------------------------------------------------ 底部导航 */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 6px calc(6px + var(--safe-b));
  background: var(--nav-bg);
  border-top: 3px solid var(--line);
  backdrop-filter: blur(8px);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 4px 0 2px;
  text-decoration: none; color: var(--text-dim);
  font-size: 11px; letter-spacing: .05em;
  border-radius: 10px;
  transition: background .15s, color .15s;
}
.tab img { width: 26px; height: 26px; opacity: .72; transition: transform .15s, opacity .15s; }
.tab.active { color: var(--ink); background: rgba(127, 175, 108, .22); }
html[data-theme="night"] .tab.active { color: var(--warm); background: rgba(243, 201, 99, .14); }
.tab.active img { opacity: 1; transform: translateY(-1px) scale(1.06); }

/* ------------------------------------------------------------------ 通用元件 */
.h4 {
  margin: 22px 0 8px;
  font-size: 14px; letter-spacing: .08em;
  color: var(--text-dim);
}
.panel {
  margin: 12px 0;
  padding: 14px 16px 12px;
  background: var(--card);
  border: 3px solid var(--line);
  border-radius: var(--r);
  box-shadow: inset 0 0 0 3px var(--card-2), 0 3px 0 rgba(43, 42, 38, .18);
}
.panel__title {
  margin: 0 0 6px;
  font-size: 13px; font-weight: 700; letter-spacing: .12em;
  color: var(--text-dim);
}
.panel__title::before {
  content: ""; display: inline-block;
  width: 8px; height: 8px; margin-right: 7px;
  background: var(--warm);
  border: 2px solid var(--amber-deep);
  transform: rotate(45deg) translateY(-1px);
}
.panel--curiosity {
  background: linear-gradient(180deg, rgba(243, 201, 99, .26), rgba(243, 201, 99, .10)), var(--card);
}
.para { margin: 0 0 4px; font-size: 15px; }
.para--dim { color: var(--text-dim); font-size: 14px; }
.tiny { font-size: 12px; opacity: .75; }

.rhythm {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 34px; height: 34px;
  border-radius: 50%;
  font-size: 16px; font-weight: 700;
  border: 3px solid var(--line);
  background: var(--card);
}
.rhythm--急 { background: var(--rose); }
.rhythm--稳 { background: var(--grass-pale); }
.rhythm--缓 { background: var(--sky); }

.tag {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; color: var(--text-dim);
  border: 2px solid var(--line);
  background: var(--card-2);
}
.tag--ok { color: var(--grass-deep); border-color: var(--grass); background: rgba(127, 175, 108, .2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px;
  font-family: inherit; font-size: 15px; font-weight: 700; letter-spacing: .06em;
  color: var(--ink);
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: var(--r);
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  transition: transform .06s, box-shadow .06s, filter .15s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--ink); }
.btn--primary { background: var(--grass-lt); }
.btn--ghost { background: var(--card); box-shadow: 0 3px 0 var(--line); border-color: var(--line); }
.btn--danger { color: #7A2E2E; }
.btn--big { width: 100%; padding: 15px; font-size: 17px; }
.btn:disabled { filter: saturate(.4) brightness(.96); opacity: .8; }

.linkbtn {
  background: none; border: 0; padding: 4px;
  font: inherit; font-size: 13px; color: var(--wood);
  text-decoration: underline dotted;
  cursor: pointer;
}
html[data-theme="night"] .linkbtn { color: var(--warm); }

.iconbtn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: var(--card); border: 3px solid var(--line); border-radius: 12px;
  cursor: pointer; color: var(--text);
  font-size: 16px;
}
.iconbtn--flip img { transform: scaleX(-1); }

/* ------------------------------------------------------------------ 首页 */
.day-head { text-align: center; margin: 4px 0 14px; }
.day-head__date { font-size: 13px; letter-spacing: .1em; color: var(--text-dim); }
.day-head__sub { font-size: 15px; margin-top: 2px; }

.cast { text-align: center; padding: 8px 0 0; }
.cast__ball { position: relative; display: grid; place-items: center; height: 208px; }
.ball {
  width: 192px; height: 192px;
  image-rendering: pixelated;
  background-repeat: no-repeat;
  background-position: 0 0;
  filter: drop-shadow(0 8px 12px rgba(43, 42, 38, .28));
}
.ball--idle {
  background-image: url("../assets/fx/ball-idle.png");
  background-size: 1152px 192px;
  animation: ballIdle 4.2s steps(6) infinite;
}
.ball--cast {
  background-image: url("../assets/fx/ball-cast.png");
  background-size: 1536px 192px;
  animation: ballCast 1.15s steps(8) 1 forwards;
}
@keyframes ballIdle { from { background-position: 0 0; } to { background-position: -1152px 0; } }
@keyframes ballCast { from { background-position: 0 0; } to { background-position: -1536px 0; } }

.cast__fairy {
  position: absolute; right: 6%; bottom: 2px;
  width: 64px; height: auto;
  filter: drop-shadow(0 4px 6px rgba(43, 42, 38, .22));
  animation: bob 3.2s ease-in-out infinite;
}
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

.cast__hello { margin: 10px 6px 18px; font-size: 15px; color: var(--text); }
.cast__tip { margin-top: 12px; font-size: 12px; color: var(--text-dim); letter-spacing: .08em; }

.gua-card {
  position: relative;
  margin: 2px 0 14px;
  padding: 16px;
  background: var(--card);
  border: 3px solid var(--line);
  border-radius: 18px;
  box-shadow: inset 0 0 0 4px var(--card-2), 0 5px 0 rgba(43, 42, 38, .2);
}
.gua-card__top { display: flex; gap: 14px; align-items: center; }
.gua-card__img { width: 96px; height: 96px; flex: none; }
.gua-card__meta { flex: 1; min-width: 0; padding-right: 42px; }
.gua-card__no { font-size: 12px; letter-spacing: .16em; color: var(--text-dim); }
.gua-card__name { margin: 0; font-size: 30px; line-height: 1.2; letter-spacing: .06em; }
.gua-card__trigram { font-size: 12px; color: var(--text-dim); }
.gua-card__rhythm { position: absolute; right: 14px; top: 14px; }
.gua-card__keyword {
  margin-top: 10px; padding-top: 10px;
  border-top: 2px dashed rgba(140, 98, 68, .35);
  text-align: center; font-size: 16px; letter-spacing: .1em; color: var(--amber-deep);
}
html[data-theme="night"] .gua-card__keyword { color: var(--warm); }

.advice { margin: 0; padding-left: 20px; }
.advice li { margin: 6px 0; font-size: 15px; }
.advice li::marker { color: var(--amber); font-weight: 700; }

.foot-note {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  margin: 16px 0 4px;
}

.action-row {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  margin: 10px 0 6px;
}
.action-row .btn { width: 100%; }
.action-row .linkbtn { margin-top: 2px; }

/* ------------------------------------------------------------------ 海报 */
.poster-img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 58vh;
  margin: 0 auto;
  border: 3px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 6px 18px rgba(43, 42, 38, .25);
}
.poster-actions {
  display: flex; gap: 8px; margin-top: 14px;
}
.poster-actions .btn { flex: 1; padding: 10px 6px; font-size: 14px; }
.centered { text-align: center; margin-top: 10px; }

/* ------------------------------------------------------------------ 卦历 */
.cal { padding-top: 2px; }
.cal__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal__title { text-align: center; line-height: 1.1; }
.cal__title-y { display: block; font-size: 11px; letter-spacing: .3em; color: var(--text-dim); }
.cal__title-m { display: block; font-size: 30px; font-weight: 700; }
.cal__title-m small { font-size: 14px; font-weight: 400; }

.cal__week {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
  margin-bottom: 6px;
  text-align: center; font-size: 12px; color: var(--text-dim);
}

.cal__grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }

.cell {
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  background: var(--card);
  border: 2px solid var(--sand);
  border-radius: 10px;
  font: inherit; color: var(--text-dim);
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
}
.cell--void { background: transparent; border-color: transparent; cursor: default; }
.cell--done { border-color: var(--amber); background: var(--cream-lt); }
.cell--muted { opacity: .55; border-color: rgba(230, 211, 174, .5); }
.cell--today {
  border-color: var(--amber-deep);
  background: var(--warm);
  box-shadow: 0 0 0 3px rgba(243, 201, 99, .45);
  color: var(--ink);
}
.cell__no {
  position: absolute; top: 2px; left: 5px;
  font-size: 11px; font-weight: 700; color: var(--text-dim);
}
.cell--today .cell__no { color: var(--ink); }
.cell__gua { width: 18px; height: 18px; margin-top: 6px; opacity: .95; }
html[data-theme="night"] .cell { background: rgba(255, 251, 240, .08); }
html[data-theme="night"] .cell--done { background: rgba(255, 251, 240, .14); }
html[data-theme="night"] .cell--today { background: var(--warm); }

.cal__foot {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 14px; font-size: 13px; color: var(--text-dim);
}
.cal__foot b { color: var(--amber-deep); }
html[data-theme="night"] .cal__foot b { color: var(--warm); }

/* ------------------------------------------------------------------ 图鉴 */
.atlas__intro { margin: 0 0 14px; font-size: 13px; color: var(--text-dim); }
.atlas__grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.atlas__item {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px 6px;
  background: var(--card); border: 2px solid var(--sand); border-radius: 12px;
  font: inherit; color: var(--text); cursor: pointer;
}
.atlas__item img { width: 28px; height: 28px; }
.atlas__name { font-size: 12px; letter-spacing: .04em; }
.atlas__item .dot {
  position: absolute; top: 5px; right: 5px;
  width: 6px; height: 6px; border-radius: 50%; background: var(--amber);
}
html[data-theme="night"] .atlas__item { background: rgba(255,251,240,.08); }

/* ------------------------------------------------------------------ 日记 */
.journal__head { margin: 0 0 8px; font-size: 13px; letter-spacing: .08em; color: var(--text-dim); }
.photo-pick { display: block; cursor: pointer; }
.photo-pick__preview {
  display: grid; place-items: center;
  min-height: 180px;
  border: 3px dashed var(--line); border-radius: 16px;
  background: rgba(255, 251, 240, .55);
  color: var(--text-dim); text-align: center; font-size: 13px;
  overflow: hidden;
}
.photo-pick__preview img { width: 100%; max-height: 320px; object-fit: cover; }
html[data-theme="night"] .photo-pick__preview { background: rgba(255, 251, 240, .07); }
.textarea {
  width: 100%; margin: 12px 0; padding: 12px 14px;
  font: inherit; font-size: 15px; line-height: 1.7;
  color: var(--text); background: var(--card);
  border: 3px solid var(--line); border-radius: var(--r);
  resize: vertical;
}
.thumbs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.thumb {
  position: relative; aspect-ratio: 1; padding: 0; overflow: hidden;
  border: 2px solid var(--line); border-radius: 10px;
  background: var(--card-2); cursor: pointer;
  display: grid; place-items: center; color: var(--text-dim); font-size: 12px;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb em {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 1px 0; font-style: normal; font-size: 10px; text-align: center;
  color: var(--ink); background: rgba(246, 238, 217, .85);
}

/* ------------------------------------------------------------------ 设置 */
.form { display: flex; flex-direction: column; gap: 12px; margin-bottom: 6px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text-dim); }
.form input, .form select {
  padding: 11px 13px;
  font: inherit; font-size: 15px; color: var(--text);
  background: var(--card);
  border: 3px solid var(--line); border-radius: var(--r);
}
.form input:focus, .form select:focus { outline: 3px solid rgba(127, 175, 108, .5); }
.form__row { display: flex; gap: 10px; }
.form__row .btn { flex: 1; }
.switch { flex-direction: row !important; align-items: center; gap: 8px; }
.switch input { width: 22px; height: 22px; accent-color: var(--grass); }
.about-art { display: flex; justify-content: center; margin: 14px 0 8px; }
.about-art img { width: 72px; height: 72px; }

/* ------------------------------------------------------------------ 抽屉 */
.sheet {
  position: fixed; inset: 0; z-index: 60;
  display: none;
  background: rgba(43, 42, 38, .45);
  align-items: flex-end;
}
.sheet.open { display: flex; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet__panel {
  width: 100%; max-width: 520px; margin: 0 auto;
  max-height: 86vh; overflow-y: auto;
  padding: 4px var(--pad) calc(20px + var(--safe-b));
  background: var(--sheet-bg);
  border-top: 4px solid var(--line);
  border-radius: 22px 22px 0 0;
  animation: slideUp .24s cubic-bezier(.22, .8, .3, 1);
}
@keyframes slideUp { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet__bar { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 2px; }
.sheet__title { margin: 2px 0 10px; font-size: 17px; letter-spacing: .04em; }
.sheet__body { font-size: 15px; }
.sheet__gua { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.sheet__gua img { width: 72px; height: 72px; }
.sheet__no { font-size: 12px; color: var(--text-dim); letter-spacing: .12em; }
.sheet__name { font-size: 22px; font-weight: 700; }
.sheet__tri { font-size: 12px; color: var(--text-dim); }
.sheet__photo { width: 100%; border-radius: 12px; margin: 8px 0; }

/* ------------------------------------------------------------------ 提示 */
#toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b));
  transform: translate(-50%, 12px);
  max-width: 82vw; padding: 10px 16px;
  background: rgba(43, 42, 38, .92); color: #FFFBF0;
  font-size: 13px; line-height: 1.6; text-align: center;
  border-radius: 12px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 80;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.fatal {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-content: center; gap: 8px;
  padding: 24px; text-align: center;
  background: #FFFBF0; color: #2B2A26; font-size: 14px;
}

/* ------------------------------------------------------------------ 窄屏 */
@media (max-width: 340px) {
  body { font-size: 14px; }
  .atlas__grid { grid-template-columns: repeat(3, 1fr); }
  .gua-card__name { font-size: 26px; }
  .gua-card__img { width: 78px; height: 78px; }
}

/* 减少动效偏好 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
