/* ゴルフAIコーチ — 配色の既定値。
   **正本は config/coach.js の COACH_PUBLIC.brand**。app.js が起動時に
   同じ変数名で :root を上書きするので、コーチを差し替えるときにこのファイルは触らない。
   ここに残してあるのは、/api/coach が届く前と JS 無効時に見せるフォールバック。 */

:root {
  --navy: #1a2742;
  --gold: #c9a961;
  --gold-accent: #d4ad53;
  --cream: #faf5ec;
  --ink-on-gold: #2d1e14;
  --ink-brown: #3d2817;
  --line: rgba(61, 40, 23, 0.12);
  --danger: #b3261e;
  --danger-bg: #fdecea;

  --font-mincho: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "MS PMincho", serif;
  --font-gothic: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo",
    system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--cream);
  color: var(--ink-brown);
  font-family: var(--font-gothic);
  font-size: 16px;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}

[hidden] {
  display: none !important;
}

/* ---------- パスコードゲート ---------- */

.gate {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--navy);
}

.gate-card {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}

.gate-title {
  font-family: var(--font-mincho);
  font-size: 22px;
  letter-spacing: 0.06em;
  margin: 0;
  color: var(--navy);
}

.gate-note {
  margin: 6px 0 22px;
  font-size: 12px;
  color: rgba(61, 40, 23, 0.6);
}

.gate-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 6px;
}

.gate-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  font-family: inherit;
  color: var(--ink-brown);
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.gate-input:focus {
  outline: 2px solid var(--gold-accent);
  outline-offset: 1px;
}

.gate-error {
  margin: 12px 0 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
}

/* 「リンクを送りました」の案内。**成功／未登録を出し分けない**ので、
   常にこの1種類だけを出す（画面がメールアドレスの存在確認になるのを防ぐ）。 */
.gate-sent {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(201, 169, 97, 0.14);
  color: var(--ink-brown);
  font-size: 13px;
  line-height: 1.6;
}

.gate-button {
  width: 100%;
  margin-top: 18px;
  padding: 13px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-on-gold);
  background: var(--gold);
  border: none;
  border-radius: 12px;
  cursor: pointer;
}

.gate-button:active {
  background: var(--gold-accent);
}

.gate-button:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---------- チャット3層 ---------- */

.app {
  position: relative; /* トリミング画面（.trim）の absolute 基準 */
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.header {
  flex-shrink: 0;
  background: var(--navy);
  padding: 10px 16px calc(10px + env(safe-area-inset-top, 0px));
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  padding-bottom: 10px;
  text-align: center;
}

.header-title {
  margin: 0;
  font-family: var(--font-mincho);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--gold);
}

.header-sub {
  margin: 2px 0 0;
  font-size: 11px;
  line-height: 1.4;
  color: rgba(250, 245, 236, 0.7);
}

/* ---------- リッチメニュー ---------- */
/* 中身は app.js が features フラグを見て描画する。ボタンが0個なら枠ごと隠す。 */

.richmenu {
  flex-shrink: 0;
  background: var(--navy);
  border-top: 1px solid rgba(250, 245, 236, 0.12);
  padding: 0 10px 8px;
}

.richmenu-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 0 6px;
}

.menu-button {
  flex: 1 1 30%;
  min-height: 40px;
  padding: 8px 6px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--cream);
  background: rgba(250, 245, 236, 0.1);
  border: 1px solid rgba(201, 169, 97, 0.5);
  border-radius: 10px;
  cursor: pointer;
}

.menu-button:active {
  background: rgba(201, 169, 97, 0.28);
}

.richmenu-toggle {
  display: block;
  margin: 0 auto;
  padding: 2px 10px;
  font-family: inherit;
  font-size: 11px;
  color: rgba(250, 245, 236, 0.7);
  background: none;
  border: none;
  cursor: pointer;
}

/* ---------- 初回同意（免責） ---------- */

.consent-panel {
  position: absolute;
  inset: 0;
  z-index: 30; /* history-panel(20) / trim より上。同意前は他の操作より優先する */
  background: rgba(26, 39, 66, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.consent-card {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 18px;
  padding: 24px 20px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}

.consent-title {
  margin: 0 0 10px;
  font-family: var(--font-mincho);
  font-size: 17px;
  font-weight: 600;
  color: var(--navy);
}

.consent-body {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink-brown);
}

.consent-link {
  margin: 0 0 16px;
  font-size: 13px;
}

.consent-link a {
  color: var(--navy);
}

.consent-error {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
}

.consent-agree {
  width: 100%;
  padding: 13px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-on-gold);
  background: var(--gold);
  border: none;
  border-radius: 12px;
  cursor: pointer;
}

.consent-agree:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---------- 過去のやり取り ---------- */

.history-panel {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(26, 39, 66, 0.55);
  display: flex;
  align-items: flex-end;
}

.history-card {
  width: 100%;
  max-height: 82%;
  display: flex;
  flex-direction: column;
  background: var(--cream);
  border-radius: 16px 16px 0 0;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom, 0px));
}

