/* ===== カラートークン（ライト既定） ===== */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1b1f27;
  --text-sub: #6b7280;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --ok: #2f9e44;
  --ng: #e03131;
  --border: #dde0e6;
  --tab-bg: #ffffff;
  --shadow: rgba(0, 0, 0, 0.08);
}

/* ダーク（端末設定追従） */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161c;
    --surface: #1f232c;
    --text: #e7e9ee;
    --text-sub: #9aa1ad;
    --accent: #5c7cfa;
    --accent-text: #ffffff;
    --ok: #40c057;
    --ng: #fa5252;
    --border: #333945;
    --tab-bg: #1a1d24;
    --shadow: rgba(0, 0, 0, 0.4);
  }
}

/* ダーク（手動指定） */
:root[data-theme="dark"] {
  --bg: #14161c;
  --surface: #1f232c;
  --text: #e7e9ee;
  --text-sub: #9aa1ad;
  --accent: #5c7cfa;
  --accent-text: #ffffff;
  --ok: #40c057;
  --ng: #fa5252;
  --border: #333945;
  --tab-bg: #1a1d24;
  --shadow: rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Hiragino Sans", sans-serif;
  height: 100%;
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
}

/* ===== ヘッダー ===== */
#header {
  background: var(--accent);
  color: var(--accent-text);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-shrink: 0;
}
#header h1 { font-size: 18px; font-weight: 700; }
#headerInfo { font-size: 12px; opacity: 0.85; }

/* ===== メイン ===== */
#main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.view { padding: 16px; }

/* ===== 学習 ===== */
.study-info { font-size: 13px; color: var(--text-sub); margin-bottom: 12px; text-align: center; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 2px 8px var(--shadow);
  padding: 28px 20px;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
}
.card-num { font-size: 12px; color: var(--text-sub); }
.card-front { font-size: 26px; font-weight: 700; line-height: 1.4; word-break: break-word; }
.card-back { font-size: 20px; line-height: 1.5; color: var(--accent); font-weight: 600; word-break: break-word; }

.btn-audio {
  background: none;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 24px;
  padding: 8px 22px;
  font-size: 15px;
}
.btn-audio:disabled { opacity: 0.35; border-color: var(--text-sub); color: var(--text-sub); }
.btn-audio:active:not(:disabled) { background: var(--accent); color: var(--accent-text); }

.study-done { text-align: center; padding: 60px 20px; }
.study-done p { font-size: 18px; margin-bottom: 24px; color: var(--text-sub); }

/* 親指の届く下部に操作ボタンを固定 */
.study-actions {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 64px);
  padding: 0 16px 12px;
}

.btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 14px;
  font-size: 18px;
  font-weight: 700;
  font-family: inherit;
  padding: 16px;
  color: var(--accent-text);
  background: var(--accent);
}
.btn:active { filter: brightness(0.85); }
.btn-big { min-height: 60px; }
.btn-primary { background: var(--accent); }
.judge-row { display: flex; gap: 12px; }
.btn-ng { background: var(--ng); }
.btn-ok { background: var(--ok); }

/* ===== 一覧 ===== */
.search-wrap { position: sticky; top: 0; background: var(--bg); padding: 4px 0 10px; z-index: 5; }
#searchBox {
  width: 100%;
  font-size: 16px;
  font-family: inherit;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.list-container { display: flex; flex-direction: column; gap: 6px; }
.list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  gap: 10px;
  align-items: center;
}
.list-item .li-num { font-size: 11px; color: var(--text-sub); min-width: 34px; }
.list-item .li-body { flex: 1; min-width: 0; }
.list-item .li-en { font-size: 15px; font-weight: 600; }
.list-item .li-ja { font-size: 13px; color: var(--text-sub); }
.list-item .li-play { font-size: 18px; color: var(--accent); padding: 6px; }
.list-item.no-audio .li-play { opacity: 0.25; }
.list-item.playing { border-color: var(--accent); }
.list-hint { text-align: center; color: var(--text-sub); font-size: 13px; padding: 20px; }

/* ===== 統計・設定 ===== */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.stat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
}
.stat-num { font-size: 28px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 12px; color: var(--text-sub); margin-top: 4px; }
.box-dist { font-size: 13px; color: var(--text-sub); text-align: center; margin-bottom: 8px; }
.section-title { font-size: 15px; margin: 20px 0 10px; }
.setting-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.setting-row label { font-size: 15px; }
.setting-row select {
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
}

/* ===== タブバー ===== */
#tabbar {
  flex-shrink: 0;
  display: flex;
  background: var(--tab-bg);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-sub);
  padding: 14px 0;
}
.tab.active { color: var(--accent); }
