/* 方舟大亨 — 溫暖紙質 × 現代極簡（延續 versele 視覺語言） */
:root {
  --bg: #faf6ee;
  --card: #fffdf7;
  --ink: #2d2416;
  --ink-soft: #6f6352;
  --line: #e6dcc8;
  --gold: #a87b2d;
  --gold-soft: #f3e8d2;
  --green: #4a7c46;
  --green-bg: #e4efe0;
  --red: #b04a3a;
  --red-bg: #f6e2dd;
  --gray-bg: #efeade;
  --sky: #cfe8f7;
  --water: #8fc0dd;
  --wood: #9a6a35;
  --wood-dark: #7a4f27;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(90, 70, 30, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171310;
    --card: #211c16;
    --ink: #ece2d0;
    --ink-soft: #a2947c;
    --line: #3a3226;
    --gold: #d3a856;
    --gold-soft: #33291a;
    --green: #8fbf87;
    --green-bg: #263822;
    --red: #d98070;
    --red-bg: #3c221c;
    --gray-bg: #2a251d;
    --sky: #23374a;
    --water: #2c526b;
    --wood: #7a5228;
    --wood-dark: #5c3c1c;
    --shadow: 0 2px 10px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
/* 關鍵：凡是 author CSS 設過 display 的元素，hidden 屬性都必須贏（versele 踩過的雷） */
[hidden] { display: none !important; }
html { height: 100%; }
body {
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg); color: var(--ink);
  max-width: 520px; margin: 0 auto; padding: 0 12px 86px;
  min-height: 100%;
}