.history-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.history-title {
  margin: 0;
  font-family: var(--font-mincho);
  font-size: 15px;
  font-weight: 600;
  color: var(--navy);
}

.history-close {
  width: 32px;
  height: 32px;
  font-size: 20px;
  line-height: 1;
  color: var(--ink-brown);
  background: none;
  border: none;
  cursor: pointer;
}

.history-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-top: 10px;
}

.history-row {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.history-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: rgba(61, 40, 23, 0.55);
}

.history-badge {
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(201, 169, 97, 0.24);
  color: var(--ink-on-gold);
  font-weight: 700;
}

.history-body {
  margin-top: 2px;
  font-size: 14px;
}

.history-body p {
  margin: 0;
}

.history-body .disclaimer-note {
  margin-top: 0.5em;
}

.history-row.assistant .history-body {
  color: var(--ink-brown);
}

.history-row.user .history-body {
  color: var(--navy);
  font-weight: 600;
}

.history-empty {
  margin: 24px 0;
  text-align: center;
  font-size: 13px;
  color: rgba(61, 40, 23, 0.6);
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty {
  margin: 24px auto 0;
  max-width: 420px;
  text-align: center;
}

.empty-lead {
  margin: 0 0 18px;
  font-size: 14px;
  color: rgba(61, 40, 23, 0.7);
}

.chips {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.chip {
  max-width: 100%;
  padding: 9px 16px;
  font-family: inherit;
  font-size: 13px;
  color: var(--ink-brown);
  background: #fff;
  border: 1px solid var(--gold);
  border-radius: 999px;
  cursor: pointer;
}

.chip:active {
  background: rgba(201, 169, 97, 0.18);
}

/* ---------- 吹き出し ---------- */

.row {
  display: flex;
}

.row.user {
  justify-content: flex-end;
}

.row.assistant {
  justify-content: flex-start;
}

.bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.75;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.row.user .bubble {
  background: var(--gold);
  color: var(--ink-on-gold);
  border-bottom-right-radius: 4px;
}

.row.assistant .bubble {
  background: #fff;
  color: var(--ink-brown);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(61, 40, 23, 0.08);
}

.bubble.thinking {
  color: rgba(61, 40, 23, 0.55);
}

/* 限定Markdownの出力要素 */
.bubble p {
  margin: 0;
}

.bubble p + p {
  margin-top: 0.35em;
}

.bubble ul {
  margin: 0.4em 0;
  padding-left: 1.2em;
}

.bubble li {
  margin: 0.15em 0;
}

.bubble strong {
  font-weight: 700;
}

.md-gap {
  height: 0.5em;
}

/* AI回答の吹き出し・履歴に常設する免責注記。COACH_PUBLIC.disclaimer.bubbleNote。 */
.disclaimer-note {
  margin: 0.5em 0 0;
  padding-top: 0.4em;
  border-top: 1px solid var(--line);
  font-size: 11px;
  line-height: 1.4;
  color: rgba(61, 40, 23, 0.55);
}

.error {
  align-self: center;
  max-width: 90%;
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
  text-align: center;
}

/* ---------- 入力バー ---------- */

.composer {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: #fff;
  border-top: 1px solid var(--line);
}

.input {
  flex: 1;
  min-height: 44px;
  max-height: 128px;
  padding: 11px 14px;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink-brown);
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 14px;
  resize: none;
}

.input:focus {
  outline: 2px solid var(--gold-accent);
  outline-offset: 1px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.video-button {
  flex-shrink: 0;
  height: 44px;
  width: 44px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  background: var(--cream);
  border: 1px solid var(--gold);
  border-radius: 14px;
  cursor: pointer;
}

.video-button:active {
  background: rgba(201, 169, 97, 0.25);
}

.video-button:disabled {
  opacity: 0.4;
  cursor: default;
}

.send {
  flex-shrink: 0;
  height: 44px;
  padding: 0 18px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-on-gold);
  background: var(--gold);
  border: none;
  border-radius: 14px;
  cursor: pointer;
}

.send:active {
  background: var(--gold-accent);
}

.send:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ---------- v4 動画トリミング ---------- */

.trim {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(26, 39, 66, 0.55);
}

.trim-panel {
  width: 100%;
  max-width: 480px;
  max-height: 100%;
  overflow-y: auto;
  background: var(--cream);
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.25);
}

.trim-title {
  margin: 0 0 10px;
  font-family: var(--font-mincho);
  font-size: 16px;
  letter-spacing: 0.04em;
  color: var(--navy);
  text-align: center;
}

.trim-video {
  display: block;
  width: 100%;
  max-height: 42dvh;
  background: #000;
  border-radius: 12px;
  object-fit: contain;
}

.trim-length {
  margin: 12px 0 4px;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  color: var(--ink-brown);
}

.trim-length.over {
  color: var(--danger);
}

/* 2ハンドルスライダー: range を2本重ねる。つまみだけタッチを受ける */
.range-wrap {
  position: relative;
  height: 40px;
  margin: 0 6px;
}

