/* ============================================================
 * 星からの小さな便り — style.css
 *
 * 世界観：「静かな夜空から届く小さな手紙」
 *  ・夜空は深い紺。読む場所（便箋・カード）は暖かい白で、いちばん読みやすく
 *  ・文字は大きめ（本文22px・月日17px以上）。rem 指定なので、端末の文字サイズ設定に追従する
 *  ・色だけで状態を伝えない（選択中は文字バッジ＋太い枠）
 *  ・背景の星は飾り。本文の背後には重ねない
 *
 * 色の約束（コントラストは test/contrast.test.mjs で実測）
 *   夜空の文字 #F4F2EC ／ 便箋 #FFF9F0 ＋ 文字 #263247 ／ 淡い金 #DEC58C は飾りと大きなボタンだけ
 * ============================================================ */

:root {
  --bg1: #152238;
  --bg2: #292644;
  --paper: #FFF9F0;
  --ink: #263247;
  --night-text: #F4F2EC;
  --gold: #DEC58C;
  --line: #CDBF9A;
  --sel: #FFF0CC;
  --ring-light: #FFE9A8;
  --ring-dark: #152238;

  --sans: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "BIZ UDPGothic", "Yu Gothic UI", "Yu Gothic", "Meiryo", "Noto Sans JP", "Noto Sans CJK JP", sans-serif;
  --serif: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "BIZ UDPMincho", "Noto Serif JP", "Noto Serif CJK JP", serif;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg1);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--night-text);
  font-family: var(--sans);
  font-size: 1.25rem;       /* 20px */
  line-height: 1.8;
  overflow-wrap: anywhere;
  word-break: normal;
  line-break: strict;
  -webkit-font-smoothing: antialiased;
}

/* ---- 夜空（飾り） ---- */
.sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1.6px 1.6px at 8% 12%, rgba(222,197,140,.9), transparent 70%),
    radial-gradient(1.2px 1.2px at 22% 6%, rgba(244,242,236,.8), transparent 70%),
    radial-gradient(1.8px 1.8px at 91% 9%, rgba(222,197,140,.9), transparent 70%),
    radial-gradient(1.2px 1.2px at 78% 21%, rgba(244,242,236,.7), transparent 70%),
    radial-gradient(1.4px 1.4px at 5% 38%, rgba(244,242,236,.7), transparent 70%),
    radial-gradient(1.6px 1.6px at 95% 46%, rgba(222,197,140,.8), transparent 70%),
    radial-gradient(1.2px 1.2px at 3% 71%, rgba(222,197,140,.8), transparent 70%),
    radial-gradient(1.4px 1.4px at 97% 78%, rgba(244,242,236,.7), transparent 70%),
    radial-gradient(1.2px 1.2px at 12% 93%, rgba(244,242,236,.7), transparent 70%),
    radial-gradient(1.6px 1.6px at 88% 95%, rgba(222,197,140,.8), transparent 70%),
    linear-gradient(170deg, var(--bg1) 0%, var(--bg2) 100%);
}

#app {
  width: 100%;
  max-width: 36rem;
  margin: 0 auto;
  padding: calc(1.25rem + var(--safe-t)) 1rem calc(2rem + var(--safe-b));
}

/* ---- スキップリンク・読み上げ専用 ---- */
.skip {
  position: absolute; left: .5rem; top: -4rem; z-index: 100;
  background: var(--paper); color: var(--ink); padding: .75rem 1rem; border-radius: .75rem; font-weight: 700;
}
.skip:focus { top: .5rem; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---- キーボードのフォーカス：内側が淡い金・外側が濃紺の二重の輪（夜空でも便箋の上でも見える） ---- */
:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--ring-dark);
  outline-offset: 3px;
  box-shadow: 0 0 0 3px var(--ring-light);
  border-radius: .5rem;
}
main:focus, h2:focus, .letter:focus { outline: none; box-shadow: none; }
.sign:focus-visible, .btn:focus-visible, summary:focus-visible { border-radius: 1.1rem; }

