/* ==========================================================================
   カラダログ・パーソナル — デザイントークン + 共通コンポーネント
   正: design/visual.md。色・余白・角丸・フォントは必ず変数経由(ベタ書き禁止)
   ========================================================================== */

:root {
  color-scheme: light dark;

  /* ===== ニュートラル ===== */
  --c-bg:          #F7F6F2;
  --c-surface:     #FFFFFF;
  --c-surface-2:   #EFEDE8;
  --c-text-1:      #2B2A27;
  --c-text-2:      #6E6B64;
  --c-border:      #E5E2DB;

  /* ===== メイン / アクセント ===== */
  --c-main:        #2F6E64;
  --c-main-soft:   #E7F0ED;
  --c-accent:      #C97E45;
  --c-accent-soft: #F7ECE0;
  --c-accent-deep: #9C5A2A;

  /* ===== 体調スコア5段階(データ色) ===== */
  --c-score-1:     #C25450;
  --c-score-2:     #D6935B;
  --c-score-3:     #C4BCAC;
  --c-score-4:     #7FAE9E;
  --c-score-5:     #2F6E64;

  /* ===== ヒートマップ専用ランプ ===== */
  --c-heat-1:      #DCE9E4;
  --c-heat-2:      #B7D6CC;
  --c-heat-3:      #8CBFAF;
  --c-heat-4:      #579C8A;
  --c-heat-5:      #2F6E64;

  /* ===== 機能色 ===== */
  --c-warn:        #B4514D;
  --c-warn-soft:   #F6E9E8;
  --c-warn-deep:   #8F3A37;
  --c-good:        #3E7D63;
  --c-good-soft:   #E8F1EB;
  --c-good-deep:   #2E6350;

  /* ===== Chart.js 系列色 ===== */
  --c-chart-1:     #2F6E64;
  --c-chart-2:     #C97E45;
  --c-chart-3:     #5B7A99;
  --c-chart-4:     #8C8778;
  --c-chart-grid:  #ECEAE4;
  --c-chart-base:  #C4BCAC;

  /* ===== 影 ===== */
  --shadow-card:   0 1px 3px rgba(43,42,39,0.05);
  --shadow-float:  0 2px 6px rgba(43,42,39,0.06);

  /* ===== タイポグラフィ ===== */
  --font-body: -apple-system, BlinkMacSystemFont, "Hiragino Sans",
               "Hiragino Kaku Gothic ProN", sans-serif;
  --font-num:  ui-rounded, -apple-system, BlinkMacSystemFont, sans-serif;
  --fs-display: 34px;
  --fs-num-lg:  28px;
  --fs-h1:      22px;
  --fs-h2:      17px;
  --fs-body:    16px;
  --fs-caption: 13px;
  --fs-micro:   11px;

  /* ===== 余白 ===== */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;

  /* ===== 角丸 ===== */
  --r-s: 8px;
  --r-m: 12px;
  --r-l: 16px;
  --r-full: 999px;

  --nav-height: 49px;
}

