/* 羅針（Rashin）— スタイル。コンセプト＝「羅針盤」。静かな大人の上質さ・過度な演出は避ける。 */

:root {
  --font-serif: "Hiragino Mincho ProN", "YuMincho", "Yu Mincho", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;

  --bg: #f7f5f0;
  --bg-elevated: #fbfaf7;
  --fg: #2a2b2e;
  --muted: #706e68;
  --line: #e6e1d6;
  --card-bg: #ffffff;
  --accent: #33445f;
  --accent-gold: #a9824f;
  --chip-bg: #f0ede4;
  --chip-fg: #4b4a45;
  --danger: #a3402a;
  --overlay: rgba(30, 26, 20, 0.4);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1220;
    --bg-elevated: #101828;
    --fg: #e8e6df;
    --muted: #97a0b3;
    --line: #22304a;
    --card-bg: #121a2c;
    --accent: #7fa3d6;
    --accent-gold: #e0b872;
    --chip-bg: #1a2540;
    --chip-fg: #c9d3e6;
    --danger: #e08469;
    --overlay: rgba(4, 7, 14, 0.6);
  }
}

* {
  box-sizing: border-box;
}

/* hidden属性は常に効かせる（.modal-wrap や .view の display:flex に上書きされないように） */
[hidden] {
  display: none !important;
}
html,
body {
  margin: 0;
  padding: 0;
}
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}
h1,
h2 {
  font-family: var(--font-sans);
}
blockquote {
  margin: 0;
}
.muted {
  color: var(--muted);
}
.muted.small {
  font-size: 12px;
}

/* ---------- フォーム共通 ---------- */
.view label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 16px 0 6px;
}
.view textarea,
.view input[type="text"],
.view input[type="search"],
.view input[type="password"] {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--card-bg);
  color: var(--fg);
}
.view textarea {
  resize: vertical;
}
.view input:focus,
.view textarea:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  font-family: var(--font-sans);
  font-size: 15px;
  border-radius: 12px;
  padding: 12px 18px;
  border: 1px solid var(--line);
  background: var(--card-bg);
  color: var(--fg);
  cursor: pointer;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
button.primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
button.ghost {
  background: transparent;
}
button.ghost.danger {
  color: var(--danger);
  border-color: var(--danger);
}
button.small {
  font-size: 13px;
  padding: 8px 12px;
  margin-top: 8px;
}
.icon-btn {
  border: 0;
  background: none;
  font-size: 20px;
  padding: 4px 8px;
}
.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.btn-row button {
  flex: 1;
}
.btn-row.col {
  flex-direction: column;
}

/* ---------- 合言葉ゲート ---------- */
.gate-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.gate {
  max-width: 360px;
  width: 100%;
  text-align: center;
}
.gate-mark {
  font-size: 40px;
  margin-bottom: 8px;
}
.gate h1 {
  font-size: 22px;
  margin: 0 0 10px;
  letter-spacing: 0.06em;
}
.gate-desc {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 20px;
  line-height: 1.7;
}
.gate input {
  width: 100%;
  margin-bottom: 12px;
  font-family: inherit;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--card-bg);
  color: var(--fg);
}
.gate button {
  width: 100%;
}
.gate-err {
  color: var(--danger);
  font-size: 13px;
  min-height: 1.4em;
  margin-top: 10px;
}

/* ---------- ヘッダー ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
}
.brand h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.06em;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sync-state {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

/* 相棒＝呼吸する光（ダークモードのみ・reduced-motionでは静止） */
.compass-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-gold);
  display: inline-block;
  margin-right: 8px;
}
@media (prefers-color-scheme: dark) {
  .compass-dot {
    animation: breathe 3.2s ease-in-out infinite;
  }
}
@keyframes breathe {
  0%,
  100% {
    box-shadow: 0 0 3px 1px rgba(224, 184, 114, 0.35);
    opacity: 0.55;
  }
  50% {
    box-shadow: 0 0 12px 3px rgba(224, 184, 114, 0.75);
    opacity: 1;
  }
}

/* ---------- 本体・ボトムナビ ---------- */
.views {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 18px 108px;
}
.bottomnav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: var(--bg-elevated);
  border-top: 1px solid var(--line);
  padding: 6px 4px max(6px, env(safe-area-inset-bottom));
}
.navbtn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: 0;
  background: none;
  font-size: 11px;
  color: var(--muted);
  padding: 6px 2px;
  border-radius: 10px;
}
.navbtn.active {
  color: var(--accent);
  font-weight: 600;
}
.navicon {
  font-size: 18px;
}