/* ── 頁首 ── */
header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 2px 8px; border-bottom: 1px solid var(--line); margin-bottom: 10px;
}
h1 { font-size: 1.1rem; letter-spacing: .1em; font-weight: 700; display: flex; align-items: baseline; gap: 7px; white-space: nowrap; }
.day-tag { font-size: .72rem; color: var(--gold); font-weight: 600; letter-spacing: .04em; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--card); color: var(--ink-soft); font-size: .95rem; cursor: pointer;
  display: grid; place-items: center; flex-shrink: 0;
}
.icon-btn:active { transform: scale(.93); }
.flood-chip {
  font-size: .78rem; font-weight: 700; color: var(--ink-soft); cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 10px; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.flood-chip.urgent { color: #fff; background: var(--red); border-color: var(--red); animation: pulse 1.2s ease infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .65; } }

/* ── 資源列（sticky） ── */
.res-bar {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  display: flex; gap: 6px; padding: 6px 0 8px;
}
.res-chip {
  flex: 1; min-width: 0; background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 5px 7px; text-align: center; box-shadow: var(--shadow);
}
.res-chip .r-ico { font-size: .82rem; }
.res-chip b { display: block; font-size: .92rem; font-variant-numeric: tabular-nums; }
.res-chip small { display: block; font-size: .64rem; color: var(--ink-soft); min-height: .9em; font-variant-numeric: tabular-nums; }
.res-chip.starving { border-color: var(--red); background: var(--red-bg); }
.res-chip.starving small { color: var(--red); font-weight: 700; }

/* ── 卡片與按鈕 ── */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-bottom: 10px;
}
.card h3 { font-size: .92rem; margin-bottom: 10px; letter-spacing: .04em; }
.row-card { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rc-info { flex: 1; min-width: 0; }
.rc-info b { font-size: .9rem; display: block; }
.rc-info small { font-size: .74rem; color: var(--ink-soft); display: block; margin-top: 2px; }
.btn {
  border: none; border-radius: 10px; background: var(--gold-soft); color: var(--gold);
  font-size: .88rem; font-weight: 700; padding: 9px 14px; cursor: pointer; white-space: nowrap;
  font-family: inherit;
}
.btn.primary { background: var(--gold); color: #fff; box-shadow: var(--shadow); }
.btn.wide { display: block; width: 100%; margin-top: 10px; padding: 12px; font-size: .95rem; letter-spacing: .08em; }
.btn.small { font-size: .76rem; padding: 6px 10px; }
.btn:disabled { opacity: .35; cursor: default; }
.btn:not(:disabled):active { transform: scale(.97); }
.maxed { font-size: .8rem; color: var(--green); font-weight: 700; white-space: nowrap; }
.hint-line { display: block; font-size: .72rem; color: var(--ink-soft); margin-top: 8px; line-height: 1.6; }
.warn-line { display: block; font-size: .74rem; color: var(--red); margin-top: 6px; }
.pop { animation: pop .25s ease; }
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ── 方舟場景 ── */
.sea {
  position: relative; height: 158px; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line); box-shadow: var(--shadow);
  background: linear-gradient(var(--sky) 0 62%, var(--water) 62% 100%);
}
.ark {
  position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%);
  transition: width .5s ease; animation: bob 3.2s ease-in-out infinite;
}
@keyframes bob { 0%, 100% { transform: translateX(-50%) translateY(0) rotate(-.5deg); } 50% { transform: translateX(-50%) translateY(-4px) rotate(.5deg); } }
.ark-roof { height: 13px; background: var(--wood-dark); border-radius: 10px 10px 0 0; margin: 0 14%; }
.ark-deck {
  background: var(--wood); padding: 4px 8px; min-height: 26px;
  text-align: center; font-size: 1rem; line-height: 1.35; letter-spacing: 2px;
}
.deck-empty { font-size: .68rem; color: #f3e3c3; opacity: .85; letter-spacing: .05em; }
.ark-hull {
  background: var(--wood-dark); border-radius: 0 0 46% 46% / 0 0 78% 78%;
  padding: 2px 12px 9px; text-align: center; font-size: .72rem; letter-spacing: 3px; color: #f3e3c3;
}
.waves {
  position: absolute; bottom: -6px; left: -30px; right: -30px; height: 34px;
  font-size: 24px; white-space: nowrap; opacity: .9; animation: drift 5s linear infinite;
}
@keyframes drift { from { transform: translateX(0); } to { transform: translateX(-33px); } }
.sea.raining { filter: saturate(.75) brightness(.82); }
.sea.raining::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(75deg, transparent 0 7px, rgba(150, 185, 225, .38) 7px 8px);
  animation: rain .45s linear infinite;
}
@keyframes rain { to { background-position: -30px 110px; } }
.scene-cap { text-align: center; font-size: .76rem; color: var(--ink-soft); margin: 6px 0 10px; }

/* ── 工人指派 ── */
.job-summary { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: .76rem; color: var(--ink-soft); margin-bottom: 8px; }
.worker-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; border-top: 1px dashed var(--line);
}
.w-name { font-size: .84rem; font-weight: 600; width: 4.6em; flex-shrink: 0; }
.w-job { font-size: .7rem; color: var(--gold); width: 2.4em; flex-shrink: 0; }
.job-btns { display: flex; gap: 4px; margin-left: auto; }
.job-btn {
  width: 34px; height: 32px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); font-size: .9rem; cursor: pointer; display: grid; place-items: center;
}
.job-btn.active { background: var(--gold); border-color: var(--gold); box-shadow: var(--shadow); }
.job-btn:active { transform: scale(.92); }

