/* 英会話フレーズ帳 */

:root {
  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --text: #1c1c1e;
  --text-muted: #6e6e73;
  --accent: #1e6fd9;
  --accent-soft: #e3edfb;
  --border: #e2e4e9;
  --danger: #d93a3a;
  --again: #e0524f;
  --hard: #e8923a;
  --good: #3fa25c;
  --easy: #3a7de8;
  --radius: 14px;
  --tabbar-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101114;
    --card-bg: #1c1d21;
    --text: #f2f2f5;
    --text-muted: #9a9aa2;
    --accent: #4a8ceb;
    --accent-soft: #1d2c42;
    --border: #2c2d33;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}

#view {
  min-height: 100dvh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
}
body.fullscreen #view { padding-bottom: 0; }

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

h1 { font-size: 22px; margin-bottom: 14px; }
h2 { font-size: 16px; margin-bottom: 8px; }

.muted { color: var(--text-muted); }
.small-text { font-size: 13px; }
.center { text-align: center; }
.error { color: var(--danger); }
.warn-text { color: var(--hard); font-size: 14px; margin: 6px 0; }
.hidden { display: none !important; }

/* ---- タブバー ---- */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 10;
}
body.fullscreen .tabbar { display: none; }
.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 10px;
  min-height: 44px;
}
.tabbar a.active { color: var(--accent); }
.tab-icon { font-size: 21px; }

/* ---- ボタン ---- */
.primary-btn, .secondary-btn {
  display: block;
  width: 100%;
  padding: 13px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
  font-family: inherit;
}
.primary-btn { background: var(--accent); color: #fff; }
.primary-btn:disabled { opacity: 0.55; }
.primary-btn.big { padding: 16px; font-size: 17px; }
.secondary-btn {
  background: var(--card-bg);
  color: var(--accent);
  border: 1px solid var(--border);
  margin-top: 8px;
}
.secondary-btn.danger { color: var(--danger); }
.icon-btn {
  background: none; border: none; font-size: 19px; cursor: pointer;
  min-width: 44px; min-height: 44px; color: var(--text);
}

/* ---- ホーム ---- */
.app-title { text-align: center; margin: 8px 0 18px; }
.stats-row { display: flex; gap: 12px; margin-bottom: 16px; }
.stat-card {
  flex: 1;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 18px 12px;
  text-align: center;
  border: 1px solid var(--border);
}
.stat-num { font-size: 40px; font-weight: 700; color: var(--accent); line-height: 1.2; }
.stat-label { font-size: 13px; color: var(--text-muted); }

.direction-toggle {
  display: flex;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 14px;
}
.dir-btn {
  flex: 1;
  padding: 10px 4px;
  border: none;
  background: none;
  border-radius: 10px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  min-height: 44px;
  font-family: inherit;
}
.dir-btn.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.home-info {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
  padding: 0 4px;
}

.banner {
  position: relative;
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: 12px 40px 12px 14px;
  font-size: 13px;
  margin-bottom: 14px;
}
.banner-close { position: absolute; top: 2px; right: 2px; background: none; border: none; font-size: 18px; min-width: 40px; min-height: 40px; color: var(--text-muted); }
.share-icon { display: inline-block; transform: rotate(0deg); }

/* ---- カテゴリ ---- */
.category-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.category-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px 12px;
  text-decoration: none;
  color: var(--text);
  min-height: 44px;
}
.cat-icon { font-size: 26px; }
.cat-name { font-size: 14px; font-weight: 600; margin: 4px 0 2px; }
.cat-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }
.cat-bar { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.cat-bar-fill { height: 100%; background: var(--good); }

/* ---- フレーズ一覧 ---- */
.page-header { margin-bottom: 12px; }
.back-link { color: var(--accent); text-decoration: none; font-size: 15px; display: inline-block; padding: 4px 0; }
.phrase-list { list-style: none; margin-top: 14px; }
.phrase-row {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  flex-wrap: wrap;
}
.phrase-main { flex: 1; min-width: 0; }
.phrase-ja { font-size: 15px; }
.phrase-en { font-size: 15px; color: var(--accent); font-weight: 500; }
.phrase-note { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.phrase-actions { display: flex; align-items: center; }
.speak-btn {
  background: none; border: none; font-size: 20px; cursor: pointer;
  min-width: 44px; min-height: 44px;
}
.speak-btn.small { font-size: 15px; min-width: 32px; min-height: 32px; }
.speak-btn.big { font-size: 28px; }
.speak-btn.recording { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }

.dialog-turns { width: 100%; margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; }
.turn { margin-bottom: 10px; padding-left: 8px; border-left: 3px solid var(--border); }
.turn-you { border-left-color: var(--accent); }
.turn-speaker { font-size: 11px; color: var(--text-muted); font-weight: 600; }
.turn-ja, .turn-q { font-size: 14px; }
.turn-en, .turn-a { font-size: 14px; color: var(--accent); font-weight: 500; }

/* ---- 学習画面 ---- */
.study {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
}
.study-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
}
.progress-track { flex: 1; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); transition: width 0.25s; }
.progress-text { font-size: 12px; color: var(--text-muted); min-width: 44px; text-align: right; }

