/* Mira — 言葉が主役の紙面。角丸4px、影とグラデーションは使わない */

:root,
:root[data-theme="day"] {
  /* 昼：白い紙に墨 */
  --bg: #F7F7F5;
  --text: #1A1A1A;
  --muted: #5C5C5C;
  --rule: #DADAD5;
  --card: #FFFFFF;
  --label: #C8442E;
  --accent: #C8442E;
  --on-accent: #FFFFFF;
  --line: #1A1A1A;
  --mood-excited: #D98E04;
  --mood-calm: #4E8B6E;
  --mood-irritated: #C8442E;
  --mood-gloomy: #4A6FA5;
  --mood-neutral: #5C5C5C;
}

:root[data-theme="night"] {
  /* 夜：紺色の紙に金 */
  --bg: #12172B;
  --text: #ECE6D6;
  --muted: #A7A9B8;
  --rule: #2A3150;
  --card: #12172B;
  --label: #D4B26A;
  --accent: #C8442E;
  --on-accent: #FFFFFF;
  --line: #D4B26A;
  --mood-excited: #E8C46A;
  --mood-calm: #8FC9A6;
  --mood-irritated: #E58A73;
  --mood-gloomy: #8FA8D8;
  --mood-neutral: #A7A9B8;
}

:root {
  --mincho: "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --gothic: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", sans-serif;
  --latin: "Cormorant Garamond", Georgia, serif;
  --radius: 4px;
  color-scheme: light;
}
:root[data-theme="night"] { color-scheme: dark; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: var(--gothic);
  font-size: 16px;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 14px) 16px calc(env(safe-area-inset-bottom) + 96px);
}

body.no-nav #app { padding-bottom: calc(env(safe-area-inset-bottom) + 32px); }

button { font: inherit; color: inherit; }

/* ---------- 見出し ---------- */

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule);
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-family: var(--latin);
  font-weight: 600;
  font-size: 30px;
  line-height: 1;
  letter-spacing: 0.02em;
}
.logo svg { width: 18px; height: 18px; fill: var(--label); }

.date {
  font-family: var(--mincho);
  font-size: 14px;
  color: var(--muted);
}

.subhead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule);
}

.btn-back {
  border: none;
  background: none;
  padding: 8px 0;
  min-height: 44px;
  color: var(--muted);
  cursor: pointer;
}

.label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 28px 0 10px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.2em;
  color: var(--label);
}
.label::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--rule);
}

.question {
  margin: 0 0 18px;
  font-family: var(--mincho);
  font-size: 24px;
  font-weight: 600;
  line-height: 1.6;
}

.hint, .note, .status {
  margin: 8px 0;
  font-size: 13px;
  color: var(--muted);
}
.note {
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  margin-top: 16px;
}
.status { margin-top: 28px; text-align: center; }

/* ---------- ボタン ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 18px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: default; pointer-events: none; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 500;
}
.btn-primary .sub { font-size: 13px; opacity: 0.85; font-weight: 400; }
.btn-block { display: flex; width: 100%; }
.btn-small { min-height: 36px; padding: 4px 12px; font-size: 14px; }
.btn-quiet {
  min-height: 44px;
  padding: 8px 0;
  border: none;
  background: none;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}

.actions { display: grid; gap: 10px; margin-top: 24px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ---------- カード・引用 ---------- */

.card {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  padding: 16px;
}

.quote {
  margin: 0;
  font-family: var(--mincho);
  font-size: 17px;
  line-height: 1.9;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--muted);
}
.meta .mood-word { display: inline-flex; align-items: center; gap: 6px; color: var(--text); }
.q-small { margin: 0 0 8px; font-size: 13px; color: var(--muted); }

.glyph { width: 12px; height: 12px; flex: none; }

details.raw { margin-top: 12px; }
details.raw summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}
details.raw .quote { padding: 4px 0 4px 14px; border-left: 1px solid var(--rule); }

/* ---------- 気分9マス ---------- */

.mood {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 6px;
}
.axis-y {
  /* 縦書きなので row が上→下の並びになる */
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
  writing-mode: vertical-rl;
  padding: 8px 0;
  /* 縦書きの高さがマスの大きさに影響しないよう、行の高さに合わせるだけにする */
  contain: size;
  width: 22px;
}
.axis-x {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
}

.mood-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  min-width: 0;
}

