:root {
  --bg: #faf6ef;
  --paper: #fffdf8;
  --ink: #3a3129;
  --muted: #8a7d70;
  --line: #e6dccd;
  --accent: #c8665a;
  --accent-ink: #fff;
  --plus: #3f8a5b;
  --minus: #c0463a;
  --il-b: #7fa7c9;
  --il-c: #f3d9a4;
  --il-shadow: #ece3d4;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1b18;
    --paper: #2a2521;
    --ink: #eee5da;
    --muted: #a99c8e;
    --line: #443b34;
    --accent: #e08a7d;
    --accent-ink: #1f1b18;
    --plus: #79c793;
    --minus: #f08a7e;
    --il-b: #6d93b5;
    --il-c: #d9bb82;
    --il-shadow: #342d28;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  line-height: 1.7;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 16px;
}

.screen[hidden] { display: none; }

h1, h2, h3 { margin: 0 0 12px; }

.logo {
  margin-top: 18vh;
  font-size: 2.6rem;
  text-align: center;
  letter-spacing: 0.1em;
}

.lead, .note { text-align: center; }
.note, .hint { color: var(--muted); font-size: 0.85rem; }

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: bold;
}

button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button:disabled { opacity: 0.5; cursor: default; }

.stack { display: grid; gap: 10px; margin-top: 20px; }

.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 4px; font-size: 0.9rem; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; gap: 8px; }
.field input, .field select { flex: 1; min-width: 0; }
.field button { padding: 8px 12px; font-size: 0.85rem; }

input, select {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  width: 100%;
}

/* メイン */
#screen-main:not([hidden]) {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 32px);
}

.status {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  font-size: 0.85rem;
}

.status .label { display: block; color: var(--muted); font-size: 0.75rem; }
.status .value { font-weight: bold; }
.status .savings { grid-column: span 2; font-size: 1.1rem; }

.diary {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  margin: 12px 0;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: repeating-linear-gradient(var(--paper) 0 27px, var(--line) 27px 28px) local;
}

.diary li { line-height: 28px; }
.diary .age { color: var(--accent); font-weight: bold; margin-right: 6px; }
.diary .money { color: var(--muted); font-size: 0.85rem; }

.plus { color: var(--plus); }
.minus { color: var(--minus); }

.controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.controls button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); font-weight: bold; }

/* イベント */
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: end center;
  background: rgb(0 0 0 / 0.4);
  padding: 16px;
}

.modal[hidden] { display: none; }

.modal-body {
  width: 100%;
  max-width: 448px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 20px;
  border-radius: 18px;
  background: var(--paper);
}

.modal-body .stack { margin-top: 12px; }

.option { display: grid; gap: 2px; text-align: left; }
.option .sub { color: var(--muted); font-size: 0.8rem; }

/* リザルト */
.rank {
  margin-top: 24px;
  font-size: 4rem;
  font-weight: bold;
  text-align: center;
  color: var(--accent);
  line-height: 1.2;
}