/* ── 尋獸 ── */
.exp-slot { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.bar { flex: 1; height: 10px; background: var(--gray-bg); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; width: 0%; background: var(--gold); border-radius: 99px; transition: width .25s linear; }
.exp-time { font-size: .78rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; min-width: 3.2em; text-align: right; }

/* ── 動物收藏 ── */
.animal-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.animal-card {
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 6px; text-align: center;
  background: var(--bg); display: flex; flex-direction: column; gap: 4px; align-items: center;
}
.animal-card.t2 { border-color: var(--gold); }
.animal-card.t3 { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.animal-card.boarded { background: var(--green-bg); border-color: var(--green); box-shadow: none; }
.a-emoji { font-size: 1.6rem; line-height: 1.2; }
.a-name { font-size: .8rem; font-weight: 700; }
.a-tier { font-size: .62rem; color: var(--gold); }
.a-cnt { font-size: .72rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.a-status { min-height: 1.4em; display: grid; place-items: center; width: 100%; }
.badge { font-size: .64rem; padding: 2px 6px; border-radius: 999px; }
.badge.ok { background: var(--green-bg); color: var(--green); font-weight: 700; }
.badge.wait { background: var(--gold-soft); color: var(--gold); }
.badge.full { background: var(--red-bg); color: var(--red); }
.badge.none { background: var(--gray-bg); color: var(--ink-soft); }
.a-rel { display: flex; flex-direction: column; gap: 3px; width: 100%; }
.rel-btn {
  border: 1px dashed var(--line); background: none; color: var(--ink-soft);
  font-size: .62rem; border-radius: 6px; padding: 3px 2px; cursor: pointer; font-family: inherit;
}
.rel-btn:active { transform: scale(.95); }

/* ── 約定分頁 ── */
.flood-card.now { border-color: var(--red); }
.flood-big {
  text-align: center; font-size: 2rem; font-weight: 800; letter-spacing: .06em;
  color: var(--gold); font-variant-numeric: tabular-nums; margin: 6px 0 8px;
}
.flood-card.now .flood-big { color: var(--red); }
.settle-preview { font-size: .82rem; color: var(--ink-soft); line-height: 1.7; }
.settle-preview .gain { color: var(--gold); font-size: .95rem; }
.shop-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 0; border-top: 1px dashed var(--line);
}
.lore {
  font-family: "Noto Serif TC", "PMingLiU", Georgia, serif;
  font-size: .9rem; line-height: 1.9; color: var(--ink);
  background: var(--gold-soft); border-radius: 10px; padding: 12px 14px;
}
.lore-sub { font-size: .76rem; color: var(--ink-soft); margin-top: 8px; text-align: right; }

/* ── 底部分頁列 ── */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 520px; z-index: 30;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding: 4px 8px calc(6px + env(safe-area-inset-bottom));
}
.tab-btn {
  flex: 1; border: none; background: none; cursor: pointer; color: var(--ink-soft);
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  font-size: 1.15rem; padding: 6px 0 3px; border-radius: 10px; font-family: inherit;
}
.tab-btn span { font-size: .66rem; letter-spacing: .1em; }
.tab-btn.active { color: var(--gold); background: var(--gold-soft); font-weight: 700; }

/* ── 彈窗 ── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 14, 5, .55);
  display: grid; place-items: center; z-index: 50; padding: 18px;
}
.modal-backdrop[hidden] { display: none; } /* 雙保險（同全域 [hidden] 規則） */
.modal {
  background: var(--card); color: var(--ink); border-radius: 18px; position: relative;
  max-width: 440px; width: 100%; max-height: 82vh; overflow-y: auto;
  padding: 26px 22px; box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
  animation: rise .22s ease;
}
@keyframes rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-close {
  position: absolute; top: 12px; right: 12px; border: none; background: none;
  color: var(--ink-soft); font-size: 1.1rem; cursor: pointer; padding: 6px;
}
.modal h2 { font-size: 1.1rem; letter-spacing: .1em; margin-bottom: 14px; }
.modal p { font-size: .9rem; line-height: 1.8; color: var(--ink-soft); margin-bottom: 10px; }
.modal p b { color: var(--ink); }
.settle-grid {
  display: flex; flex-direction: column; gap: 8px; font-size: .9rem;
  background: var(--gold-soft); border-radius: 10px; padding: 14px 16px; margin: 12px 0;
}
.settle-total { border-top: 1px dashed var(--gold); padding-top: 8px; font-weight: 700; color: var(--gold); }

/* ── Toast ── */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 20px; border-radius: 999px;
  font-size: .9rem; z-index: 99; animation: pop .2s ease; white-space: nowrap; max-width: 92vw;
  overflow: hidden; text-overflow: ellipsis;
}
@media (min-width: 521px) { body { padding-top: 6px; } }
