/*
 * いつか帳 — 共通スタイル (spec §1.5 / §8.8)。
 * ストアおよび艦隊既存アプリのノートブック風・クラフト調ミニマルを踏襲する。
 *
 * ⚠ CSP が style-src 'self' なので、inline <style> と style 属性は使えない。
 *    JS から見た目を変えるときは classList の付け替えで行うこと。
 *
 * 構成:
 *   1. トークンと下地          … /join と アプリ本体で共有
 *   2. /join が使う部品        … .sheet / .btn / .notice / .trip-name
 *   3. アプリ本体 (body.app)   … app bar / 一覧 / カード / シート / トースト
 */

/* フォントは HTML 側の <link rel="stylesheet"> で並列に読む。
   ここで @import すると CSS の取得が直列になり LCP 目標 (2.5s) に効く。 */

/* ══ 1. トークンと下地 ══════════════════════════════════════════════════ */

:root {
  --color-paper: #fdf6e3;
  --color-paper-dark: #f5ecda;
  --color-ink: #1a1a2e;
  --color-ink-light: #4a4a6a;
  --color-paper-line: #c8d8e8;
  /*
   * ⚠ spec §8.8 は `#2980b9` を指定しているが、**同じ spec の §4.10 が要求する
   *   コントラスト比 4.5:1 を満たせない**ので 1 段暗くしてある (PR-F の Lighthouse 実測):
   *
   *     白文字 on #2980b9        = 4.3:1  → AA 未達 (「はじめる」等のボタン全部)
   *     #2980b9 文字 on 用紙色   = 4.0:1  → AA 未達 (「リンク」「マップで ひらく」等)
   *     白文字 on #2471a3        = 5.3:1  ✓
   *     #2471a3 文字 on 用紙色   = 5.0:1  ✓
   *
   *   spec の 2 つの条項が衝突していたので、**目の要求 (§4.10) の側を正とした**。
   *   見た目はほぼ同じ青のまま。ここを明るく戻すと a11y スコアが 95 → 92 に落ちる。
   */
  --color-accent: #2471a3;
  --color-border: #d5c8b8;
  --color-danger: #b5533f;
}

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

body {
  background-color: var(--color-paper);
  background-image: repeating-linear-gradient(
    transparent,
    transparent 31px,
    var(--color-paper-line) 31px,
    var(--color-paper-line) 32px
  );
  color: var(--color-ink);
  font-family: "Kiwi Maru", serif;
  line-height: 2rem;
  min-height: 100dvh;
  padding: 24px 16px;
}

.brand {
  font-family: "Caveat", "Kiwi Maru", cursive;
  font-size: 28px;
  color: var(--color-accent);
  text-align: center;
  margin-bottom: 8px;
}

.sheet {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 20px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--color-border);
  border-radius: 10px;
}

h2 {
  font-size: 18px;
  margin-bottom: 12px;
}

p {
  margin-bottom: 12px;
}

.muted {
  color: var(--color-ink-light);
  font-size: 14px;
}

.trip-name {
  font-size: 20px;
  font-weight: 500;
  /* 招待の旅名は未検証のユーザ入力。1 行に固定し、はみ出しは省略する
     (§7.5.1 対策 2 — 改行や記号でフィッシング文面を組ませない)。 */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

/* タップ領域は 44x44 px 以上 (spec §4.10)。 */
.btn {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 20px;
  padding: 12px 16px;
  font-family: inherit;
  font-size: 16px;
  color: #fff;
  background: var(--color-accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}

.btn:disabled {
  background: var(--color-border);
  cursor: default;
}

.btn-secondary {
  color: var(--color-ink);
  background: var(--color-paper-dark);
  border: 1px solid var(--color-border);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
  border: none;
}

.btn-small {
  width: auto;
  min-height: 44px;
  margin-top: 0;
  padding: 8px 14px;
  font-size: 14px;
  flex: 0 0 auto;
}

.notice {
  padding: 12px;
  border-left: 4px solid var(--color-accent);
  background: var(--color-paper-dark);
  font-size: 14px;
}

.notice-error {
  border-left-color: var(--color-danger);
}

[hidden] {
  display: none !important;
}

/* フォーカスの可視化を消さない (spec §4.10)。 */
:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ══ 3. アプリ本体 ══════════════════════════════════════════════════════ */

body.app {
  padding: 0;
  /* FAB とトーストがコンテンツ末尾に重ならないように余白を確保する。 */
  padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
}

/* シート表示中は背後をスクロールさせない (style 属性が使えないので class で) */
body.sheet-open {
  overflow: hidden;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--color-paper);
  color: var(--color-ink);
  padding: 12px 16px;
  z-index: 100;
}

.skip-link:focus {
  left: 0;
}

.app-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-top, 0px));
  background: var(--color-paper);
  border-bottom: 1px solid var(--color-border);
}

