/* =========================================================
   フレポケ
   色はすべて --c-* 変数。値は js/core/appearance.js が
   選択中のテーマ（またはキャラカラー）から設定する。
   ========================================================= */

:root {
  /* 初期値（JS 反映前の一瞬だけ使う：Midnight Purple） */
  --c-bg: #17121f;
  --c-surface: #231a30;
  --c-surface-alt: #2e2340;
  --c-text: #f1ecfa;
  --c-muted: #b9aecb;
  --c-accent: #b892ff;
  --c-on-accent: #1a1226;
  --c-line: #3d3052;

  --radius: 20px;
  --radius-sm: 14px;
  --tap: 48px;
  --gutter: 16px;
  --content: 560px;
  --tabbar-h: 64px;
  --shadow: 0 6px 20px rgb(0 0 0 / 0.08);
  --ease: cubic-bezier(.2, .7, .2, 1);

  color-scheme: light;
}
:root[data-scheme="dark"] { color-scheme: dark; --shadow: 0 6px 20px rgb(0 0 0 / 0.35); }

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

html {
  -webkit-text-size-adjust: 100%;
  background: var(--c-bg);
  overflow-x: hidden;
  /* キーボード操作でフォーカスした要素が、固定ヘッダー・下部ナビの裏に隠れないようにする */
  scroll-padding-top: calc(env(safe-area-inset-top) + 72px);
  scroll-padding-bottom: calc(env(safe-area-inset-bottom) + var(--tabbar-h) + 24px);
}
@supports (overflow: clip) { html { overflow-x: clip; } }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Maru Gothic ProN", "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.65;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
/* 色の切り替えアニメーションは起動後だけ（起動時のちらつき防止） */
:root[data-ready] body { transition: background-color .3s var(--ease), color .3s var(--ease); }

img, svg { display: block; max-width: 100%; }
button, input { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }

.icon { width: 24px; height: 24px; flex: none; }

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

:focus-visible {
  outline: 3px solid var(--c-accent);
  outline-offset: 3px;
  border-radius: 10px;
}
.view:focus { outline: none; }

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 100;
  padding: 10px 16px; border-radius: 999px;
  background: var(--c-accent); color: var(--c-on-accent); font-weight: 700;
}
.skip-link:focus { top: calc(env(safe-area-inset-top) + 8px); }

/* ---------- ヘッダー ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: calc(var(--content) + var(--gutter) * 2);
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + var(--gutter)) 8px calc(env(safe-area-inset-left) + var(--gutter));
  background: var(--c-bg);
  background: color-mix(in srgb, var(--c-bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
.logo {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: var(--tap); padding-right: 8px;
  text-decoration: none;
}
.logo__mark { width: 32px; height: 32px; border-radius: 9px; }
.logo__text { font-size: 21px; font-weight: 800; letter-spacing: .06em; white-space: nowrap; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: var(--tap); height: var(--tap);
  padding: 0; border: 1px solid var(--c-line); border-radius: 50%;
  background: var(--c-surface); color: var(--c-text);
  cursor: pointer;
}
.icon-btn:active { transform: scale(.95); }

/* ---------- レイアウト ---------- */
.view {
  display: flex; flex-direction: column; gap: 16px;
  max-width: calc(var(--content) + var(--gutter) * 2);
  margin: 0 auto;
  padding: 8px calc(env(safe-area-inset-right) + var(--gutter)) calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px) calc(env(safe-area-inset-left) + var(--gutter));
}
.view > * { min-width: 0; }

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.section-title { font-size: 17px; font-weight: 700; margin-bottom: 10px; }
.page-title { font-size: 22px; font-weight: 800; margin-bottom: 12px; }
.hint { font-size: 14px; color: var(--c-muted); }
.empty { color: var(--c-muted); font-size: 15px; padding: 8px 0 4px; }

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 18px;
  border: 1px solid var(--c-line); border-radius: 999px;
  background: var(--c-surface-alt); color: var(--c-text);
  font-weight: 700; font-size: 15px; text-decoration: none; white-space: nowrap;
  cursor: pointer;
  transition: transform .15s var(--ease), background-color .2s;
}
.btn:active { transform: scale(.97); }
.btn .icon { width: 20px; height: 20px; }
.btn--primary { background: var(--c-accent); border-color: var(--c-accent); color: var(--c-on-accent); }
.btn--soft { background: var(--c-surface); }
.btn--block { width: 100%; }