/* ---------- 放り込む ---------- */
.review-label {
  font-size: 14px;
  color: var(--muted);
  margin: 4px 0 12px;
}
.quote-preview {
  font-family: var(--font-serif);
  font-size: 19px;
  line-height: 1.9;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px 22px;
  white-space: pre-wrap;
  word-break: break-word;
}
.add-status {
  font-size: 13px;
  color: var(--muted);
  min-height: 1.4em;
  margin-top: 8px;
}
.privacy {
  font-size: 12px;
  color: var(--muted);
  margin-top: 28px;
  line-height: 1.7;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.fade-in {
  animation: fadeIn 0.35s ease;
}

/* ---------- タグ ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--chip-fg);
}
.chip-sm {
  font-size: 11px;
  padding: 2px 8px;
}
.chip-toggle {
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  color: var(--fg);
}
.chip-toggle.on {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.chip-editable {
  background: var(--chip-bg);
}
.chip-remove {
  border: 0;
  background: none;
  color: inherit;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.chip-editor {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 0;
  min-height: 1.6em;
}
.chip-add input {
  width: 100%;
}
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.card-tags.center {
  justify-content: center;
}

/* ---------- 一覧・検索 ---------- */
.search-bar {
  margin-bottom: 12px;
}
.tag-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}
.quote-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.quote-card {
  width: 100%;
  text-align: left;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.quote-card:hover,
.quote-card:active {
  transform: perspective(700px) rotateX(1.6deg) rotateY(-1deg) translateY(-2px);
  box-shadow: 0 14px 34px -20px rgba(20, 20, 30, 0.35);
}
.quote-body {
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.85;
  margin: 0;
}
.quote-source {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}
.quote-meta-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}
.quote-date {
  color: var(--muted);
  font-size: 12px;
}
.origin-badge {
  font-size: 10px;
  letter-spacing: 0.05em;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 1px 7px;
}

/* ---------- 今日の1枚 ---------- */
.today-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding-top: 12px;
}
.today-card {
  width: 100%;
  max-width: 560px;
  min-height: 220px;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 44px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
  box-shadow: 0 20px 60px -30px rgba(20, 20, 30, 0.35);
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: transform;
}
.today-quote {
  font-family: var(--font-serif);
  font-size: clamp(20px, 2.6vw + 14px, 30px);
  line-height: 1.9;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}
.today-source {
  color: var(--muted);
  font-size: 14px;
  margin: 0;
}

/* ---------- 軸・対話：セグメント切替 ---------- */
.segmented {
  display: flex;
  gap: 4px;
  background: var(--chip-bg);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 20px;
}
.segbtn {
  flex: 1;
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
}
.segbtn.active {
  background: var(--card-bg);
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(20, 20, 30, 0.12);
}

/* ---------- 対話 ---------- */
.hint-note {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 16px;
  line-height: 1.7;
}
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 14px;
  min-height: 20px;
}
.chat-msg {
  max-width: 92%;
  display: flex;
  flex-direction: column;
}
.chat-msg.q {
  align-self: flex-end;
  align-items: flex-end;
}
.chat-msg.a {
  align-self: flex-start;
  align-items: flex-start;
}
.chat-bubble {
  display: inline-block;
  text-align: left;
  padding: 12px 16px;
  border-radius: 16px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.85;
  font-size: 15px;
}
.chat-msg.q .chat-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg.a .chat-bubble {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  font-family: var(--font-serif);
}
.chat-msg.loading .chat-bubble {
  color: var(--muted);
  font-family: var(--font-sans);
}
.chat-related-label {
  font-size: 11px;
  color: var(--muted);
  margin: 8px 0 4px;
}
.chat-related {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chat-related-chip {
  max-width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--chip-bg);
  color: var(--chip-fg);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.6;
  cursor: pointer;
  white-space: normal;
}
.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-top: 6px;
}
.chat-input-row textarea {
  flex: 1;
  width: auto;
  font-family: inherit;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--card-bg);
  color: var(--fg);
  resize: vertical;
}
.chat-input-row textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.chat-input-row button {
  flex-shrink: 0;
}

/* ---------- 軸 ---------- */
.axis-current {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 20px;
  margin: 6px 0 14px;
}
.axis-current-body {
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.9;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}
.axis-current-meta {
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0 0;
}
.axis-status {
  font-size: 13px;
  color: var(--muted);
  min-height: 1.4em;
  margin-top: 8px;
}
.axis-draft-label {
  font-size: 12px;
  color: var(--accent-gold);
  margin: 18px 0 6px;
  line-height: 1.7;
}
.axis-versions {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.axis-version-btn {
  width: 100%;
  text-align: left;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.axis-version-date {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
}
.axis-version-preview {
  font-family: var(--font-serif);
  font-size: 14px;
  line-height: 1.85;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

/* ---------- モーダル（詳細・設定） ---------- */
.modal-wrap {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 20px;
}
.modal {
  background: var(--bg);
  width: 100%;
  max-width: 520px;
  max-height: 80vh;
  overflow-y: auto;
  border-radius: 20px;
  padding: 22px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.modal-head h2 {
  font-size: 16px;
  margin: 0;
}
.detail-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 10px;
}

/* ---------- トースト ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%) translateY(10px);
  opacity: 0;
  pointer-events: none;
  background: var(--fg);
  color: var(--bg);
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 999px;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 40;
  max-width: 84vw;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- 控えめな動き・reduced-motion対応（全消去でなくフェードへ縮退） ---------- */
@media (prefers-reduced-motion: reduce) {
  .compass-dot {
    animation: none !important;
    opacity: 0.8;
    box-shadow: 0 0 6px 2px rgba(224, 184, 114, 0.5);
  }
  .today-card,
  .quote-card {
    transition: opacity 0.3s ease !important;
  }
  .today-card:hover,
  .quote-card:hover,
  .quote-card:active {
    transform: none !important;
  }
  .fade-in {
    animation: fadeInReduced 0.3s ease !important;
  }
}
@keyframes fadeInReduced {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
