/* Hallmark · redesign · macrostructure: App Shell (top-bar + segmented views + reading list) · tone: 古書/詞華集・静けさ・可読性最優先
 * paper band: light(古紙セピア) · display: roman-mincho-serif · accent hue: 臙脂 warm-red ~5deg（goal-roadmap 暗×金と paper band で差別化）
 * Hallmark · pre-emit critique: P5 H4 E5 S5 R5 V5
 * ことば帖 アプリスタイル。全色・寸法は tokens.css のトークンを参照（インライン値禁止）。
 * 反スロップ: 左ボーダーカード不使用 / hover は (hover:hover) 端末のみ / focus-visible は即時表示。 */

@import url("/css/tokens.css");

/* ============================================================
   ベース
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html, body { overflow-x: clip; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.container { width: 100%; max-width: var(--container); margin-inline: auto; }

/* ============================================================
   ボタン（8状態: default / hover / focus / active / disabled / loading）
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-s);
  min-height: 44px; padding: 0 var(--space-l);
  border: 1px solid var(--border); border-radius: var(--radius-button);
  background: var(--surface-2); color: var(--text);
  font-size: var(--text-body); font-weight: 600; line-height: 1;
  transition: background var(--dur) var(--ease-out), border-color var(--dur) var(--ease-out), transform var(--dur) var(--ease-out);
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--text-on-accent); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-2); }
.btn-danger { background: transparent; border-color: var(--danger-line); color: var(--danger); }
.btn-block { width: 100%; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-busy="true"] { opacity: 0.55; cursor: default; transform: none; }
@media (hover: hover) {
  .btn-primary:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); }
  .btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
  .btn-danger:hover:not(:disabled) { background: var(--danger-soft); }
}

/* アイコンボタン */
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; padding: 0;
  border: 1px solid transparent; border-radius: var(--radius-button);
  background: transparent; color: var(--text-2); font-size: 1.25rem; line-height: 1;
}
@media (hover: hover) { .btn-icon:hover { background: var(--surface-2); } }
.btn-icon:active { transform: translateY(1px); }

/* フォーカスリング（即時・全インタラクティブ要素共通） */
:where(.btn, .btn-icon, .tab, .input, .search-input, textarea, select, .star-btn, .chip-select-item, .card-tap):focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

/* ============================================================
   ログイン
   ============================================================ */
.login-screen {
  min-height: 100dvh; display: grid; place-items: center;
  padding: var(--space-l); background: radial-gradient(120% 80% at 50% 0%, var(--surface) 0%, var(--bg) 55%, var(--bg-deep) 100%);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius-card);
  padding: var(--space-xl); box-shadow: var(--shadow-pop), var(--inner-edge);
  text-align: center;
}
.login-brand { font-family: var(--font-serif); font-size: var(--text-display); font-weight: 700; letter-spacing: 0.04em; }
.login-brand .mark, .brand .mark { color: var(--accent); }
.login-lead { margin: var(--space-s) 0 var(--space-xl); color: var(--text-3); font-size: var(--text-sm); }
.login-card .field { text-align: left; }

/* ============================================================
   フォーム要素
   ============================================================ */
.field { display: flex; flex-direction: column; gap: var(--space-xs); margin-bottom: var(--space-m); }
.field > label { font-size: var(--text-sm); font-weight: 600; color: var(--text-2); }
.field .hint { font-size: var(--text-caption); color: var(--text-3); }
.input, .search-input, textarea, select {
  width: 100%; min-height: 44px; padding: 10px var(--space-m);
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-button);
  transition: border-color var(--dur) var(--ease-out);
}
textarea { min-height: 120px; resize: vertical; line-height: 1.7; }
.input:focus, .search-input:focus, textarea:focus, select:focus { border-color: var(--accent); outline: none; }
.input::placeholder, .search-input::placeholder, textarea::placeholder { color: var(--text-3); }
.form-error { min-height: 1.2em; margin: var(--space-s) 0 0; color: var(--danger); font-size: var(--text-sm); }

/* ============================================================
   アプリヘッダー（sticky）
   ============================================================ */
.app-header {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border-soft);
  padding: max(var(--space-s), env(safe-area-inset-top)) var(--space-m) var(--space-s);
}
.header-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-s); max-width: var(--container); margin-inline: auto; }
.brand { font-family: var(--font-serif); font-size: var(--text-h2); font-weight: 700; letter-spacing: 0.03em; }
.search-wrap { position: relative; max-width: var(--container); margin: var(--space-s) auto 0; }
.search-input { padding-right: 40px; }
.search-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; border: 0; border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--text-2); font-size: 1.1rem; line-height: 1;
}

