/*
 * sketchy.css — Claude Design v3 由来の手書き風テーマ。
 *
 * 大枠のみ提供 (テーマ変数 / body / navbar / box / btn / toast / 文字サイズ)。
 * 個別画面 (ダッシュボードチャート等) のクラスは、機能実装時にこのファイルへ追記する。
 *
 * フォント (Patrick Hand / Caveat / Kalam) は public/fonts/ に woff2 同梱、
 * 下記 @font-face で local 配信 (= Issue #145 Capacitor 初回起動時 FOUT 対策、
 * かつ Web 版でもネットワーク待ち削減)。
 * → CSP を有効化する場合は font-src 'self' のみで足り、fonts.gstatic.com の許可は不要。
 */

/* ローカル同梱フォント (= Google Fonts latin subset 相当)。日本語は system-ui fallback。
   Caveat は variable font (= 単一 woff2 で 500/700 両対応)、Kalam は static (= weight 別)、
   Patrick Hand は 400 のみ。unicode-range は Google Fonts 配信の latin subset と同一範囲。 */
@font-face {
  font-family: 'Caveat';
  font-style: normal;
  font-weight: 500 700;
  font-display: swap;
  src: url("/fonts/caveat-latin.woff2") format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Kalam';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/kalam-400-latin.woff2") format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Kalam';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/fonts/kalam-700-latin.woff2") format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Patrick Hand';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/patrick-hand-latin.woff2") format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --ink: #1a1a1a;
  --ink-2: #3a3a3a;
  --paper: #fbf8f1;
  --paper-2: #f3eee0;
  --muted: #6e6b60;
  --accent: #ff7a45;
  --accent-2: #ffd23f;
  --accent-3: #4ea8de;
  --accent-4: #7ac74f;
  /* danger (危険ゾーン / 破壊的操作) */
  --danger: #cc0000;
  --danger-bg: #ffe5e5;
  --danger-soft-border: rgba(204,0,0,0.35); /* sketch-box-danger-soft 用、削除より弱い警告強度 */
  /* navbar 高さ参照変数。navbar 自体の高さは padding/content で決まり、この変数に引きずられない。
     参照側 (flash toast の top-offset 等) が --navbar-height を使うことで、
     navbar 高さを変更した際に参照箇所を一括更新できる (= Issue #174 B)。
     基準値 64px = padding 8px×2 + ボタン約 46px + border-bottom 2px (= Issue #49 slim 化後の実測値)。
     iPhone PWA 端末では env(safe-area-inset-top) が 8px を超える分だけ追加で拡大 (= Issue #190)。 */
  --navbar-height: calc(64px + max(0px, env(safe-area-inset-top, 0px) - 8px));
}

/* body 全体を紙質背景に。layout から bg-base-200 は外す前提。
   min-height 100vh は viewport 短コンテンツ時に下端余白が崩れる事象 (= Web 版で稀に「下が切れる」) への予防策。 */
html, body { min-height: 100vh; }
body {
  background: var(--paper);
  background-image:
    radial-gradient(circle at 20% 10%, rgba(0,0,0,0.025) 0 1px, transparent 1px),
    radial-gradient(circle at 80% 60%, rgba(0,0,0,0.02) 0 1px, transparent 1px);
  background-size: 8px 8px, 12px 12px;
  color: var(--ink);
  font-family: 'Patrick Hand', 'Kalam', system-ui, sans-serif;
}

/* ---------- navbar ---------- */
/* Issue #49: padding 14px → 8px に縮小して navbar 高さを 74px → 約 64px に slim 化。
   ボタン自体の高さ 46px は維持するため WCAG 2.5.5 (= 44px タップ領域) は引き続き満たす。
   Issue #47 (= sketch-btn 全体 44px 化) のゴールと両立する設計、design-reviewer 事前相談で確定。

   sticky 化 (= position: sticky; top: 0): スクロール時も navbar が常時画面上部に残る。
   z-index: 30 < flash toast z-50 のため、トーストは navbar より前面に出る (= 階層整合済)。
   background: var(--paper) は半透明背景 (= scroll で下のコンテンツが透けるのを防ぐ) と
   sticky 重なり時の視認性確保のためそのまま維持。 */