/* ---- ヘッダー ---- */
.head { position: relative; padding: .5rem .25rem 1.25rem; }
.head-stars { position: absolute; right: .25rem; top: .1rem; width: 5rem; height: auto; opacity: .95; pointer-events: none; }
.head-date { margin: 0; font-size: 1.125rem; color: var(--night-text); letter-spacing: .04em; }
.head-date time { font-weight: 700; }
.head-title {
  margin: .15rem 0 .35rem;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.875rem;
  line-height: 1.35;
  letter-spacing: .04em;
  text-wrap: balance;
}
.head-lead { margin: 0; font-size: 1.125rem; }

/* ---- ボタン ---- */
.btn {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-weight: 700;
  min-height: 3.5rem;
  min-width: 3.5rem;
  padding: .65rem 1.25rem;
  border-radius: 1rem;
  border: 2px solid transparent;
  background: none;
  color: inherit;
  cursor: pointer;
  line-height: 1.4;
  text-align: center;
}
.btn-primary { background: var(--gold); color: var(--bg1); border-color: var(--gold); }
.btn-quiet { border-color: var(--night-text); color: var(--night-text); }
.btn-wide { width: 100%; }
.btn:active { transform: translateY(1px); }
.on-paper .btn-quiet { border-color: var(--ink); color: var(--ink); }
.on-paper .btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---- 案内（読み込み中・失敗・期間外） ---- */
.notice {
  margin: 0 0 1.25rem;
  padding: 1.1rem 1.25rem;
  border: 2px solid var(--gold);
  border-radius: 1.1rem;
  background: rgba(255, 255, 255, .07);
}
.notice p { margin: 0 0 .6rem; }
.notice p:last-child { margin-bottom: 0; }
.notice .notice-title { font-weight: 700; font-size: 1.3rem; }
.notice .btn { margin-top: .4rem; }

/* ---- 便箋（今日のメッセージ） ---- */
.letter-wrap { margin: 0 0 1.5rem; }
.letter {
  position: relative;
  margin-top: 1.9rem;
  padding: 2.5rem 1.4rem 1.6rem;
  background: var(--paper);
  color: var(--ink);
  border-radius: 1.25rem;
  box-shadow: 0 2px 0 rgba(222, 197, 140, .6), 0 14px 30px rgba(6, 12, 28, .45);
}
.letter::before {                      /* 便箋のふち飾り */
  content: "";
  position: absolute; inset: .5rem;
  border: 1.5px solid rgba(160, 132, 66, .55);
  border-radius: .9rem;
  pointer-events: none;
}
.letter.is-new { animation: unfold .5s ease-out both; }
@keyframes unfold { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.seal {                                /* 封の印：星座のシンボル */
  position: absolute; top: -1.9rem; left: 50%; transform: translateX(-50%);
  width: 3.8rem; height: 3.8rem; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--gold); color: var(--ink);
  border: 3px solid var(--paper);
  box-shadow: 0 3px 10px rgba(6, 12, 28, .4);
}
.seal svg { width: 2rem; height: 2rem; }
.letter-date { margin: 0; text-align: center; font-size: 1.0625rem; }
.letter-title {
  text-wrap: balance;
  margin: .1rem 0 1rem;
  text-align: center;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.75rem;
  line-height: 1.4;
  letter-spacing: .06em;
}
.letter-body p {
  margin: 0 0 1.05rem;
  font-size: 1.375rem;                 /* 22px */
  line-height: 1.95;
  text-align: left;
}
.letter-body p:last-child { margin-bottom: .25rem; }
.letter-note { margin: 1rem 0 0; font-size: 1.0625rem; line-height: 1.7; text-align: center; }
.letter-tag { display: inline-block; margin: 0 0 .75rem; padding: .25rem .8rem; border: 2px solid var(--ink); border-radius: 999px; font-weight: 700; font-size: 1.0625rem; }
.letter-actions { margin-top: 1rem; }