/* タブ（セグメント） */
.tabs {
  display: flex; gap: var(--space-xs); max-width: var(--container); margin: var(--space-s) auto 0;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; min-height: 38px; padding: 0 var(--space-m);
  border: 1px solid var(--border-soft); border-radius: var(--radius-pill);
  background: transparent; color: var(--text-3); font-size: var(--text-sm); font-weight: 600;
  transition: color var(--dur) var(--ease-out), background var(--dur) var(--ease-out), border-color var(--dur) var(--ease-out);
}
.tab[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--text-on-accent); }

/* ============================================================
   メイン / ビュー
   ============================================================ */
main { padding: var(--space-l) var(--space-m) calc(96px + env(safe-area-inset-bottom)); }
.view { display: flex; flex-direction: column; gap: var(--space-m); }
.group-head {
  display: flex; align-items: baseline; gap: var(--space-s);
  margin: var(--space-m) 0 calc(-1 * var(--space-xs)); padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--border-soft);
}
.group-head:first-child { margin-top: 0; }
.group-head .g-label { font-family: var(--font-serif); font-size: var(--text-h3); font-weight: 700; }
.group-head .g-label.kana { color: var(--accent); font-family: var(--font-serif); }
.group-head .g-count { font-size: var(--text-caption); color: var(--text-3); }
.group-head .g-dot { width: 10px; height: 10px; border-radius: 50%; align-self: center; }

/* ============================================================
   言葉カード（左ボーダー型は使わない・全周ボーダー＋面）
   ============================================================ */
.q-card {
  position: relative;
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius-card);
  padding: var(--space-l); box-shadow: var(--shadow-card), var(--inner-edge);
}
.q-body {
  margin: 0; font-family: var(--font-serif);
  font-size: var(--quote-size); line-height: var(--quote-lh); color: var(--ink);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.q-source { margin-top: var(--space-m); font-size: var(--text-sm); color: var(--text-3); }
.q-source::before { content: "— "; color: var(--text-3); }
.q-memo {
  margin-top: var(--space-m); padding-top: var(--space-m); border-top: 1px dashed var(--border-soft);
  font-size: var(--text-sm); color: var(--text-2); white-space: pre-wrap; overflow-wrap: anywhere;
}
.q-foot { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-s); margin-top: var(--space-m); }
.q-foot .spacer { flex: 1 1 auto; }

/* チップ（カテゴリ・タグ） */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px; border-radius: var(--radius-pill);
  font-size: var(--text-caption); font-weight: 600; white-space: nowrap;
}
.chip.cat { background: var(--surface-2); color: var(--text-2); }
.chip.cat .swatch { width: 8px; height: 8px; border-radius: 50%; }
.chip.tag { background: transparent; border: 1px solid var(--border-soft); color: var(--text-3); }
.chip.tag::before { content: "#"; opacity: 0.6; }

/* 登録日（created_at の控えめキャプション） */
.q-date { font-size: var(--text-caption); color: var(--text-3); white-space: nowrap; }

/* ============================================================
   思考法カード（component-scope · 言葉と差別化）
   Hallmark · component: 思考法 (badge + serif title + sans reading-body)
   theme: 古書/詞華集（既存トークン継承）· 反スロップ: 左ボーダー不使用 / hover装飾なし / focus即時
   ============================================================ */
/* 「思考法」バッジ（臙脂soft地・深臙脂文字） */
.kind-badge {
  display: inline-flex; align-items: center;
  height: 22px; padding: 0 10px; border-radius: var(--radius-pill);
  background: var(--accent-soft); color: var(--accent-deep);
  font-size: var(--text-caption); font-weight: 700; letter-spacing: 0.06em;
}
/* 名称＝明朝の主役見出し */
.q-card.method .m-title {
  margin: var(--space-s) 0 var(--space-m);
  font-family: var(--font-serif); font-size: var(--text-h1); font-weight: 700;
  line-height: 1.45; color: var(--ink); overflow-wrap: anywhere;
}
/* 内容＝可読サンセリフ・改行保持（言葉本文の明朝とは別リズム） */
.q-card.method .m-body {
  margin: 0; font-family: var(--font-sans);
  font-size: var(--text-body); line-height: 1.85; color: var(--text);
  white-space: pre-wrap; overflow-wrap: anywhere;
}

/* お気に入りスター */
.star-btn { width: 40px; height: 40px; border: 0; background: transparent; color: var(--text-3); font-size: 1.3rem; line-height: 1; border-radius: var(--radius-button); }
.star-btn[aria-pressed="true"] { color: var(--accent); }

/* カード操作（編集・削除はメニュー化せず小さなテキストボタン） */
.q-actions { display: flex; gap: var(--space-xs); }
.q-actions .mini { height: 32px; padding: 0 10px; border: 1px solid var(--border-soft); border-radius: var(--radius-button); background: transparent; color: var(--text-3); font-size: var(--text-caption); font-weight: 600; }
@media (hover: hover) { .q-actions .mini:hover { color: var(--text); border-color: var(--border); } }