.study-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 22px;
  text-align: center;
  overflow-y: auto;
}
.dir-badge { font-size: 12px; color: var(--text-muted); margin-bottom: 14px; }
.new-badge { background: var(--accent); color: #fff; font-size: 10px; padding: 2px 6px; border-radius: 6px; font-weight: 700; }
.question { font-size: 26px; font-weight: 600; }
.question.small { font-size: 16px; font-weight: 400; margin-bottom: 12px; }
.answer { font-size: 26px; font-weight: 700; color: var(--accent); margin-bottom: 10px; }
.answer-tools { display: flex; gap: 14px; justify-content: center; }
.note-box {
  margin-top: 14px;
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  text-align: left;
}

.study-footer {
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom));
}
.rating-footer { display: flex; gap: 8px; }
.rate-btn {
  flex: 1;
  border: none;
  border-radius: var(--radius);
  padding: 10px 2px;
  color: #fff;
  cursor: pointer;
  min-height: 58px;
  font-family: inherit;
}
.rate-label { display: block; font-size: 13px; font-weight: 700; }
.rate-interval { display: block; font-size: 11px; opacity: 0.85; margin-top: 2px; }
.rate-again { background: var(--again); }
.rate-hard { background: var(--hard); }
.rate-good { background: var(--good); }
.rate-easy { background: var(--easy); }

.study-empty { text-align: center; padding-top: 15dvh; }
.big-emoji { font-size: 56px; margin-bottom: 10px; }
.study-empty .primary-btn { max-width: 260px; margin: 18px auto 0; }

/* 会話カード */
.dialog-body { justify-content: flex-start; }
.dialog-title { font-weight: 700; font-size: 17px; margin-bottom: 10px; }
.dialog-scroll { width: 100%; overflow-y: auto; text-align: left; }
.dialog-scroll .turn { margin-bottom: 14px; }
.turn-q { font-size: 16px; }
.turn-a { font-size: 16px; }
.hidden-answer {
  color: var(--text-muted);
  background: var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  display: inline-block;
}

/* 発音チェック結果 */
.recog-result { margin-top: 12px; }
.recog-score { font-size: 20px; font-weight: 700; }
.score-good { color: var(--good); }
.score-retry { color: var(--hard); font-size: 15px; }
.recog-words { margin: 6px 0; font-size: 16px; }
.word-hit { color: var(--good); }
.word-miss { color: var(--danger); text-decoration: underline; font-weight: 600; }
.recog-heard { font-size: 12px; }

/* ---- フォーム ---- */
.type-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tab-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: 10px;
  font-size: 15px;
  color: var(--text-muted);
  cursor: pointer;
  min-height: 44px;
  font-family: inherit;
}
.tab-btn.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; border-color: var(--accent); }
.tab-btn.small { min-height: 36px; padding: 6px 10px; font-size: 13px; flex: none; }

.phrase-form label { display: block; margin-bottom: 12px; font-size: 14px; font-weight: 600; }
.phrase-form input[type="text"], .phrase-form input[type="number"],
.phrase-form textarea, .phrase-form select,
.settings-section input[type="text"], .settings-section input[type="number"], .settings-section select {
  width: 100%;
  margin-top: 5px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px; /* 16px未満だとiOSでズームされる */
  background: var(--card-bg);
  color: var(--text);
  font-family: inherit;
}
.cat-select-row { display: flex; gap: 8px; align-items: center; }
.cat-select-row select { flex: 1; }
.cat-select-row .secondary-btn { width: auto; margin: 5px 0 0; padding: 11px 14px; }

.turn-editor {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 10px;
}
.turn-editor input { margin-bottom: 6px; }
.turn-editor-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.speaker-toggle { display: flex; gap: 6px; align-items: center; flex: 1; }
.speaker-name { max-width: 130px; }
.phrase-form .primary-btn { margin-top: 8px; }

/* ---- 設定 ---- */
.settings-section {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.settings-section label { display: block; margin: 10px 0; font-size: 14px; font-weight: 600; }
.row-label { display: flex !important; justify-content: space-between; align-items: center; }
.row-label input[type="checkbox"] { width: 22px; height: 22px; }
.import-row { display: flex; gap: 10px; align-items: center; margin-top: 4px; }
.file-label { display: inline-block; width: auto; text-align: center; padding: 11px 16px; cursor: pointer; }
.radio-label { font-weight: 400 !important; font-size: 13px !important; display: flex !important; align-items: center; gap: 4px; margin: 0 !important; }
.debug-section summary { font-weight: 600; font-size: 15px; cursor: pointer; min-height: 30px; }
input[type="range"] { width: 100%; margin-top: 8px; }

/* ---- トースト ---- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%) translateY(20px);
  background: rgba(30, 30, 34, 0.92);
  color: #fff;
  padding: 11px 18px;
  border-radius: 22px;
  font-size: 14px;
  max-width: 86vw;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 100;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
