/* ===========================================================================
 * style.css — 見た目は仮（図形と文字のみ）
 * ・スマホ縦持ち幅 375px を基準に組み、PC では中央 1 カラムで固定
 * ・タップ領域は最低 44px（--tap）を守る
 * =========================================================================== */

:root {
  --tap: 44px;                 /* タップ領域の最小寸法。ここを一元管理する */
  --col: 420px;                /* PC 表示時のカラム幅上限 */
  --tabbar-h: 60px;

  --bg:        #16150f;
  --panel:     #23211a;
  --panel-2:   #2c2a21;
  --line:      #4a463a;
  --text:      #e8e3d4;
  --text-dim:  #a49e8b;
  --accent:    #c8a24a;
  --unread-bg: #3a3320;
  --unread-ln: #c8a24a;
  --danger:    #8a3b32;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #0d0c08;
  color: var(--text);
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "MS PMincho", serif;
  font-size: 16px;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}

/* ---------- 全体レイアウト ---------- */
.app {
  position: relative;
  width: 100%;
  max-width: var(--col);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  overflow-x: hidden;
}

.screens {
  display: block;
  padding: 0 16px calc(var(--tabbar-h) + 24px);
}
.app.no-tabbar .screens { padding-bottom: 24px; }

.screen[hidden] { display: none; }

/* ---------- 見出し ---------- */
.head {
  padding: 20px 0 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}
.head--sub { margin-top: 28px; }
.head__title { margin: 0; font-size: 22px; letter-spacing: .08em; }
.head__title--sm { font-size: 17px; color: var(--text-dim); }
.head__sub { margin: 4px 0 0; font-size: 13px; color: var(--text-dim); }

.empty {
  margin: 40px 0;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
}

/* ---------- ボタン共通（タップ領域 44px 以上） ---------- */
.btn {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--panel-2);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.4;
  cursor: pointer;
}
.btn:active { background: var(--line); }

.btn--primary {
  display: block;
  width: 100%;
  margin-top: 24px;
  min-height: 52px;
  border-color: var(--accent);
  background: var(--accent);
  color: #201c10;
  font-size: 17px;
  letter-spacing: .12em;
}
.btn--danger { border-color: var(--danger); background: var(--danger); color: #fff; }
.btn--back {
  display: inline-block;
  margin-bottom: 10px;
  padding: 8px 14px;
  font-size: 14px;
}

/* ---------- 1. 建国画面 ---------- */
.founding { padding: 40px 4px 24px; }
.founding__banner {
  margin: 0 0 28px;
  padding: 14px 16px;
  border: 1px solid var(--danger);
  border-left-width: 4px;
  background: #2a1a17;
  font-size: 14px;
  line-height: 1.8;
  white-space: pre-line;   /* 告知文の改行を活かす */
}
.founding__title {
  margin: 0 0 20px;
  font-size: 30px;
  letter-spacing: .18em;
  text-align: center;
  color: var(--accent);
}
.founding__lead {
  margin: 0 0 36px;
  text-align: center;
  font-size: 14px;
  color: var(--text-dim);
}
.founding__label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
.founding__input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 17px;
}
.founding__note { margin: 8px 0 0; font-size: 12px; color: var(--text-dim); }

/* ---------- 2. 年表画面 ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }

.entry {
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);   /* カテゴリ色は JS が上書きする */
  border-radius: 2px;
  background: var(--panel);
}
/* 未読は背景色で既読と区別する。
   左の色帯はカテゴリ色専用なので、未読では色を上書きしない。 */
.entry--unread {
  background: var(--unread-bg);
}
.entry__meta {
  display: flex;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--text-dim);
}
.entry__cat {
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 2px;
}
.entry--unread .entry__new { color: var(--accent); }
.entry__text { margin: 0; font-size: 15px; }

.entry--fall {
  border-color: var(--danger);
  background: #2a1a17;
  text-align: center;
}
.entry--fall .entry__text { font-size: 17px; letter-spacing: .1em; }

/* ---------- 3. 政庁画面 ---------- */
.slider { margin-bottom: 18px; }
.slider__head {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  margin-bottom: 2px;
}
.slider__val { color: var(--accent); font-variant-numeric: tabular-nums; }
/* input[type=range] 自体を 44px 高さにしてタップ領域を確保 */
.slider__input {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: var(--tap);
  margin: 0;
  background: transparent;
  cursor: pointer;
}
.slider__input::-webkit-slider-runnable-track {
  height: 6px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 3px;
}
.slider__input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px; height: 28px; margin-top: -12px;
  border: 1px solid #8d7327; border-radius: 50%;
  background: var(--accent);
}
.slider__input::-moz-range-track {
  height: 6px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 3px;
}
.slider__input::-moz-range-thumb {
  width: 26px; height: 26px; border: 1px solid #8d7327; border-radius: 50%; background: var(--accent);
}