.ending { text-align: center; font-size: 1.3rem; font-weight: bold; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
td { padding: 4px 0; border-bottom: 1px solid var(--line); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.total td { font-weight: bold; }

.timeline { padding-left: 1.2em; font-size: 0.9rem; }

section h3 { margin-top: 24px; }

button.danger { color: var(--minus); border-color: var(--minus); background: transparent; }

a.button {
  display: block;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  color: inherit;
  text-align: center;
  text-decoration: none;
}

.form label.check { display: flex; align-items: center; gap: 10px; font-size: 1rem; }
.form label.check input { width: auto; }

/* イラスト */
.illust { display: block; width: 100%; height: auto; }
.il-a { fill: var(--accent); }
.il-b { fill: var(--il-b); }
.il-c { fill: var(--il-c); }
.il-ink { fill: var(--ink); }
.il-shadow { fill: var(--il-shadow); }
.il-line-a { stroke: var(--accent); }
.il-line-b { stroke: var(--il-b); }
.il-line-ink { stroke: var(--ink); }

.title-illust { width: 200px; margin: 12vh auto 0; }
.title-illust + .logo { margin-top: 8px; }
#modal-illust { width: 160px; margin: 0 auto 8px; }

/* 年末の収支 */
.year-summary {
  margin: -4px 0 12px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  font-size: 0.85rem;
  animation: fade-in 0.2s ease-out;
}
.year-summary[hidden] { display: none; }
.ys-head { font-weight: bold; margin-bottom: 4px; }
.ys-grid { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 0 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; }

@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* リザルト */
.result-head { text-align: center; }
.comment { margin: 4px 0 16px; }
.title-badge {
  display: inline-grid;
  gap: 2px;
  padding: 10px 20px;
  border: 2px solid var(--accent);
  border-radius: 999px;
  font-weight: bold;
  font-size: 1.1rem;
}
.title-badge .label { font-size: 0.75rem; color: var(--muted); font-weight: normal; }
.sub { display: block; color: var(--muted); font-size: 0.8rem; font-weight: normal; }

.new {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.7rem;
  font-weight: bold;
  vertical-align: middle;
}

.compare { margin: 8px 0 0; font-size: 0.9rem; }

.bars { display: grid; gap: 8px; font-size: 0.85rem; }
.bar { display: grid; grid-template-columns: 7.5em 1fr auto; align-items: center; gap: 8px; }
.bar-label { line-height: 1.3; }
.bar-track { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 5px; }

.achievements, .cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.cards { grid-template-columns: 1fr 1fr; }
.achievements li, .cards li {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  font-size: 0.9rem;
}
.locked { opacity: 0.55; }
.card-rank { display: block; font-size: 1.6rem; font-weight: bold; color: var(--accent); line-height: 1.2; }
.locked .card-rank { color: var(--muted); }
.count { color: var(--muted); font-size: 0.85rem; font-weight: normal; }

.timeline { list-style: none; padding: 0; }
.timeline li { padding: 2px 0; }
.timeline .age { color: var(--accent); font-weight: bold; margin-right: 8px; }

.share-preview { display: block; width: 100%; border-radius: 12px; border: 1px solid var(--line); }
.share button[hidden] { display: none; }

/* 言語の切り替え */
.lang-switch {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  margin-top: 24px;
  font-size: 0.85rem;
}
.lang-switch a { color: var(--muted); }
.lang-switch a[aria-current] { color: var(--accent); font-weight: bold; text-decoration: none; }

/* ブラウザの言語が別の対応言語のときの1行の案内（src/parts/suggest.html） */
.suggest {
  position: fixed;
  top: 8px;
  left: 8px;
  right: 8px;
  z-index: 900;
  max-width: 464px;
  margin: 0 auto;
  padding: 8px 40px 8px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  font-size: 0.85rem;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.12);
}
.suggest[hidden] { display: none; }
/* 案内が出ているあいだは、上の部分（文章のページの戻るリンク・ゲームのステータス）が隠れないように下げる */
body:has(#langSuggest:not([hidden])) #app { padding-top: 64px; }
.suggest a { color: var(--accent); font-weight: bold; }
.suggest-close {
  position: absolute;
  top: 2px;
  right: 4px;
  padding: 4px 10px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.1rem;
}

/* ページ下のメニュー（プライバシーポリシー・ほかのゲーム・Cookie の設定） */
.site-nav ul {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 16px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.8rem;
}
.site-nav a { color: var(--muted); }

/* 文章のページ（遊び方・プライバシーポリシー） */
#app.doc { max-width: 720px; min-height: auto; padding-bottom: 40px; }
.doc-back { display: inline-block; margin: 8px 0 16px; color: var(--muted); }
.doc h1 { font-size: 1.6rem; color: var(--accent); }
.doc-body {
  padding: 4px 20px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
}
.doc-body h2 { margin: 24px 0 8px; padding-bottom: 4px; border-bottom: 2px solid var(--line); font-size: 1.15rem; }
.doc-body p, .doc-body ul { margin: 0 0 12px; }
.doc-body ul { padding-left: 1.3em; }
.doc-body li { margin-bottom: 4px; }
.doc-body a { color: var(--accent); overflow-wrap: anywhere; }
.doc-body .table { overflow-x: auto; margin: 8px 0 14px; }
.doc-body table { min-width: 100%; font-size: 0.85rem; }
.doc-body th, .doc-body td { padding: 6px 8px; border: 1px solid var(--line); text-align: left; vertical-align: top; }
.doc-body th { background: var(--bg); }
.doc-body .example { padding: 8px 12px; border-radius: 10px; background: var(--bg); font-size: 0.9rem; }
.doc-body .note, .doc-body .date { color: var(--muted); font-size: 0.85rem; }
.doc .site-nav ul { font-size: 0.85rem; }