/* ---------- 挨拶エリア ---------- */
.hero {
  position: relative;
  overflow: hidden;
  padding: 18px 18px 14px;
  isolation: isolate;
}
.hero__motifs { position: absolute; inset: 0; z-index: -1; pointer-events: none; opacity: .5; }
.motif {
  position: absolute;
  transform: translate(-50%, -50%) rotate(var(--rot, 0deg));
  animation: motif-float 6s var(--ease) infinite alternate;
  animation-delay: calc(var(--i) * -0.9s);
}
@keyframes motif-float {
  to { transform: translate(-50%, calc(-50% - 6px)) rotate(calc(var(--rot, 0deg) + 8deg)); }
}

.hero__body { display: flex; align-items: center; gap: 14px; }
.hero__art { flex: none; }
.hero__talk { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.hero__tag { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.hero__no {
  font-size: 12px; font-weight: 700; letter-spacing: .08em;
  padding: 1px 8px; border-radius: 999px;
  background: var(--c-accent); color: var(--c-on-accent);
}
.hero__name { font-size: 20px; font-weight: 800; }
.hero__catch { font-size: 13px; color: var(--c-muted); font-weight: 600; }
.hero__switch { position: relative; margin-top: 12px; width: 100%; }

.bubble {
  position: relative;
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--c-surface-alt);
  border: 1px solid var(--c-line);
  font-size: 15px; font-weight: 600;
  overflow-wrap: anywhere;
}
.bubble::before {
  content: "";
  position: absolute; left: -7px; top: 18px;
  width: 12px; height: 12px;
  background: inherit;
  border-left: 1px solid var(--c-line); border-bottom: 1px solid var(--c-line);
  transform: rotate(45deg);
}

/* ---------- キャラのイラスト ---------- */
.chara-art {
  --art-size: 120px;
  position: relative;
  width: var(--art-size); height: var(--art-size);
  border-radius: 50%;
  display: grid; place-items: center;
}
.chara-art--lg { animation: chara-bob 3.6s var(--ease) infinite alternate; }
.chara-art--sm { --art-size: 64px; }
.chara-art img { width: 100%; height: 100%; object-fit: contain; }
@keyframes chara-bob { to { transform: translateY(-5px); } }

.chara-art.is-fallback {
  background: var(--art-bg);
  border: 2px dashed var(--art-accent);
  color: var(--art-ink);
}
.chara-art__fallback {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; line-height: 1.25; padding: 6px;
}
.chara-art__no { font-size: 11px; font-weight: 700; letter-spacing: .06em; }
.chara-art__name { font-size: 18px; font-weight: 800; }
.chara-art__note { font-size: 10px; margin-top: 4px; }
.chara-art--sm .chara-art__name { font-size: 12px; }
.chara-art--sm .chara-art__note { display: none; }
.chara-art--sm .chara-art__no { font-size: 9px; }

/* ---------- 検索 ---------- */
.search {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 6px 6px 44px;
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.search:focus-within { border-color: var(--c-accent); }
.search__icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--c-muted); }
.search__input {
  flex: 1; min-width: 0; min-height: 44px;
  border: 0; background: transparent;
  font-size: 16px; /* iOS でのズームを防ぐ */
  -webkit-appearance: none; appearance: none;
}
.search__input::placeholder { color: var(--c-muted); opacity: 1; }
.search__input:focus { outline: none; }
.search__btn { min-height: 44px; padding: 0 16px; }

/* ---------- ショートカット ---------- */
.shortcuts__list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tile {
  display: flex; flex-direction: column; gap: 2px;
  min-height: 108px; height: 100%; padding: 14px;
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  transition: transform .15s var(--ease);
}
.tile:active { transform: scale(.97); }
.tile__icon {
  display: grid; place-items: center;
  width: 42px; height: 42px; margin-bottom: 6px;
  border-radius: 13px;
  background: var(--c-accent); color: var(--c-on-accent);
}
.tile__title { font-weight: 800; font-size: 15px; }
.tile__desc { font-size: 12.5px; color: var(--c-muted); }

/* ---------- 最近の記録 ---------- */
.recent__list { display: flex; flex-direction: column; }
.recent__list li + li { border-top: 1px solid var(--c-line); }
.recent__item {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--tap); padding: 6px 0;
  text-decoration: none;
}
.recent__title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.recent__date { font-size: 13px; color: var(--c-muted); }
.chip {
  flex: none;
  font-size: 12px; font-weight: 700;
  padding: 2px 10px; border-radius: 999px;
  background: var(--c-surface-alt); border: 1px solid var(--c-line);
}

/* ---------- 準備中画面 ---------- */
.back-link {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: var(--tap); align-self: flex-start;
  color: var(--c-muted); font-weight: 700; text-decoration: none;
}
.placeholder__query { margin-bottom: 12px; color: var(--c-muted); }
.placeholder__talk { display: flex; align-items: center; gap: 14px; }
.placeholder__talk .bubble { flex: 1; min-width: 0; }