.alloc-total { margin: 4px 0 0; font-size: 13px; color: var(--text-dim); text-align: right; }

.params { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.param {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--panel);
}
.param__name { font-size: 13px; color: var(--text-dim); }
.param__val { font-size: 26px; color: var(--accent); font-variant-numeric: tabular-nums; }
.param__bar { height: 4px; background: var(--panel-2); border: 1px solid var(--line); }
.param__fill { height: 100%; background: var(--accent); }

/* ---------- 4. 書庫画面 ---------- */
.archive { list-style: none; margin: 0; padding: 0; }
.archive__item { margin-bottom: 10px; }
.archive__btn {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
}
.archive__btn:active { background: var(--panel-2); }
.archive__sub { display: block; margin-top: 2px; font-size: 12px; color: var(--text-dim); }

/* ---------- 5. 画面下部の固定タブ ---------- */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  width: 100%;
  max-width: var(--col);
  height: var(--tabbar-h);
  border-top: 1px solid var(--line);
  background: var(--panel-2);
}
.tabbar[hidden] { display: none; }
.tab {
  flex: 1 1 0;
  min-height: var(--tap);
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 15px;
  letter-spacing: .1em;
  cursor: pointer;
}
.tab:last-child { border-right: 0; }
.tab.is-active { color: #201c10; background: var(--accent); }

/* ---------- デバッグパネル（右上・折りたたみ） ---------- */
/* 右上の常設バー。共有アイコンと DEBUG が横に並ぶ */
.topbar {
  position: fixed;
  top: 6px;
  left: 50%;
  transform: translateX(calc(var(--col) / 2 - 100%));
  z-index: 50;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 6px;
  width: 292px;
  max-width: calc(100vw - 12px);
}
.debug {
  position: relative;      /* 展開部を絶対配置にして、ボタンの幅だけを占める */
  flex: 0 0 auto;
  text-align: right;
  font-family: "Consolas", "Courier New", monospace;
}
.debug__toggle {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(20,19,13,.92);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}
.debug__body {
  position: absolute;
  right: 0;
  top: 100%;
  width: 236px;
  margin-top: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(20,19,13,.96);
  text-align: left;
}
.debug__body[hidden] { display: none; }
.debug__row { display: flex; gap: 6px; margin-bottom: 8px; }
.debug__row .btn { flex: 1 1 0; padding: 6px 2px; font-family: inherit; font-size: 12px; }
.debug__dump {
  margin: 0 0 8px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-all;
}
.debug .btn--danger { width: 100%; font-family: inherit; font-size: 12px; }

/* 画面幅がカラム幅より狭いとき（スマホ）はデバッグパネルを右端に寄せる */
@media (max-width: 440px) {
  .topbar { left: auto; right: 6px; transform: none; }
}

/* ===========================================================================
 * 追加分（視覚方針バッチ）
 * =========================================================================== */

/* ---------- カテゴリ記号（色帯とセットで左端に置く） ---------- */
.entry__mark {
  font-size: 13px;
  line-height: 1;
  /* 色は JS がカテゴリ色で入れる。記号そのものが識別子なので、
     色が見えなくてもカテゴリ名の表示で意味が通る。 */
}

/* ---------- 帰還要約（年表の最上部・タップで閉じる） ---------- */
.recap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: var(--tap);
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid var(--accent);
  border-left: 4px solid var(--accent);
  border-radius: 2px;
  background: #2b2617;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  text-align: left;
  cursor: pointer;
}
.recap[hidden] { display: none; }
.recap:active { background: #362f1c; }
.recap__text { flex: 1 1 auto; }
.recap__close { flex: 0 0 auto; font-size: 12px; color: var(--text-dim); }


/* ---------- 建国画面：年表見本 ---------- */
.sample {
  margin-top: 34px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.sample__title {
  margin: 0 0 4px;
  font-size: 15px;
  letter-spacing: .12em;
  color: var(--text-dim);
}
.sample__note { margin: 0 0 12px; font-size: 12px; color: var(--text-dim); }
.timeline--sample .entry { margin-bottom: 8px; opacity: .92; }
.timeline--sample .entry__text { font-size: 14px; }

/* ---------- 建国画面：書庫リンク ---------- */
.founding__archive { margin: 22px 0 0; text-align: center; }
.linkbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  min-width: 120px;
  padding: 10px 18px;
  border: 0;
  border-bottom: 1px solid var(--text-dim);
  border-radius: 0;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}
.linkbtn:active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- 共有画像の生成に使う作業用 canvas（画面には出さない） ---------- */
.offscreen {
  position: absolute;
  left: -99999px;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* ---------- 建国行（滅亡行と対になる固定行） ---------- */
.entry--found {
  border-color: #7d5f57;
  background: #2a211e;
  text-align: center;
}
.entry--found .entry__text { font-size: 17px; letter-spacing: .1em; }

/* ---------- 導入案内（建国直後の年表の最上部） ---------- */
.intro {
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px solid #7d5f57;
  border-left: 4px solid #c08c7d;
  border-radius: 2px;
  background: #241d1b;
}
.intro[hidden] { display: none; }
.intro__text { margin: 0; font-size: 14px; line-height: 1.9; color: var(--text); }

/* 文中のリンク。見た目は行内のままで、タップ領域だけ 44px 以上にする
   （上下の padding を負の margin で打ち消して、行の高さを増やさない） */
.intro__link {
  display: inline-block;
  min-width: 44px;
  padding: 13px 10px;      /* 20px + 13px*2 = 46px の当たり判定 */
  margin: -13px 0;         /* 見た目の行の高さは増やさない */
  border: 0;
  border-bottom: 1px solid var(--accent);
  border-radius: 0;
  background: transparent;
  color: var(--accent);
  font-family: inherit;
  font-size: 14px;
  line-height: 20px;
  vertical-align: baseline;
  cursor: pointer;
}
.intro__link:active { background: #33291f; }

/* ---------- デバッグパネルの横幅いっぱいのボタン ---------- */
.debug__wide { width: 100%; margin-bottom: 8px; font-family: inherit; font-size: 12px; }

/* ===========================================================================
 * 追加分（共有アイコン / 予告ゲージ / プレビュー）
 * =========================================================================== */

/* ---------- 右上のアイコンボタン（共有） ---------- */
.iconbtn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(20,19,13,.92);
  color: var(--accent);
  cursor: pointer;
}
.iconbtn[hidden] { display: none; }
.iconbtn:active { background: #2b2617; }
.iconbtn[disabled] { color: var(--text-dim); cursor: default; }
.iconbtn__svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
}

/* ---------- 次の出来事の予告 ---------- */
.omen {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.omen[hidden] { display: none; }

.omen__gauge {
  position: relative;
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
}
.omen__gauge[hidden] { display: none; }
.omen__ring { width: 56px; height: 56px; transform: rotate(-90deg); }
.omen__track { fill: none; stroke: var(--panel-2); stroke-width: 4; }
.omen__fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  /* 円周 = 2πr = 2 * π * 24 ≒ 150.8 */
  stroke-dasharray: 150.8;
  stroke-dashoffset: 150.8;
  transition: stroke-dashoffset .9s linear;
}
.omen__label {
  position: absolute;
  left: 0; top: 0;
  width: 56px; height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: .02em;
}
.omen__caption { margin: 0; font-size: 12px; color: var(--text-dim); line-height: 1.6; }

/* ---------- 新しく書かれた項目がふわりと現れる ---------- */
@keyframes entryEnter {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.entry--enter { animation: entryEnter .5s ease-out both; }

@media (prefers-reduced-motion: reduce) {
  .entry--enter { animation: none; }
  .omen__fill { transition: none; }
}

/* ---------- 共有画像のプレビュー ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6,6,4,.82);
}
.modal__panel {
  position: relative;
  width: 100%;
  max-width: 340px;
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  padding: 16px;
  border: 1px solid var(--accent);
  border-radius: 2px;
  background: var(--bg);
}
.modal__title {
  margin: 0 0 10px;
  font-size: 15px;
  letter-spacing: .1em;
  color: var(--accent);
  text-align: center;
}
.modal__body {
  flex: 1 1 auto;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.modal__status { margin: 0; font-size: 14px; color: var(--text-dim); text-align: center; }
.modal__status[hidden] { display: none; }
.modal__img {
  display: block;
  max-width: 100%;
  max-height: 52vh;
  border: 1px solid var(--line);
}
.modal__img[hidden] { display: none; }
.modal__toast {
  margin: 10px 0 0;
  padding: 8px 10px;
  border: 1px solid var(--accent);
  border-radius: 2px;
  background: #2b2617;
  color: var(--accent);
  font-size: 14px;
  text-align: center;
  letter-spacing: .1em;
}
.modal__toast[hidden] { display: none; }
.modal__actions { display: flex; gap: 8px; margin-top: 14px; }
.modal__btn { flex: 1 1 0; min-height: var(--tap); }
.modal__btn[hidden] { display: none; }
.modal__btn--save {
  border-color: var(--accent);
  background: var(--accent);
  color: #201c10;
}

/* ===========================================================================
 * 国の眺め（3Dビュー）と、年表の全画面表示
 * =========================================================================== */

/* ---------- 眺め ---------- */
.view {
  position: relative;
  height: 55vh;
  min-height: 240px;
  margin: 0 -16px 14px;          /* 画面の端まで見せる */
  background: #1a1611;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}
.view__canvas { position: absolute; inset: 0; }
.view__canvas canvas { display: block; width: 100%; height: 100%; }

.view__fallback {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  margin: 0; padding: 20px;
  color: var(--text-dim); font-size: 13px; line-height: 1.8; text-align: center;
}
.view__fallback[hidden] { display: none; }

.view__turn {
  position: absolute; top: 50%; transform: translateY(-50%);
  z-index: 3;
  width: var(--tap); height: 60px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 2px;
  background: rgba(20,17,12,.7); color: var(--accent);
  font-family: inherit; font-size: 22px; line-height: 1; cursor: pointer;
}
.view__turn:active { background: rgba(60,50,28,.85); }
.view__turn:disabled { opacity: .35; cursor: default; }
.view__turn--l { left: 6px; }
.view__turn--r { right: 6px; }
.view__turn[hidden] { display: none; }

/* 予告ゲージは眺めの上に重ねる */
.view .omen {
  position: absolute; left: 8px; top: 8px; z-index: 3;
  margin: 0; padding: 5px 10px 5px 6px;
  border: 1px solid var(--line); border-radius: 2px;
  background: rgba(20,17,12,.74);
  max-width: calc(100% - 120px);
}
.view .omen__caption { color: var(--text-dim); }

/* ---------- 直近の年表 ---------- */
.timeline--recent .entry { margin-bottom: 10px; }

.btn--wide {
  display: block; width: 100%;
  margin: 4px 0 8px;
  min-height: var(--tap);
  border-color: var(--line);
  background: var(--panel-2);
  color: var(--text);
  letter-spacing: .08em;
}
.btn--wide:active { background: var(--line); }

/* ---------- 年表・全文（全画面） ---------- */
.full {
  position: fixed; inset: 0; z-index: 60;
  display: flex; flex-direction: column;
  background: var(--bg);
}
.full[hidden] { display: none; }
.full__head {
  flex: 0 0 auto;
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.full__title { margin: 0; font-size: 20px; letter-spacing: .08em; }
.full__sub { margin: 3px 0 0; font-size: 12px; color: var(--text-dim); }
.full__body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px calc(20px + env(safe-area-inset-bottom));
}
@media (min-width: 440px) {
  .full { left: 50%; right: auto; transform: translateX(-50%); width: 100%; max-width: var(--col);
          border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}

/* ---------- 眺めをタップしたときの小窓 ---------- */
.modal__panel--small { max-width: 300px; }
.pick__text {
  margin: 0;
  padding: 14px 4px 4px;
  font-size: 15px;
  line-height: 1.9;
  color: var(--text);
  text-align: center;
}

/* ===========================================================================
 * 回想の帯と、開幕再生のスキップ
 * =========================================================================== */
.recall {
  position: absolute; left: 0; right: 0; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px 7px 12px;
  background: rgba(20,17,12,.9);
  border-bottom: 1px solid var(--accent);
}
.recall[hidden] { display: none; }
.recall__label {
  flex: 1 1 auto;
  font-size: 13px; line-height: 1.5; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.recall__back {
  flex: 0 0 auto;
  min-height: var(--tap); min-width: 96px;
  padding: 6px 12px;
  border: 1px solid var(--accent); border-radius: 2px;
  background: var(--accent); color: #201c10;
  font-family: inherit; font-size: 13px; cursor: pointer;
}
.recall__back:active { background: #b08e3d; }

/* 開幕再生を飛ばすための、眺め全体をおおう当たり */
.skip {
  position: absolute; inset: 0; z-index: 4;
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 14px;
  border: 0; background: transparent;
  color: var(--text-dim); font-family: inherit; font-size: 12px;
  letter-spacing: .08em; cursor: pointer;
}
.skip[hidden] { display: none; }

/* 年表の行はタップできる */
.entry--tappable { cursor: pointer; }
.entry--tappable:active { filter: brightness(1.2); }
.entry--recalling { border-color: var(--accent); }