.sketch-navbar {
  display: flex; align-items: center; justify-content: space-between;
  /* iPhone PWA / Dynamic Island 端末で padding-top を env(safe-area-inset-top) に拡大、ノッチ侵入回避 (= Issue #190)。
     Android Chrome / Desktop は env = 0px のため max(8px, 0px) = 8px で従来挙動維持。
     env(..., 0px) 第 2 引数は古い Chrome (< 69) / IE 等の未サポート環境向け fallback。
     padding-bottom 8px は固定 (= 画面下端の safe-area-inset-bottom は navbar の下端には発生しない)。
     --navbar-height も連動して env 値ぶん拡大するため、flash toast の top-offset も追従する。 */
  padding: max(8px, env(safe-area-inset-top, 0px)) 20px 8px; gap: 12px;
  border-bottom: 2px solid var(--ink);
  background: var(--paper);
  position: sticky; top: 0; z-index: 30;
  /* transition は本体側に置く: .is-scrolled 側にだけ書くと付く方向のみ効いて
     外す方向 (scroll up) で shadow が即時消滅して「バグっぽい」印象になるため (3 者レビュー指摘)。 */
  transition: box-shadow .15s ease;
}
.sketch-navbar-title {
  font-family: 'Caveat', cursive; font-weight: 700; font-size: 32px;
  line-height: 1; color: var(--ink); text-decoration: none;
}
/* "daily." の下に黄色マーカーを引く swoosh 装飾。
   SVG 背景画像で上下端にゆらぎを入れた蛍光ペン跡を描く (linear-gradient は直線で機械的に見えるため不採用)。
   preserveAspectRatio=none で文字幅に応じて横に伸縮、background-size で文字の下半分にだけ帯を表示。 */
.sketch-swoosh {
  display: inline-block;
  padding: 0 6px;
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 100% 42%;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 30' preserveAspectRatio='none'><path d='M0,8 C18,0 38,12 56,3 C74,0 88,11 100,4 L100,25 C82,29 62,22 44,26 C26,30 12,23 0,27 Z' fill='%23ffd23f' fill-opacity='0.95'/></svg>");
}
/* scroll 中は浮遊感として shadow を付与。
   navbar_scroll_controller.js が window.scrollY > 4px のとき .is-scrolled を element に付与する。
   transition は .sketch-navbar 本体に書いてあるため両方向 (付く / 外す) で .15s ease が効く。
   JS は class の付け外しのみ担当 (= 責務分離)。 */
.sketch-navbar.is-scrolled {
  box-shadow: 0 2px 6px rgba(0,0,0,.12);
}
.sketch-navbar-right { display: flex; align-items: center; gap: 12px; }
.sketch-navbar-name {
  font-family: 'Kalam', cursive; font-size: 14px; color: var(--ink-2);
  max-width: 8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- button ---------- */
/* button_to が <form> でラップするため :active のずれを安定させる工夫が必要 */
/* padding は WCAG 2.5.5 / Apple HIG が定める最小タップ領域 44×44px を満たすために拡大している。
   border-box 環境 (Tailwind 4 preflight 適用) で font-size 18px × line-height 1.4 + 上下 padding 20px ≒ 45px。
   縮める誘惑が出たときは iPhone 実機で誤タップが増えることを思い出すこと。
   line-height を 1.4 未満に変えた場合は `min-height: 44px;` を追加して保険をかけること。 */
.sketch-btn {
  display: inline-block; border: 2px solid var(--ink); background: var(--paper);
  font-family: 'Caveat', cursive; font-size: 18px; padding: 10px 16px; border-radius: 6px;
  color: var(--ink); text-decoration: none; cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
  transition: transform .08s ease, box-shadow .08s ease;
  /* ボタン内テキストの自動折り返し禁止 (= モバイル幅で「ログ / アウト」2 行折り返しを解消)。
     flex-shrink: 0 は flex container 内 (= navbar など) でボタンが圧縮されて
     padding すら奪われ「設 / 定」と縦書き状になる事象を抑える (画像 10 由来)。 */
  white-space: nowrap;
  flex-shrink: 0;
}
.sketch-btn:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--ink); }
.sketch-btn:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
.sketch-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}
/* primary は #ff7a45 + 黒文字 (6.73:1) で WCAG AA 合格。白文字 (2.59:1) は不可。 */
.sketch-btn-primary { background: var(--accent); color: var(--ink); }
.sketch-btn-primary:hover { background: var(--accent); color: var(--ink); }