/* ---------- 下部ナビ ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  max-width: calc(var(--content) + var(--gutter) * 2);
  margin: 0 auto;
  padding: 4px calc(env(safe-area-inset-right) + 8px) calc(env(safe-area-inset-bottom) + 4px) calc(env(safe-area-inset-left) + 8px);
  background: var(--c-surface);
  background: color-mix(in srgb, var(--c-surface) 92%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--c-line);
}
.tabbar__item {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 56px;
  color: var(--c-muted);
  font-size: 11px; font-weight: 700; text-decoration: none;
  border-radius: 12px;
}
.tabbar__item[aria-current="page"] { color: var(--c-text); }
.tabbar__item[aria-current="page"] .icon { color: var(--c-accent); }

/* ---------- シート（ダイアログ） ---------- */
.sheet {
  width: 100%; max-width: 560px;
  max-height: min(88vh, 760px);
  max-height: min(88dvh, 760px);
  margin: auto auto 0;
  padding: 0;
  border: 1px solid var(--c-line);
  border-radius: 24px 24px 0 0;
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: 0 -10px 40px rgb(0 0 0 / .25);
  overflow: hidden;
}
.sheet[open] { display: flex; flex-direction: column; animation: sheet-in .28s var(--ease); }
.sheet::backdrop { background: rgb(0 0 0 / .45); }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }

.sheet__head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px 10px 20px;
  border-bottom: 1px solid var(--c-line);
}
.sheet__title { font-size: 18px; font-weight: 800; }
.sheet__body {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 14px 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.sheet__foot {
  padding: 12px 20px calc(env(safe-area-inset-bottom) + 12px);
  border-top: 1px solid var(--c-line);
}

/* 選択肢（ラジオ）共通 */
.option, .chara-option {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 10px 14px;
  border: 2px solid var(--c-line);
  border-radius: var(--radius-sm);
  background: var(--c-surface-alt);
  cursor: pointer;
}
.option:has(input:checked), .chara-option:has(input:checked) { border-color: var(--c-accent); }
.option:has(input:disabled) { cursor: not-allowed; opacity: .6; }
.option:has(input:focus-visible), .chara-option:has(input:focus-visible) {
  outline: 3px solid var(--c-accent); outline-offset: 2px;
}
.option__text, .chara-option__text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.option__label { font-weight: 700; font-size: 15px; overflow-wrap: anywhere; }
.option__sub { font-size: 12.5px; color: var(--c-muted); }
.option__mark, .chara-option__mark {
  flex: none; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--c-line);
  display: grid; place-items: center;
}
.option:has(input:checked) .option__mark,
.chara-option:has(input:checked) .chara-option__mark {
  border-color: var(--c-accent);
  background: radial-gradient(circle, var(--c-accent) 0 45%, transparent 50%);
}

.chara-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.chara-option__head { display: flex; align-items: baseline; gap: 8px; }
.chara-option__no { font-size: 12px; font-weight: 700; color: var(--c-muted); }
.chara-option__name { font-size: 17px; font-weight: 800; }
.chara-option__meta { font-size: 12.5px; color: var(--c-muted); }
.chara-option__catch { font-size: 13px; font-weight: 600; }

.set-block { display: flex; flex-direction: column; gap: 8px; }
.set-block + .set-block { padding-top: 12px; border-top: 1px solid var(--c-line); }
.set-title { font-size: 14px; font-weight: 800; color: var(--c-muted); letter-spacing: .04em; }
.set-chara { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.set-chara p { font-weight: 700; }

.option-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.theme-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.theme-grid .option { padding: 10px; gap: 10px; }
.theme-grid .option__label { font-size: 13.5px; line-height: 1.3; }

.swatch {
  position: relative; flex: none;
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--sw-bg);
  border: 1px solid rgb(127 127 127 / .35);
  overflow: hidden;
}
.swatch__a { position: absolute; left: 5px; top: 5px; width: 18px; height: 18px; border-radius: 6px; background: var(--sw-surface); }
.swatch__b { position: absolute; right: 5px; bottom: 5px; width: 14px; height: 14px; border-radius: 50%; background: var(--sw-accent); }

/* スイッチ */
.switch { display: flex; align-items: center; gap: 12px; min-height: var(--tap); cursor: pointer; }
.switch__text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.switch__input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch__track {
  flex: none; position: relative;
  width: 52px; height: 32px; border-radius: 999px;
  background: var(--c-surface-alt); border: 2px solid var(--c-line);
  transition: background-color .2s;
}
.switch__track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--c-muted);
  transition: transform .2s var(--ease), background-color .2s;
}
.switch__input:checked + .switch__track { background: var(--c-accent); border-color: var(--c-accent); }
.switch__input:checked + .switch__track::after { transform: translateX(20px); background: var(--c-on-accent); }
.switch__input:focus-visible + .switch__track { outline: 3px solid var(--c-accent); outline-offset: 3px; }