.range-track,
.range-fill {
  position: absolute;
  top: 18px;
  height: 4px;
  border-radius: 2px;
}

.range-track {
  left: 0;
  right: 0;
  background: rgba(61, 40, 23, 0.18);
}

.range-fill {
  background: var(--gold);
}

.range-wrap .range {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 40px;
  margin: 0;
  background: none;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}

.range-wrap .range:focus {
  outline: none;
}

.range-wrap .range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  pointer-events: auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--gold);
  border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.range-wrap .range::-moz-range-thumb {
  pointer-events: auto;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--gold);
  border: 3px solid #fff;
  cursor: pointer;
}

.trim-hint {
  margin: 2px 0 14px;
  font-size: 12px;
  text-align: center;
  color: rgba(61, 40, 23, 0.6);
}

.trim-actions {
  display: flex;
  gap: 10px;
}

.trim-cancel,
.trim-submit {
  flex: 1;
  padding: 13px 8px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  border-radius: 12px;
  cursor: pointer;
}

.trim-cancel {
  flex: 0 0 32%;
  color: var(--ink-brown);
  background: #fff;
  border: 1px solid var(--line);
}

.trim-submit {
  color: var(--ink-on-gold);
  background: var(--gold);
  border: none;
}

.trim-submit:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ---------- 利用規約ページ ---------- */

.terms-page {
  min-height: 100dvh;
}

.terms {
  max-width: 560px;
  margin: 0 auto;
  padding: 32px 20px calc(48px + env(safe-area-inset-bottom, 0px));
}

.terms-title {
  font-family: var(--font-mincho);
  font-size: 22px;
  margin: 0 0 24px;
  color: var(--navy);
}

.terms-section {
  margin-bottom: 22px;
}

.terms-section h2 {
  font-size: 15px;
  margin: 0 0 8px;
  color: var(--navy);
}

.terms-section p {
  margin: 0;
  font-size: 14px;
  line-height: 1.8;
}

.terms-back {
  margin-top: 32px;
  font-size: 14px;
}

.terms-back a {
  color: var(--navy);
}

/* ---------- 自分のカルテ（karte.html） ---------- */
/* 見た目は .history-* 系を踏襲する。独立ページなので枠だけここで持つ。 */

.karte-page {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom, 0px));
}

.karte-header {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.karte-back {
  display: inline-block;
  font-size: 13px;
  color: var(--navy);
}

.karte-page-title {
  margin: 8px 0 0;
  font-family: var(--font-mincho);
  font-size: 18px;
  font-weight: 600;
  color: var(--navy);
}

.karte-page-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: rgba(61, 40, 23, 0.6);
}

.karte-list {
  padding-top: 10px;
}

.karte-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.karte-row.profile {
  background: rgba(201, 169, 97, 0.1);
  border-radius: 10px;
  padding: 12px;
}

.karte-date {
  margin: 0 0 6px;
  font-family: var(--font-mincho);
  font-size: 14px;
  font-weight: 600;
  color: var(--navy);
}

.karte-field,
.karte-raw {
  margin: 0 0 4px;
  font-size: 14px;
}

.karte-label {
  display: inline-block;
  min-width: 3.5em;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(201, 169, 97, 0.24);
  color: var(--ink-on-gold);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.karte-links {
  margin: 6px 0 0;
}

.karte-link {
  display: inline-block;
  margin-right: 10px;
  font-size: 13px;
  color: var(--navy);
}

.karte-empty {
  margin: 32px 0;
  text-align: center;
  font-size: 13px;
  color: rgba(61, 40, 23, 0.6);
}

/* ---------- Pシステム教科書（p-system.html） ---------- */

.textbook-page {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom, 0px));
}

.textbook-header {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.textbook-back {
  display: inline-block;
  font-size: 13px;
  color: var(--navy);
}

.textbook-page-title {
  margin: 8px 0 0;
  font-family: var(--font-mincho);
  font-size: 18px;
  font-weight: 600;
  color: var(--navy);
}

.textbook-intro {
  margin: 16px 0;
  font-size: 14px;
  line-height: 1.8;
}

.textbook-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 20px;
  padding: 10px;
  background: rgba(201, 169, 97, 0.1);
  border-radius: 12px;
}

.textbook-toc a {
  min-width: 40px;
  padding: 4px 10px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-on-gold);
  background: rgba(201, 169, 97, 0.24);
  border-radius: 999px;
}

.textbook-section {
  padding: 20px 0;
  border-top: 1px solid var(--line);
  scroll-margin-top: 12px;
}

.textbook-section-title {
  margin: 0 0 10px;
  font-family: var(--font-mincho);
  font-size: 16px;
  font-weight: 600;
  color: var(--navy);
}

.textbook-img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
}

.textbook-caption {
  margin: 8px 0 0;
  font-size: 13px;
  color: rgba(61, 40, 23, 0.7);
}

.textbook-note {
  margin: 24px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.7;
  color: rgba(61, 40, 23, 0.7);
}