/* ダークテーマ値(自動追従・手動の両方から参照) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --c-bg:          #1A1B19;
    --c-surface:     #242623;
    --c-surface-2:   #2C2E2A;
    --c-text-1:      #ECEAE4;
    --c-text-2:      #A3A099;
    --c-border:      #34362F;
    --c-main:        #6FB3A5;
    --c-main-soft:   #23332F;
    --c-accent:      #E0A468;
    --c-accent-soft: #332A20;
    --c-accent-deep: #E0A468;
    --c-score-1:     #D9736E;
    --c-score-2:     #E0A468;
    --c-score-3:     #8F8B80;
    --c-score-4:     #86BCA9;
    --c-score-5:     #58A08F;
    --c-heat-1:      #24332F;
    --c-heat-2:      #2B4A41;
    --c-heat-3:      #38695C;
    --c-heat-4:      #4C8E7D;
    --c-heat-5:      #6FB3A5;
    --c-warn:        #E08B85;
    --c-warn-soft:   #33231F;
    --c-warn-deep:   #E08B85;
    --c-good:        #7FBFA0;
    --c-good-soft:   #22302A;
    --c-good-deep:   #7FBFA0;
    --c-chart-1:     #6FB3A5;
    --c-chart-2:     #E0A468;
    --c-chart-3:     #8FA8C4;
    --c-chart-4:     #9B968A;
    --c-chart-grid:  #2E302B;
    --c-chart-base:  #8F8B80;
    --shadow-card:   none;
    --shadow-float:  none;
  }
}
:root[data-theme="dark"] {
  --c-bg:          #1A1B19;
  --c-surface:     #242623;
  --c-surface-2:   #2C2E2A;
  --c-text-1:      #ECEAE4;
  --c-text-2:      #A3A099;
  --c-border:      #34362F;
  --c-main:        #6FB3A5;
  --c-main-soft:   #23332F;
  --c-accent:      #E0A468;
  --c-accent-soft: #332A20;
  --c-accent-deep: #E0A468;
  --c-score-1:     #D9736E;
  --c-score-2:     #E0A468;
  --c-score-3:     #8F8B80;
  --c-score-4:     #86BCA9;
  --c-score-5:     #58A08F;
  --c-heat-1:      #24332F;
  --c-heat-2:      #2B4A41;
  --c-heat-3:      #38695C;
  --c-heat-4:      #4C8E7D;
  --c-heat-5:      #6FB3A5;
  --c-warn:        #E08B85;
  --c-warn-soft:   #33231F;
  --c-warn-deep:   #E08B85;
  --c-good:        #7FBFA0;
  --c-good-soft:   #22302A;
  --c-good-deep:   #7FBFA0;
  --c-chart-1:     #6FB3A5;
  --c-chart-2:     #E0A468;
  --c-chart-3:     #8FA8C4;
  --c-chart-4:     #9B968A;
  --c-chart-grid:  #2E302B;
  --c-chart-base:  #8F8B80;
  --shadow-card:   none;
  --shadow-float:  none;
}

/* ==========================================================================
   ベース
   ========================================================================== */

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  font-size: var(--fs-body);
  line-height: 1.7;
  color: var(--c-text-1);
  background: var(--c-bg);
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}

input, textarea, select {
  font-family: inherit;
  font-size: var(--fs-body);
  color: var(--c-text-1);
}

a { color: var(--c-main); }

button:focus-visible, a:focus-visible,
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--c-main);
  outline-offset: 2px;
}

svg { display: block; }

/* ==========================================================================
   レイアウト
   ========================================================================== */

#screen-root {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--sp-4) + env(safe-area-inset-top)) var(--sp-4)
           calc(var(--nav-height) + env(safe-area-inset-bottom) + var(--sp-7));
}

.screen-title {
  font-size: var(--fs-h1);
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: var(--sp-4);
}

.section { margin-bottom: var(--sp-6); }

.section-title {
  font-size: var(--fs-h2);
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.4;
  margin-bottom: var(--sp-3);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.text-2   { color: var(--c-text-2); }
.caption  { font-size: var(--fs-caption); line-height: 1.5; color: var(--c-text-2); }
.micro    { font-size: var(--fs-micro); line-height: 1.4; color: var(--c-text-2); }
.num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}
.num-lg {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-num-lg);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
}
.num-display {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-display);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

/* ==========================================================================
   カード
   ========================================================================== */

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-m);
  box-shadow: var(--shadow-card);
  padding: var(--sp-4);
}

.card-list { display: flex; flex-direction: column; gap: var(--sp-2); }

/* 発見カード */
.insight-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-m);
  box-shadow: var(--shadow-card);
  padding: var(--sp-3) var(--sp-4);
  overflow: hidden;
  width: 100%;
  text-align: left;
}
.insight-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
}
.insight-card.warn::before { background: var(--c-warn); }
.insight-card.good::before { background: var(--c-good); }
.insight-card .insight-icon {
  flex: 0 0 40px;
  width: 40px; height: 40px;
  border-radius: var(--r-full);
  display: flex; align-items: center; justify-content: center;
}
.insight-card.warn .insight-icon { background: var(--c-warn-soft); color: var(--c-warn-deep); }
.insight-card.good .insight-icon { background: var(--c-good-soft); color: var(--c-good-deep); }
.insight-card .insight-body { flex: 1; min-width: 0; }
.insight-card .insight-title {
  font-size: var(--fs-body);
  font-weight: 600;
  line-height: 1.4;
}
.insight-card.strong .insight-title { color: var(--c-warn-deep); }
.insight-card .insight-sub {
  font-size: var(--fs-caption);
  color: var(--c-text-2);
  line-height: 1.5;
}
.insight-card .insight-chevron { flex: 0 0 auto; color: var(--c-text-2); }
.insight-card.ghost {
  border-style: dashed;
  box-shadow: none;
  background: none;
}
.insight-card.ghost::before { display: none; }