.app-bar .brand {
  flex: 1 1 auto;
  margin: 0;
  font-size: 20px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-bar-actions {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
}

.icon-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.4;
  color: var(--color-ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  /* 折り返すと 44px の行が 3 行に伸びて app bar が崩れる */
  white-space: nowrap;
}

.icon-btn:hover {
  border-color: var(--color-border);
}

.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
}

.screen:focus {
  outline: none;
}

.section-title {
  margin: 28px 0 8px;
  font-size: 16px;
}

.empty {
  margin: 32px 0;
  text-align: center;
  color: var(--color-ink-light);
}

.count-note {
  margin-top: 16px;
  text-align: right;
}

/* ── カード一覧 ───────────────────────────────────────────────────────── */

.card-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  line-height: 1.7rem;
}

.trip-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0;
}

.trip-card-main {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 auto;
  min-width: 0;
  padding: 12px 14px;
  color: inherit;
  text-decoration: none;
}

.trip-card.archived {
  padding: 12px 14px;
  opacity: 0.75;
}

.trip-emoji {
  flex: 0 0 auto;
  font-size: 28px;
  line-height: 1;
}

.trip-card-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1 1 auto;
}

.trip-card-name {
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trip-card-meta {
  font-size: 13px;
}

/* ── ツールバー (フィルタ / ソート) ───────────────────────────────────── */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.toolbar-group {
  display: flex;
  gap: 6px;
}

.chip {
  min-height: 44px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--color-ink);
  background: var(--color-paper-dark);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

/* 選択状態は色だけでなく枠の太さでも示す (spec §4.10)。
   aria-pressed も JS 側で必ず併せて更新している。 */
.chip-on {
  color: #fff;
  background: var(--color-accent);
  border-color: var(--color-accent);
  font-weight: 500;
}

.chip:disabled {
  opacity: 0.5;
  cursor: default;
}

/* 既出のエリア = 破線チップ (spec §8.3) */
.chip-suggest {
  border-style: dashed;
  background: transparent;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.area-suggest {
  margin: -4px 0 12px;
}

/* ── スポットカード ───────────────────────────────────────────────────── */

.spot-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* 「いった」「やめた」は薄くなって下に沈む（消えない、spec §8.4）。
   並べ替えは JS 側、見た目の後退はここ。 */
.spot-card.status-went,
.spot-card.status-skip {
  opacity: 0.6;
  background: rgba(255, 255, 255, 0.35);
}

.spot-card.pending {
  opacity: 0.55;
  border-style: dashed;
}

.spot-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.spot-open {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  padding: 0;
  font-family: inherit;
  font-size: 17px;
  line-height: 1.6rem;
  text-align: left;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

.spot-name {
  display: block;
  overflow-wrap: anywhere;
}

.status-chip {
  flex: 0 0 auto;
  font-size: 13px;
  padding: 4px 10px;
  min-height: 44px;
}

.spot-card.status-want .status-chip {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.spot-memo {
  margin: 0;
  font-size: 14px;
  color: var(--color-ink-light);
  overflow-wrap: anywhere;
}

.spot-links {
  display: flex;
  gap: 16px;
  margin: 0;
  font-size: 14px;
}

.spot-links a {
  color: var(--color-accent);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.spot-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.spot-by {
  font-size: 13px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.want-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  min-width: 56px;
  justify-content: center;
  padding: 4px 10px;
  font-family: inherit;
  font-size: 15px;
  color: var(--color-ink-light);
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  cursor: pointer;
}

/* ♥ の on/off は塗り (♥) と中抜き (♡) の**字形**で示す。
   色は補助にとどめる (spec §4.10 — 色だけに依存させない)。 */
.want-btn.want-on {
  color: var(--color-danger);
  border-color: var(--color-danger);
}

.want-icon {
  font-size: 16px;
  line-height: 1;
}

/* ── FAB ─────────────────────────────────────────────────────────────── */

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 30;
  min-height: 52px;
  padding: 12px 20px;
  font-family: inherit;
  font-size: 16px;
  color: #fff;
  background: var(--color-accent);
  border: none;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(26, 26, 46, 0.25);
  cursor: pointer;
}

/* ── シート / ダイアログ ──────────────────────────────────────────────── */

.sheet-host {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(26, 26, 46, 0.4);
  overflow-y: auto;
}

/* 確認ダイアログはシートの上に重なる (core.js の layer 参照) */
.dialog-host {
  z-index: 50;
  align-items: center;
}

.sheet-panel {
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 20px 16px calc(24px + env(safe-area-inset-bottom, 0px));
  background: var(--color-paper);
  border: 1px solid var(--color-border);
  border-radius: 14px 14px 0 0;
}

.dialog-host .sheet-panel {
  margin: 16px;
  border-radius: 14px;
  max-width: 420px;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 16px;
}

.sheet-head h2 {
  margin: 0;
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sheet-actions .btn {
  margin-top: 12px;
}

.confirm p {
  font-size: 15px;
}

.menu-items {
  display: flex;
  flex-direction: column;
}

.menu-items .btn {
  margin-top: 8px;
}

/* ── フォーム ─────────────────────────────────────────────────────────── */

.field {
  display: block;
  margin-bottom: 14px;
}

.field-label {
  display: block;
  font-size: 14px;
  color: var(--color-ink-light);
  margin-bottom: 4px;
}

.input {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  font-family: inherit;
  /* 16px 未満だと iOS Safari がフォーカス時にズームする */
  font-size: 16px;
  color: var(--color-ink);
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.input[readonly] {
  background: var(--color-paper-dark);
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  font-size: 15px;
  margin-bottom: 14px;
}

.check input {
  width: 22px;
  height: 22px;
}

.more {
  margin: 4px 0 12px;
}

.more > summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  font-size: 15px;
  color: var(--color-accent);
  cursor: pointer;
}

.more-body {
  padding-top: 12px;
}

.hint {
  font-size: 13px;
  color: var(--color-ink-light);
  margin-bottom: 12px;
}

.warn {
  font-size: 13px;
  color: var(--color-danger);
  margin-bottom: 12px;
}

.spot-detail-meta p {
  font-size: 13px;
  margin-bottom: 4px;
}

/* ── メンバー / 招待 ─────────────────────────────────────────────────── */

.member-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
  background: var(--color-paper-dark);
  border: 1px solid var(--color-border);
  border-radius: 50%;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.member-body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
}

.member-name {
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.member-meta {
  font-size: 13px;
}

.invite-stat {
  font-size: 15px;
  margin-bottom: 4px;
}

.invite-fresh .input {
  font-size: 14px;
}

/* ── ゴミ箱 ───────────────────────────────────────────────────────────── */

.trash-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.trash-body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
}

.trash-name {
  font-size: 16px;
  overflow-wrap: anywhere;
}

.trash-meta {
  font-size: 13px;
}

/* ── S0 初回起動 ─────────────────────────────────────────────────────── */

.intro {
  margin-top: 24px;
}

.intro-lead {
  font-size: 20px;
  line-height: 2.2rem;
  margin-bottom: 20px;
}

.intro-points {
  list-style: none;
  margin-bottom: 20px;
}

.intro-points li {
  position: relative;
  padding-left: 20px;
  margin-bottom: 8px;
  font-size: 15px;
}

.intro-points li::before {
  content: "・";
  position: absolute;
  left: 0;
}

/* ── トースト ─────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 12px;
  width: calc(100% - 32px);
  max-width: 420px;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--color-paper);
  background: var(--color-ink);
  border-radius: 10px;
}

.toast-text {
  flex: 1 1 auto;
}

.toast-action {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 4px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--color-paper);
  background: transparent;
  border: 1px solid var(--color-paper);
  border-radius: 8px;
  cursor: pointer;
}