/* ---- 星座の選択 ---- */
.picker { margin: 0 0 1.5rem; }
.picker h2 {
  margin: 0 0 1rem;
  font-family: var(--serif);
  font-size: 1.375rem;
  text-wrap: balance;
  line-height: 1.5;
  letter-spacing: .04em;
}
.grid {
  list-style: none; margin: 0 0 1rem; padding: 0;
  display: grid; gap: .75rem;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 8.25rem), 1fr));
}
.sign {
  width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; gap: .3rem;
  position: relative;
  padding: .6rem .4rem .8rem;
  background: var(--paper); color: var(--ink);
  border: 3px solid var(--line);
  border-radius: 1.1rem;
  font: inherit; text-align: center; cursor: pointer;
  min-height: 11rem;
}
.sign .art svg { display: block; width: 5.25rem; height: 5.25rem; }
.sign .nm { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: .25rem; font-weight: 700; font-size: 1.25rem; line-height: 1.35; }
.sign .sym svg { display: block; width: 1.35rem; height: 1.35rem; }
.sign .rng { font-size: 1.0625rem; line-height: 1.4; }
.sign .badge {
  display: none;
  margin-top: .15rem; padding: .1rem .7rem;
  background: var(--ink); color: #fff;
  border-radius: 999px; font-size: 1.0625rem; font-weight: 700; line-height: 1.5;
}
.sign[data-selected="true"] { border-color: var(--ink); background: var(--sel); box-shadow: 0 0 0 3px var(--gold); }
.sign[data-selected="true"] .badge { display: inline-block; }
.sign:active { transform: translateY(1px); }
.caution { margin: 0 0 1rem; font-size: 1.0625rem; line-height: 1.7; }

/* ---- 今日の星の配置（根拠） ---- */
.evidence {
  margin: 0 0 1.5rem;
  background: var(--paper); color: var(--ink);
  border-radius: 1.1rem;
  box-shadow: 0 10px 24px rgba(6, 12, 28, .35);
}
.evidence > summary {
  list-style: none;
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  min-height: 3.75rem; padding: .7rem 1.2rem;
  font-weight: 700; font-size: 1.25rem; cursor: pointer;
}
.evidence > summary::-webkit-details-marker { display: none; }
.evidence > summary::after { content: "＋"; font-size: 1.5rem; line-height: 1; }
.evidence[open] > summary::after { content: "－"; }
.evidence-body { padding: .25rem 1.2rem 1.3rem; font-size: 1.1875rem; line-height: 1.8; }
.evidence-body h3 {
  margin: 1.3rem 0 .4rem; padding-top: 1rem;
  border-top: 1.5px dashed var(--line);
  font-family: var(--serif); font-size: 1.25rem; line-height: 1.5;
}
.evidence-body h3:first-child { margin-top: .4rem; padding-top: 0; border-top: 0; }
.evidence-body p { margin: 0 0 .6rem; }
.evidence-body ul { margin: 0 0 .6rem; padding-left: 1.3rem; }
.evidence-body li { margin-bottom: .4rem; }
.evidence-body .fact { font-weight: 700; }
.evidence-body .small { font-size: 1.0625rem; }
.evidence-more { margin-top: .5rem; }
.table-wrap { overflow-x: auto; margin: .6rem 0; }
.evidence-body table { width: 100%; border-collapse: collapse; font-size: 1.125rem; }
.evidence-body th, .evidence-body td { padding: .45rem .5rem; text-align: left; border-bottom: 1.5px solid var(--line); vertical-align: top; }
.evidence-body th { font-weight: 700; }

/* ---- フッター ---- */
.foot { margin-top: 2rem; text-align: center; }
.foot-actions { display: flex; flex-wrap: wrap; gap: .75rem; justify-content: center; }
.foot-actions .btn { flex: 1 1 11rem; }
.copy { margin: 1.1rem 0 0; font-size: 1rem; }