/* ---------- iPad・広い画面 ---------- */
@media (min-width: 700px) {
  :root { --gutter: 32px; --content: 720px; }
  .view { gap: 22px; padding-top: 16px; }
  .card { padding: 24px; }
  .hero { padding: 26px 26px 20px; }
  .chara-art--lg { --art-size: 168px; }
  .hero__name { font-size: 24px; }
  .bubble { font-size: 17px; padding: 14px 18px; }
  .hero__switch { width: auto; position: absolute; right: 20px; top: 18px; margin: 0; }
  .shortcuts__list { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
  .tile { min-height: 132px; padding: 18px; }
  .tabbar { bottom: calc(env(safe-area-inset-bottom) + 12px); border: 1px solid var(--c-line); border-radius: 22px; padding-bottom: 4px; box-shadow: var(--shadow); }
  .view { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 44px); }
  .tabbar__item { flex-direction: row; gap: 6px; font-size: 13px; }
  .sheet { margin: auto; border-radius: 24px; max-height: min(84vh, 820px); max-height: min(84dvh, 820px); }
  .theme-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .theme-grid .option { flex-direction: column; align-items: flex-start; }
  .theme-grid .option__mark { position: absolute; right: 8px; top: 8px; }
  /* キャラが増えても自動で2列に並ぶ */
  .chara-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toasts { bottom: calc(env(safe-area-inset-bottom) + var(--tabbar-h) + 28px); }
}
@media (min-width: 1100px) {
  :root { --content: 860px; }
}

/* ---------- お知らせ ---------- */
.toasts {
  position: fixed; z-index: 30;
  left: calc(env(safe-area-inset-left) + var(--gutter));
  right: calc(env(safe-area-inset-right) + var(--gutter));
  bottom: calc(env(safe-area-inset-bottom) + var(--tabbar-h) + 12px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  width: 100%; max-width: 520px;
  padding: 10px 10px 10px 16px;
  border-radius: 16px;
  background: var(--c-text); color: var(--c-bg);
  box-shadow: 0 8px 24px rgb(0 0 0 / .3);
  animation: toast-in .25s var(--ease);
}
.toast--error { border-left: 6px solid #e5484d; }
.toast__text { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.toast__action { flex: none; min-height: 44px; padding: 0 14px; }
.toast__close { flex: none; width: 44px; height: 44px; background: transparent; border-color: transparent; color: inherit; }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }

/* ---------- データ・バックアップ ---------- */
.data-status { font-weight: 700; }
.data-status.is-error { color: var(--c-text); padding: 8px 12px; border-radius: 12px; border: 2px solid #e5484d; }
.data-notes { padding-left: 1.2em; list-style: disc; font-size: 13.5px; color: var(--c-muted); display: flex; flex-direction: column; gap: 4px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-row .btn { flex: 1 1 200px; white-space: normal; text-align: center; line-height: 1.3; }
.app-version { text-align: center; padding-top: 4px; }

/* ---------- 狭い画面・文字の拡大 ---------- */
/* 文字を200%に拡大した場合や、とても幅の狭い画面では縦に並べる */
@media (max-width: 359px) {
  :root { --gutter: 12px; }
  .hero__body { flex-direction: column; align-items: stretch; }
  .hero__art { align-self: center; }
  .bubble::before { left: 24px; top: -7px; transform: rotate(135deg); }
  .shortcuts__list { grid-template-columns: minmax(0, 1fr); }
  .tile { min-height: 0; flex-direction: row; align-items: center; flex-wrap: wrap; column-gap: 12px; }
  .tile__icon { margin-bottom: 0; }
  .tile__desc { flex-basis: 100%; }
  .search { padding-left: 14px; }
  .logo__text { font-size: 18px; letter-spacing: 0; }
  .search__icon { display: none; }
  .option-row, .theme-grid { grid-template-columns: minmax(0, 1fr); }
  .btn { white-space: normal; text-align: center; }
}
@media (max-width: 299px) {
  /* 下部ナビは文字を隠してアイコンだけにする（読み上げ用の名前は残す） */
  .tabbar__item span {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  .tabbar__item { min-height: 52px; }
}

/* ---------- 動きを減らす ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
:root[data-motion="reduce"] *,
:root[data-motion="reduce"] *::before,
:root[data-motion="reduce"] *::after {
  animation-duration: .001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .001ms !important;
}