/* ---------- box / card ---------- */
.sketch-box {
  border: 2px solid var(--ink); border-radius: 6px; background: var(--paper); padding: 16px;
  box-shadow: 4px 4px 0 var(--ink);
}
.sketch-box.dashed { border-style: dashed; }
.sketch-box.filled { background: var(--paper-2); }
/* accent: オレンジ + 黒文字 (6.73:1) で WCAG AA 合格。白文字 (2.59:1) は不可。 */
.sketch-box.accent { background: var(--accent); color: var(--ink); }
.sketch-box.accent .sketch-label,
.sketch-box.accent .sketch-small { color: var(--ink-2); }
/* danger: 破壊的操作 (退会 / トークン再生成) の警告エリア。
   sketch-box-danger      → 背景 + ボーダー両方を不透明 danger 色に (= 削除ボックス、最強の警告)。
   sketch-box-danger-soft → 背景 + ボーダーを半透明赤 (35%) に (= トークン再生成ボックス、弱い警告)。
                             背景・タイトル・ボーダーで赤系 3 色を一致させ、強度差は不透明度で表現。
   --danger (#cc0000) は黒文字 (5.91:1) で WCAG AA 合格。 */
.sketch-box-danger      { background: var(--danger-bg); border-color: var(--danger); }
.sketch-box-danger-soft { background: var(--danger-bg); border-color: var(--danger-soft-border); }
/* danger テキスト (見出し・ラベル) */
.sketch-h-danger { color: var(--danger); }
/* danger ボタン: .sketch-btn と組み合わせて使う。ボーダー + 文字を danger 色に。 */
.sketch-btn-danger { border-color: var(--danger); color: var(--danger); }

/* ---------- webhook delivery history (Settings 画面) ---------- */
/* 受信履歴の各行を縦並びリストで表示。time / status / count / error_message を flex で配置。
   配色は status 別 (success=緑系 / invalid=オレンジ系 / unauthorized=赤系) で WCAG AA 黒文字コントラスト。 */
.sketch-webhook-history { list-style: none; padding: 0; margin: 0; }
.sketch-webhook-history-item {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 8px 0; border-bottom: 1px dashed var(--muted);
  font-family: 'Kalam', cursive; font-size: 14px; color: var(--ink-2);
}
.sketch-webhook-history-item:last-child { border-bottom: none; }
.sketch-webhook-history-time { color: var(--ink-2); }
.sketch-webhook-history-count { color: var(--muted); }
.sketch-webhook-history-error {
  flex-basis: 100%; margin: 4px 0 0; padding: 4px 8px;
  background: var(--paper-2); border-radius: 4px;
  color: var(--ink-2); font-size: 13px; line-height: 1.4;
}

/* 注記ブロック (= 補足情報の視覚明示)。border-left で「ここは追加情報」 を一目で示す。
   Issue #218 で確立 (= sketch-box 内の paper-2 背景だけだと外側 paper との contrast が 1.08:1 で区別不能、
   border-left + paper-2 + line-height で「補足」 「警告」 のフラグ機能が働く)。 */
.sketch-note {
  border-left: 3px solid var(--ink-2);
  background: var(--paper-2);
  padding: 8px 12px;
  border-radius: 4px;
  line-height: 1.5;
}