/* ピル・チップ */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  border-radius: var(--r-full);
  padding: 0 var(--sp-3);
  height: 28px;
  font-size: var(--fs-caption);
}
.pill.outline { border: 1px solid var(--c-border); color: var(--c-text-2); }
.pill.good { background: var(--c-good-soft); color: var(--c-good-deep); }
.pill.warn { background: var(--c-warn-soft); color: var(--c-warn-deep); }
.pill.accent { background: var(--c-accent-soft); color: var(--c-accent-deep); }

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  min-height: 44px;
  padding: var(--sp-2) var(--sp-4);
  border: 1.5px solid var(--c-border);
  border-radius: var(--r-full);
  background: var(--c-surface);
  font-size: var(--fs-body);
  color: var(--c-text-1);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.chip:active { transform: scale(0.98); }
.chip.selected {
  background: var(--c-main-soft);
  border-color: var(--c-main);
  color: var(--c-main);
  font-weight: 600;
}
.chip-group { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

/* ==========================================================================
   ボタン
   ========================================================================== */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  width: 100%;
  min-height: 48px;
  border-radius: var(--r-s);
  font-size: var(--fs-body);
  font-weight: 600;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn-primary { background: var(--c-main); color: var(--c-surface); }
:root[data-theme="dark"] .btn-primary { color: var(--c-bg); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn-primary { color: var(--c-bg); }
}
.btn-soft { background: var(--c-main-soft); color: var(--c-main); }
.btn-ghost { border: 1.5px solid var(--c-border); color: var(--c-text-1); background: var(--c-surface); }
.btn-danger { background: var(--c-warn-soft); color: var(--c-warn-deep); }
.btn-inline { width: auto; padding: 0 var(--sp-4); }

/* セグメント切替(期間・テーマ等) */
.segment {
  display: flex;
  background: var(--c-surface-2);
  border-radius: var(--r-s);
  padding: 2px;
  gap: 2px;
}
.segment button {
  flex: 1;
  min-height: 40px;
  border-radius: calc(var(--r-s) - 2px);
  font-size: var(--fs-caption);
  color: var(--c-text-2);
}
.segment button.selected {
  background: var(--c-surface);
  color: var(--c-text-1);
  font-weight: 600;
  box-shadow: var(--shadow-card);
}

/* ==========================================================================
   フォーム
   ========================================================================== */

.field { margin-bottom: var(--sp-4); }
.field-label {
  display: block;
  font-size: var(--fs-caption);
  color: var(--c-text-2);
  margin-bottom: var(--sp-1);
}
.input, textarea.input {
  width: 100%;
  min-height: 44px;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-s);
  padding: var(--sp-2) var(--sp-3);
}
textarea.input { line-height: 1.8; resize: vertical; }
.input:focus { outline: 2px solid var(--c-main); outline-offset: 0; border-color: var(--c-main); }

/* ==========================================================================
   ボトムナビ
   ========================================================================== */

.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 100;
  display: flex;
  justify-content: center;
  background: color-mix(in srgb, var(--c-surface) 85%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--c-border);
  box-shadow: var(--shadow-float);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav .nav-inner {
  display: flex;
  width: 100%;
  max-width: 560px;
}
.nav-btn {
  position: relative;
  flex: 1;
  height: var(--nav-height);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--c-text-2);
  font-size: 10px;
  line-height: 1;
}
.nav-btn.active { color: var(--c-main); }
.nav-btn.active::before {
  content: "";
  position: absolute;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 24px; height: 2px;
  background: var(--c-main);
  border-radius: var(--r-full);
}
.nav-btn .nav-dot {
  position: absolute;
  top: 6px;
  right: calc(50% - 16px);
  width: 6px; height: 6px;
  border-radius: var(--r-full);
  background: var(--c-accent);
}