.cell {
  position: relative;
  aspect-ratio: 1.25;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  cursor: pointer;
  padding: 0;
}
.cell .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--tone); }
.cell-name { font-size: 11px; color: var(--muted); }
.cell[aria-checked="true"] { outline: 2px solid var(--text); outline-offset: -2px; }
.cell[aria-checked="true"] .dot { width: 18px; height: 18px; }

.tone-excited { --tone: var(--mood-excited); }
.tone-calm { --tone: var(--mood-calm); }
.tone-irritated { --tone: var(--mood-irritated); }
.tone-gloomy { --tone: var(--mood-gloomy); }
.tone-neutral { --tone: var(--mood-neutral); }

/* ---------- チップ・切り替え ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  min-height: 40px;
  padding: 6px 14px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: transparent;
  font-size: 14px;
  cursor: pointer;
}
.chip[aria-pressed="true"] {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

.tag-add { display: flex; gap: 8px; margin-top: 12px; }
.tag-add input { flex: 1; min-width: 0; }
.tag-add .btn { min-height: 44px; flex: none; }
.chip .x { margin-left: 6px; color: var(--muted); }

.seg {
  display: grid;
  grid-template-columns: repeat(var(--n, 3), 1fr);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}
.seg button {
  min-height: 44px;
  padding: 6px 4px;
  border: none;
  border-left: 1px solid var(--rule);
  background: transparent;
  font-size: 14px;
  cursor: pointer;
}
.seg button:first-child { border-left: none; }
.seg button:disabled { color: var(--muted); opacity: 0.5; cursor: default; }
.seg button[aria-pressed="true"] { background: var(--text); color: var(--bg); }

/* ---------- 入力 ---------- */

textarea, input, select {
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font-size: 16px;
}
textarea {
  min-height: 108px;
  padding: 12px 14px;
  font-family: var(--mincho);
  font-size: 17px;
  line-height: 1.8;
  resize: vertical;
}
input, select { min-height: 44px; padding: 8px 12px; font-family: var(--gothic); }
textarea:focus, input:focus, select:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--label);
  outline-offset: 1px;
}

.field { display: block; margin-top: 14px; }
.field > span { display: block; margin-bottom: 4px; font-size: 13px; color: var(--muted); }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.steps { margin: 12px 0 0; padding-left: 1.4em; font-size: 14px; }
.steps li { margin-top: 8px; }

.ok { color: var(--mood-calm); }

/* ---------- 星図 ---------- */

.map {
  display: block;
  width: 100%;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}
.map svg { display: block; width: 100%; height: auto; }
.map-small svg { max-width: 300px; margin: 0 auto; }

.ring { fill: none; stroke: var(--rule); stroke-width: 1; }
.map-month { fill: var(--muted); font-family: var(--mincho); font-size: 15px; text-anchor: middle; }
.map-tick { fill: var(--muted); font-family: var(--gothic); font-size: 8px; text-anchor: middle; }
.con-line { fill: none; stroke: var(--line); stroke-width: 0.8; opacity: 0.4; stroke-linejoin: round; }
.con-line.on { opacity: 1; stroke-width: 1.3; }
.star { fill: var(--tone); }
.star-g.dim { opacity: 0.3; }
.empty-day { fill: var(--muted); opacity: 0.45; }
.today-ring { fill: none; stroke: var(--line); stroke-width: 1; }
.today-slot { fill: none; stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; }
.sel-ring { fill: none; stroke: var(--text); stroke-width: 1.2; }
.hit { fill: transparent; cursor: pointer; }

.month-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
}
.month-nav h1 {
  margin: 0;
  font-family: var(--mincho);
  font-size: 20px;
  font-weight: 600;
}
.month-nav button {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
}
.month-nav button:disabled { opacity: 0.35; cursor: default; }

/* ---------- 下部ナビ・トースト ---------- */

.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--rule);
  background: var(--bg);
}
body.no-nav .nav { display: none; }
.nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 58px;
  padding: 8px 0 6px;
  border: none;
  border-top: 2px solid transparent;
  margin-top: -1px;
  background: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.nav svg { width: 20px; height: 20px; fill: currentColor; stroke: currentColor; }
.nav svg path[fill="none"] { fill: none; }
.nav button[aria-current="page"] { color: var(--text); border-top-color: var(--label); }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom) + 76px);
  max-width: 448px;
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  text-align: center;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