/* ============================================================
   空状態
   ============================================================ */
.empty { text-align: center; padding: var(--space-3xl) var(--space-m); color: var(--text-3); }
.empty .e-mark { font-size: 2.5rem; font-family: var(--font-serif); color: var(--accent-deep); }
.empty .e-title { margin: var(--space-m) 0 var(--space-xs); font-size: var(--text-h3); color: var(--text-2); font-weight: 700; }
.empty .e-sub { font-size: var(--text-sm); }

/* ============================================================
   FAB（言葉を追加・親指リーチ）
   ============================================================ */
.fab {
  position: fixed; right: var(--space-l); bottom: calc(var(--space-l) + env(safe-area-inset-bottom)); z-index: 40;
  display: inline-flex; align-items: center; gap: var(--space-s);
  height: 52px; padding: 0 var(--space-l);
  border: 0; border-radius: var(--radius-pill);
  background: var(--accent); color: var(--text-on-accent); font-weight: 700; font-size: var(--text-body);
  box-shadow: var(--shadow-pop);
  transition: transform var(--dur) var(--ease-out), background var(--dur) var(--ease-out);
}
.fab .fab-plus { font-size: 1.4rem; line-height: 1; }
.fab:active { transform: translateY(1px) scale(0.99); }
@media (hover: hover) { .fab:hover { background: var(--accent-strong); } }

/* ============================================================
   メニュー ポップオーバー
   ============================================================ */
.menu-pop {
  position: fixed; z-index: 60; min-width: 200px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
  box-shadow: var(--shadow-pop); padding: var(--space-xs);
}
.menu-pop button {
  display: flex; align-items: center; gap: var(--space-s); width: 100%;
  min-height: 44px; padding: 0 var(--space-m); border: 0; border-radius: var(--radius-button);
  background: transparent; color: var(--text); font-size: var(--text-sm); text-align: left;
}
@media (hover: hover) { .menu-pop button:hover { background: var(--surface-2); } }
.menu-pop button.danger { color: var(--danger); }

/* ============================================================
   モーダル（モバイル＝ボトムシート）
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: var(--scrim);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
  animation: overlay-in var(--dur) var(--ease-out);
}
.modal {
  width: 100%; max-width: 640px; max-height: 92dvh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  padding: var(--space-l) var(--space-l) calc(var(--space-l) + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-pop);
  animation: sheet-in 0.22s var(--ease-out);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-s); margin-bottom: var(--space-l); }
.modal-title { font-family: var(--font-serif); font-size: var(--text-h2); font-weight: 700; }
.modal-foot { display: flex; gap: var(--space-s); margin-top: var(--space-l); }
.modal-foot .btn { flex: 1; }

/* カテゴリ選択チップ群 */
.chip-select { display: flex; flex-wrap: wrap; gap: var(--space-xs); }
.chip-select-item {
  height: 36px; padding: 0 var(--space-m); border: 1px solid var(--border); border-radius: var(--radius-pill);
  background: transparent; color: var(--text-2); font-size: var(--text-sm); font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip-select-item .swatch { width: 9px; height: 9px; border-radius: 50%; }
.chip-select-item[aria-pressed="true"] { background: var(--surface-2); border-color: var(--accent); color: var(--text); }

/* カテゴリ管理行 */
.cat-row { display: flex; align-items: center; gap: var(--space-s); padding: var(--space-s) 0; border-bottom: 1px solid var(--border-soft); }
.cat-row .swatch { width: 14px; height: 14px; border-radius: 50%; flex: 0 0 auto; }
.cat-row .c-name { flex: 1; min-width: 0; }
.cat-row input.input { min-height: 40px; }

/* ============================================================
   トースト
   ============================================================ */
.toast-host { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: var(--space-s); width: max-content; max-width: 92vw; }
.toast {
  padding: 10px var(--space-l); border-radius: var(--radius-pill);
  background: var(--ink); color: var(--paper-hi); font-size: var(--text-sm); font-weight: 600;
  box-shadow: var(--shadow-pop); animation: toast-in var(--dur) var(--ease-out);
}
.toast.err { background: var(--danger); color: var(--paper-hi); }

/* ============================================================
   アニメーション
   ============================================================ */
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-in { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ============================================================
   デスクトップ拡張
   ============================================================ */
@media (min-width: 720px) {
  .modal-overlay { align-items: center; padding: var(--space-l); }
  .modal { border-radius: var(--radius-card); }
  .fab { right: calc((100vw - var(--container)) / 2 + var(--space-s)); }
}
@media (min-width: 760px) {
  .fab { right: max(var(--space-l), calc((100vw - var(--container)) / 2 - 64px)); }
}

/* ============================================================
   モーション低減
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