/* ==========================================================================
   モーダル / ボトムシート
   ========================================================================== */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--c-surface);
  border-radius: var(--r-l) var(--r-l) 0 0;
  box-shadow: var(--shadow-float);
  padding: var(--sp-4) var(--sp-4) calc(var(--sp-5) + env(safe-area-inset-bottom));
  animation: sheet-up 0.25s ease-out;
}
@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
.sheet-handle {
  width: 36px; height: 4px;
  border-radius: var(--r-full);
  background: var(--c-border);
  margin: 0 auto var(--sp-4);
}
.sheet-title {
  font-size: var(--fs-h2);
  font-weight: 600;
  margin-bottom: var(--sp-3);
}
.sheet-options { display: flex; flex-direction: column; gap: var(--sp-2); }
.sheet-option {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  min-height: 52px;
  padding: var(--sp-2) var(--sp-3);
  border: 1.5px solid var(--c-border);
  border-radius: var(--r-s);
  background: var(--c-surface);
  text-align: left;
  font-size: var(--fs-body);
}
.sheet-option.selected {
  border-color: var(--c-main);
  background: var(--c-main-soft);
  font-weight: 600;
}

/* ==========================================================================
   バナー・トースト
   ========================================================================== */

#banner-area {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 var(--sp-4);
}
.banner {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  background: var(--c-accent-soft);
  border: 1px solid var(--c-border);
  border-radius: var(--r-m);
  padding: var(--sp-3) var(--sp-4);
  margin-top: var(--sp-3);
  font-size: var(--fs-caption);
  color: var(--c-text-1);
}
.banner .banner-actions { margin-left: auto; display: flex; gap: var(--sp-2); flex-shrink: 0; }
.banner button { font-size: var(--fs-caption); font-weight: 600; color: var(--c-accent-deep); min-height: 44px; padding: 0 var(--sp-2); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + var(--sp-4));
  transform: translateX(-50%);
  z-index: 300;
  background: var(--c-text-1);
  color: var(--c-bg);
  font-size: var(--fs-caption);
  border-radius: var(--r-full);
  padding: var(--sp-2) var(--sp-4);
  box-shadow: var(--shadow-float);
  animation: toast-in 0.2s ease-out;
  max-width: calc(100vw - 32px);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ==========================================================================
   オンボーディング
   ========================================================================== */

.onboarding-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: var(--c-bg);
  overflow-y: auto;
  padding: calc(var(--sp-7) + env(safe-area-inset-top)) var(--sp-4)
           calc(var(--sp-7) + env(safe-area-inset-bottom));
}
.onboarding-inner { max-width: 480px; margin: 0 auto; }
.onboarding-inner h1 {
  font-size: var(--fs-h1);
  line-height: 1.3;
  margin-bottom: var(--sp-4);
}
.onboarding-step {
  display: flex;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.onboarding-step .step-num {
  flex: 0 0 32px;
  width: 32px; height: 32px;
  border-radius: var(--r-full);
  background: var(--c-main-soft);
  color: var(--c-main);
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-num);
}

/* ==========================================================================
   汎用パーツ
   ========================================================================== */

.divider { border: none; border-top: 1px solid var(--c-border); margin: var(--sp-4) 0; }

.empty-note {
  text-align: center;
  color: var(--c-text-2);
  font-size: var(--fs-caption);
  padding: var(--sp-5) var(--sp-4);
}

.app-footer {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 var(--sp-4) calc(var(--nav-height) + env(safe-area-inset-bottom) + var(--sp-5));
  font-size: var(--fs-micro);
  color: var(--c-text-2);
  line-height: 1.6;
}

.chart-box { position: relative; width: 100%; }
.chart-box canvas { max-width: 100%; }

.spark-box { height: 32px; position: relative; }

/* スクリーンリーダー専用 */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   モーション抑制
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