/* status バッジ。border-radius + padding + 黒文字 (6.73:1 / 7:1+) で AA 確実。 */
.sketch-status {
  display: inline-block; padding: 2px 8px; border: 1px solid var(--ink); border-radius: 4px;
  font-family: 'Kalam', cursive; font-size: 13px; line-height: 1.2; color: var(--ink);
}
.sketch-status-success      { background: var(--accent-4); }   /* 緑 (#7ac74f) + 黒文字 = AA */
.sketch-status-invalid      { background: var(--accent); }     /* オレンジ (#ff7a45) + 黒文字 6.73:1 = AA */
.sketch-status-unauthorized { background: #ffd9d9; }            /* 赤系。MVP では非表示だが将来 #55 で使う */

/* ---------- typography ---------- */
.sketch-h  { font-family: 'Caveat', cursive; font-weight: 700; font-size: 24px; margin: 0 0 6px; line-height: 1.1; }
.sketch-hh { font-family: 'Caveat', cursive; font-size: 30px; margin: 0; line-height: 1.1; }
/* font-size 14px 統一 (モバイル + プロジェクタ可読性、design-reviewer 指摘) */
.sketch-label { font-family: 'Kalam', cursive; font-size: 14px; color: var(--muted); }
.sketch-small { font-family: 'Kalam', cursive; font-size: 14px; color: var(--ink-2); }
/* 食品換算テキスト: モバイル 375px で長い文字列が折り返さないよう ellipsis を当てる専用クラス */
.sketch-food-equivalent { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sketch-body-text { font-family: 'Kalam', cursive; font-size: 15px; line-height: 1.55; color: var(--ink-2); }

/* highlight (黄/緑のマーカー風) */
.sketch-hl-yellow { background: var(--accent-2); padding: 0 4px; }
.sketch-hl-green  { background: var(--accent-4); padding: 0 4px; }

/* ---------- flash toast ---------- */
/* daisyUI alert を sketchy トーストに差し替え。
   PR #25 で詰めた flash_controller.js の fade-out 挙動 (opacity transition) はそのまま動かすため、
   transition: opacity を残し、初期 opacity-0 / 表示時 opacity-1 のクラスは layout 側で付ける。 */
.sketch-toast {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  border: 2px solid var(--ink); border-radius: 6px; padding: 12px 14px;
  box-shadow: 4px 4px 0 var(--ink);
  font-family: 'Kalam', cursive; font-size: 14px; line-height: 1.45; color: var(--ink);
  transition: opacity .3s;
}
.sketch-toast.notice { background: #e7f5d9; }
.sketch-toast.alert  { background: #ffd9d9; }
.sketch-toast-message { flex: 1; }
.sketch-toast-close {
  background: transparent; border: none; cursor: pointer; padding: 0;
  width: 32px; height: 32px; flex-shrink: 0;
  font-family: 'Caveat', cursive; font-size: 24px; line-height: 1; color: var(--ink);
}
.sketch-toast-close:hover { color: var(--accent); }

/* ---------- page wrappers (汎用) ---------- */
.sketch-page-narrow { max-width: 26rem; margin: 0 auto; padding: 24px 4px; }

/* ==========================================================================
   Dashboard — ホーム画面専用クラス
   Wireframe v3 由来の sketchy スタイル。機能実装時に追記した区画。
   ========================================================================== */

/* ---- バナー (状態通知帯) ---- */
.sketch-banner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  border: 2px solid var(--ink); border-radius: 6px; padding: 12px 16px;
  box-shadow: 3px 3px 0 var(--ink);
  margin-bottom: 16px;
}
.sketch-banner-guest  { background: #fff7e0; }
.sketch-banner-android { background: #e8f4ff; }
.sketch-banner-empty  { background: #e7f5d9; }

.sketch-banner-body {
  display: flex; align-items: flex-start; gap: 10px; flex: 1; min-width: 0;
}
.sketch-banner-icon { font-size: 24px; flex-shrink: 0; line-height: 1; }
.sketch-banner-text {
  font-family: 'Kalam', cursive; font-size: 14px; line-height: 1.5;
  color: var(--ink-2); margin: 0;
}
.sketch-banner-action { flex-shrink: 0; }

/* ---- Dashboard ラッパー ----
   padding-bottom 48px は 下段カードの box-shadow (3px 3px 0) や frame アクセサリーが
   viewport 下端で見切れないようにするための余裕。32px だと scroll restoration や
   font load 時の layout shift で稀に「下が切れる」事象が発生していたため、48px に増量 (= 予防的)。 */
.sketch-dashboard { padding-bottom: 48px; }

/* ---- トップバー ---- */
.sketch-topbar {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin-bottom: 14px;
  border-bottom: 2px solid var(--ink); padding-bottom: 14px;
}

/* ---- 貯カロリー (Issue #41 = アプリ哲学のステップ① 核機能) ----
   メイン KPI として大きく表示。矢印・色分けは「数値プレッシャー回避」の原則で意図的に持たない。
   flex + flex-wrap で 6 桁以上 (= 100,000 kcal+) になっても数値と単位「kcal」が綺麗に折り返す。 */
.sketch-savings-main {
  display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px;
  font-family: 'Caveat', cursive; font-weight: 700;
  font-size: 48px; line-height: 1.1; color: var(--ink);
  margin-top: 4px;
}

/* ---- メイングリッド (チャート 1.5fr + サイドパネル 1fr) ---- */
.sketch-main-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

/* ---- サイドパネル (AI カード + ストリーク 縦並び) ---- */
.sketch-side { display: flex; flex-direction: column; gap: 14px; }

/* ---- SVG チャート ---- */
.sketch-chart-svg { width: 100%; height: 220px; margin-top: 6px; }

/* ---- ストリーク ---- */
.sketch-streak-row {
  display: flex; gap: 6px; margin-top: 8px;
}
.sketch-streak-cell { text-align: center; flex: 1; }
.sketch-streak-dot {
  height: 28px; border: 2px solid var(--ink); border-radius: 50%;
  margin-bottom: 2px;
}
.sketch-streak-dot.done   { background: var(--accent); }       /* 歩いた日 (オレンジ) */
.sketch-streak-dot.today  { background: var(--accent-2); }     /* 今日 (黄) */
.sketch-streak-dot.empty  { background: var(--paper); }        /* 記録なし */
.sketch-streak-dot.future { background: transparent; border-style: dashed; } /* 未来 */

/* ---- AI アバター ---- */
.sketch-ai-avatar {
  width: 36px; height: 36px; flex-shrink: 0;
  border: 2px solid var(--ink); border-radius: 50%;
  background: var(--accent-3); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Caveat', cursive; font-size: 20px; font-weight: 700;
}

/* ---- 凡例カラーチップ ---- */
.sketch-sw {
  display: inline-block;
  width: 14px; height: 14px;
  border: 1.5px solid var(--ink);
  vertical-align: -2px;
  margin-right: 4px;
}

/* ---- 下段 4 カードグリッド ----
   minmax(0, 1fr) は CSS Grid の min-width: auto デフォルト挙動 (= grid item 内容が長いと
   grid 全体が container を超えて bleed する) を抑える。30px Caveat の「+5.4」「7,200」等が
   モバイル幅 (= 2 列) で右切れしていた事象 (画像 1 由来) への対処。 */
.sketch-bottom-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

/* ---- レスポンシブ (760px 以下: グリッドを縦積みに) ---- */
@media (max-width: 760px) {
  .sketch-main-grid   { grid-template-columns: 1fr; }
  .sketch-bottom-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sketch-topbar      { flex-direction: column; align-items: flex-start; gap: 6px; }

  /* banner はモバイル幅で flex 横並び + flex-shrink: 0 のボタンが幅を奪い、テキスト領域が
     極小に潰れる (= 「これは / サンプ / ルデー / タで / す。」と 1-3 文字ずつ折り返し) ため、
     縦並びに切り替えて icon + text を 1 ブロック / CTA を次行に展開する (画像 3 由来)。 */
  .sketch-banner       { flex-direction: column; align-items: stretch; }
  .sketch-banner-action { display: flex; justify-content: flex-start; }

  /* navbar はモバイル幅で「タイトル + 名前 + 設定 + ログアウト」が総幅オーバーになり、
     設定/ログアウトのボタン内テキストが「設/定」「ロ/グ/ア/ウ/ト」と 1 文字ずつ縦書きみたいに
     圧縮される事象が発生 (画像 6 由来)。名前を非表示にしてスペース確保 + ボタンを padding/font-size
     縮小で軽量化することで横並び維持。
     PR #204 で padding 6px 10px / font-size 14px に縮小したが、それでも縦書き状の圧縮が解消されず
     (画像 8 由来) → space-between から flex-start に変更してボタン群を左寄せにし、
     ボタンに割り当て可能な横幅を確保。padding は 8px 14px に戻して読みやすさ優先。 */
  .sketch-navbar { justify-content: flex-start; }
  .sketch-navbar-name { display: none; }
  .sketch-navbar-right .sketch-btn { padding: 8px 14px; font-size: 14px; }
  /* モバイル幅では sketch-navbar-title (= 「weight daily.」 Caveat 32px) が 2 行折り返しになるため、
     ボタン群を少し下にずらして daily. の下半分付近に揃え、視覚バランスを取る (画像 11 ユーザー報告由来、微調整レベル)。 */
  .sketch-navbar-right { margin-top: 6px; }
}


/* Issue #314: 同期ボタン上の最終同期時刻表示 (= 「最終同期: N 時間前」)。
   data-warning="true" (= 24h 以上未同期) で ⚠️ アイコン + 赤色強調。
   data-warning="false" (= 24h 未満 / 未同期) は muted 色で目立たせない。
   JS 側 (native_health_controller#updateLastSyncDisplay) が dataset.warning を更新する SSOT。 */
.sketch-last-sync {
  color: var(--muted);
}
.sketch-last-sync[data-warning="true"] {
  color: var(--danger);
  font-weight: 700;
}
.sketch-last-sync[data-warning="true"]::before {
  content: "⚠️ ";
  margin-right: 4px;
}