/* ---- モーダル（このアプリについて・お便り・星座の確認） ---- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
  background: rgba(8, 14, 30, .8);
}
.modal-panel {
  width: 100%; max-width: 38rem;
  max-height: 94vh; max-height: 94dvh;
  display: flex; flex-direction: column;
  background: var(--paper); color: var(--ink);
  border-radius: 1.4rem 1.4rem 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .4);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .9rem 1.1rem .7rem 1.3rem;
  border-bottom: 1.5px solid var(--line);
}
.modal-head h2 { margin: 0; font-family: var(--serif); font-size: 1.4rem; line-height: 1.4; }
.modal-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 1rem 1.3rem calc(1.5rem + var(--safe-b)); font-size: 1.1875rem; line-height: 1.85; }
.modal-body h3 { margin: 1.4rem 0 .4rem; font-family: var(--serif); font-size: 1.25rem; line-height: 1.5; }
.modal-body h3:first-child { margin-top: .2rem; }
.modal-body p { margin: 0 0 .7rem; }
.modal-body ul, .modal-body ol { margin: 0 0 .7rem; padding-left: 1.4rem; }
.modal-body li { margin-bottom: .4rem; }
.modal-body .small { font-size: 1.0625rem; }
.modal-body a { color: var(--ink); font-weight: 700; text-decoration: underline; text-underline-offset: .2em; }
.modal-body details { margin: .6rem 0; border: 1.5px solid var(--line); border-radius: .8rem; padding: .2rem .9rem; }
.modal-body summary { cursor: pointer; font-weight: 700; min-height: 3rem; display: flex; align-items: center; }
.modal-body pre { white-space: pre-wrap; font: inherit; font-size: 1rem; line-height: 1.6; margin: .4rem 0 .8rem; }
.form-frame { width: 100%; height: 62vh; height: 62dvh; min-height: 22rem; border: 1.5px solid var(--line); border-radius: .8rem; background: #fff; }

@media (min-width: 40rem) {
  .modal { align-items: center; padding: 1.5rem; }
  .modal-panel { border-radius: 1.4rem; max-height: 88vh; max-height: 88dvh; }
}

/* ---- 星座の確認フォーム ---- */
.field { margin: 0 0 1.1rem; border: 0; padding: 0; min-width: 0; }
.field > legend, .field > label { display: block; padding: 0; margin: 0 0 .3rem; font-weight: 700; }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.row > * { flex: 1 1 6.5rem; min-width: 0; }
.row > .row-fixed { flex: 0 0 auto; }
select, input[type="number"] {
  font: inherit; font-size: 1.25rem; color: var(--ink);
  width: 100%; min-height: 3.5rem; padding: .5rem .8rem;
  border: 2px solid var(--ink); border-radius: .8rem; background: #fff;
}
.radio { display: flex; align-items: center; gap: .7rem; min-height: 3.25rem; font-weight: 400; cursor: pointer; }
.radio input { width: 1.6rem; height: 1.6rem; accent-color: var(--ink); flex: 0 0 auto; }
.result { margin-top: 1.1rem; padding: 1rem 1.1rem; border: 2px solid var(--ink); border-radius: 1rem; background: var(--sel); }
.result p { margin: 0 0 .6rem; }
.result .btn { margin: .25rem .4rem .25rem 0; }
.result .big { font-family: var(--serif); font-size: 1.5rem; font-weight: 700; }
.help { margin: .3rem 0 0; font-size: 1.0625rem; line-height: 1.7; }
.error-text { color: #8A1C1C; font-weight: 700; }

.noscript { margin: 1rem; padding: 1rem; background: var(--paper); color: var(--ink); border-radius: 1rem; }

/* ---- 動きを減らす設定 ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ---- 印刷：夜空を消して、便りだけ ---- */
@media print {
  .sky, .head-stars, .foot, .picker, .evidence { display: none !important; }
  body { background: #fff; color: #000; }
}

/* ---- 行末に句点だけが残らないよう、折り返しを整える（対応していない端末では無視される） ---- */
.letter-body p, .letter-note, .modal-body p, .evidence-body p, .caution, .notice p { text-wrap: pretty; }
.head-lead { text-wrap: balance; }

/* 星の飾りは文字の後ろ（文字が大きくなって重なっても読める） */
.head-stars { z-index: 0; opacity: .6; }
.head > :not(.head-stars) { position: relative; z-index: 1; }

/* ---- ダイアログの見出し・閉じるボタン・ラジオボタン（選択状態がはっきり分かるように自作） ---- */
.modal-head h2 { text-wrap: balance; font-size: 1.3rem; }
.modal-head .btn { flex: 0 0 auto; white-space: nowrap; }
.radio input {
  appearance: none; -webkit-appearance: none;
  display: grid; place-content: center;
  width: 1.75rem; height: 1.75rem; margin: 0; flex: 0 0 auto;
  border: 2px solid var(--ink); border-radius: 50%; background: #fff;
}
.radio input::before { content: ""; width: .9rem; height: .9rem; border-radius: 50%; background: var(--ink); transform: scale(0); }
.radio input:checked::before { transform: scale(1); }
.field > label.radio { display: flex; }

/* hidden 属性は、他のどの表示指定よりも優先する */
[hidden] { display: none !important; }
