/* ===== Theme tokens (Claude-inspired) ===== */
:root {
  --bg: #faf9f7;
  --bg-elev: #ffffff;
  --bg-panel: #f3f0ec;
  --border: #e5e1da;
  --text: #1f1e1d;
  --text-muted: #6b665e;
  --accent: #c96442;
  --accent-soft: #f3d7cd;
  --danger: #b3261e;
  --success: #2f7d4a;
  --warn: #d4a017;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04), 0 1px 1px rgba(0,0,0,0.02);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 24px 48px rgba(0,0,0,0.12), 0 8px 16px rgba(0,0,0,0.06);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --font-sans: -apple-system, "Hiragino Sans", "Yu Gothic UI", system-ui, sans-serif;
  --font-serif: "Hiragino Mincho ProN", "Yu Mincho", serif;
}

html[data-theme="dark"], body.theme-dark {
  --bg: #1f1e1d;
  --bg-elev: #2a2826;
  --bg-panel: #262422;
  --border: #3a3633;
  --text: #ebe7e0;
  --text-muted: #968f86;
  --accent: #e08368;
  --accent-soft: #4a2e26;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg: 0 24px 48px rgba(0,0,0,0.6);
}
html[data-theme="dark"] #importBtn, body.theme-dark #importBtn {
  background: #1e3022; border-color: #3a5e3e; color: #85c48a;
}
html[data-theme="dark"] #importBtn:hover, body.theme-dark #importBtn:hover {
  background: #243826; border-color: #5a8f5f;
}
html[data-theme="dark"] #exportCsvBtn, body.theme-dark #exportCsvBtn {
  background: #221e36; border-color: #463d6e; color: #a89de0;
}
html[data-theme="dark"] #exportCsvBtn:hover, body.theme-dark #exportCsvBtn:hover {
  background: #2a2540; border-color: #6e63a4;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"], body.theme-auto {
    --bg: #1f1e1d;
    --bg-elev: #2a2826;
    --bg-panel: #262422;
    --border: #3a3633;
    --text: #ebe7e0;
    --text-muted: #968f86;
    --accent: #e08368;
    --accent-soft: #4a2e26;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.5);
    --shadow-lg: 0 24px 48px rgba(0,0,0,0.6);
  }
}

/* ===== Reset ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; color: inherit; }
ul { list-style: none; }

.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.small { font-size: 0.85em; }
.spacer { flex: 1; }

/* ===== Top bar ===== */
.top-bar {
  position: fixed; top: 0; left: 0; right: 0;
  height: 56px;
  padding: 0 12px;
  padding-top: env(safe-area-inset-top, 0);
  height: calc(56px + env(safe-area-inset-top, 0));
  display: flex; align-items: center; gap: 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}
.top-bar > * { padding-top: env(safe-area-inset-top, 0); }
.top-bar .icon-btn,
.top-bar .top-title,
.top-bar .top-actions { padding-top: 0; }
.icon-btn {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: var(--text);
  transition: background .15s;
  font-size: 22px;
}
.icon-btn:hover, .icon-btn:active { background: var(--bg-panel); }
.top-title {
  flex: 1;
  display: flex; flex-direction: column; line-height: 1.2;
  min-width: 0;
}
.top-title #currentDeckName {
  font-weight: 600; font-size: 16px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.top-actions { display: flex; gap: 4px; background: var(--bg-panel); border-radius: 999px; padding: 3px; }
.mode-btn {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-muted);
  transition: all .15s;
}
.mode-btn.active {
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ===== Side panel ===== */
.side-panel {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: min(320px, 85vw);
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 16px 14px;
  padding-top: calc(16px + env(safe-area-inset-top, 0));
  display: flex; flex-direction: column; gap: 18px;
  transform: translateX(-100%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  z-index: 50;
  overflow-y: auto;
}
.side-panel.open { transform: translateX(0); }
.backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  opacity: 0; pointer-events: none;
  transition: opacity .25s;
  z-index: 40;
}
.backdrop.open { opacity: 1; pointer-events: auto; }
.side-panel-header { display: flex; align-items: center; justify-content: space-between; }
.brand {
  font-family: var(--font-serif);
  font-size: 20px; font-weight: 500;
  letter-spacing: 0.02em;
}
.side-panel-section { display: flex; flex-direction: column; gap: 6px; }
.section-title {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 4px 4px;
}
.badge {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  text-transform: none;
  letter-spacing: 0;
}
.deck-list { display: flex; flex-direction: column; gap: 2px; }
.deck-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s;
}
.deck-item:hover { background: var(--bg-elev); }
.deck-item.active { background: var(--bg-elev); box-shadow: var(--shadow-sm); }
.deck-item .deck-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.deck-item .deck-name {
  flex: 1; font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.deck-item .deck-meta { font-size: 11px; color: var(--text-muted); }
.deck-item .deck-edit {
  visibility: hidden;
  width: 28px; height: 28px;
  border-radius: 50%;
  font-size: 14px;
  color: var(--text-muted);
}
.deck-item:hover .deck-edit { visibility: visible; }
.deck-item .deck-edit:hover { background: var(--bg-panel); color: var(--text); }
.deck-item .deck-check {
  width: 17px; height: 17px;
  flex-shrink: 0;
  accent-color: var(--accent, #c96442);
  cursor: pointer;
  margin: 0;
}

.combined-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  font-size: 12px;
  color: var(--text-muted);
}
.link-btn {
  background: none; border: none; padding: 0;
  color: var(--accent, #c96442);
  font-size: 12px; cursor: pointer;
  text-decoration: underline;
  flex-shrink: 0;
}
.mode-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.ghost-btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  transition: all .12s;
}
.ghost-btn:hover { border-color: var(--accent); }
.ghost-btn.full { width: 100%; }
#importBtn {
  background: #edf4ee;
  border-color: #b2d4b6;
  color: #376b3e;
}
#importBtn:hover { border-color: #7aba82; background: #e0efe1; }
#exportCsvBtn {
  background: #edeaf7;
  border-color: #c4bde6;
  color: #5a529a;
}
#exportCsvBtn:hover { border-color: #9b90d4; background: #e4e0f3; }
.primary-btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500;
  color: white;
  background: var(--accent);
  transition: filter .12s, transform .05s;
}
.primary-btn:hover { filter: brightness(1.05); }
.primary-btn:active { transform: scale(0.98); }
.danger-btn {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--danger);
  border: 1px solid transparent;
}
.danger-btn:hover { background: rgba(179,38,30,0.08); }


.side-panel-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ===== Empty view ===== */
.empty-view, .study-view, .quiz-view, .edit-view {
  position: absolute;
  top: calc(56px + env(safe-area-inset-top, 0));
  left: 0; right: 0; bottom: 0;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0));
  overflow-y: auto;
}
.empty-view {
  display: flex; align-items: center; justify-content: center;
}
.empty-card {
  max-width: 380px;
  text-align: center;
  padding: 40px 24px;
}
.empty-emoji { font-size: 56px; margin-bottom: 16px; }
.empty-card h2 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 24px;
  margin-bottom: 10px;
}
.empty-card p { margin-bottom: 24px; line-height: 1.6; }

/* ===== Study view ===== */
.study-view {
  display: flex; flex-direction: column;
}
.study-main {
  flex: 1;
  display: flex; gap: 16px;
  min-height: 0;
}
.study-main .study-stage { flex: 1; }
.study-outline {
  width: 240px; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.outline-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px; font-weight: 600;
  color: var(--text-muted);
}
.outline-list { flex: 1; overflow-y: auto; padding: 6px; }
.outline-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 9px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: background .1s;
}
.outline-item:hover { background: var(--bg-panel); }
.outline-item[draggable="true"]:not(.selectable) { cursor: grab; }
.outline-item.dragging { opacity: .4; cursor: grabbing; }
.outline-move-btn {
  display: none; margin-left: auto; flex-shrink: 0;
  background: none; border: 1px solid var(--border); border-radius: 6px;
  padding: 1px 7px; font-size: 12px; cursor: pointer;
  color: var(--text-muted); line-height: 1.6;
}
.outline-item:hover .outline-move-btn { display: inline-block; }
.outline-move-btn:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.deck-item.drag-over {
  background: var(--accent-soft);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 8px;
}
.outline-item.current {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
}
.outline-num { color: var(--text-muted); font-size: 11px; min-width: 24px; text-align: right; flex-shrink: 0; }
.outline-term { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.outline-mark { font-size: 12px; flex-shrink: 0; }
.outline-head .link-btn { margin-left: auto; }
.outline-head .link-btn.active { color: var(--accent); font-weight: 700; }
.outline-bulk-bar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}
.outline-bulk-bar .spacer { flex: 1; }
.outline-bulk-bar .bulk-all { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-muted); cursor: pointer; }
.outline-bulk-bar .bulk-count { font-size: 12px; color: var(--text-muted); }
.outline-bulk-bar .ghost-btn,
.outline-bulk-bar .danger-btn { padding: 4px 9px; font-size: 12px; }
.outline-bulk-bar button:disabled { opacity: .45; cursor: not-allowed; }
.outline-item .outline-check { flex-shrink: 0; margin: 0; cursor: pointer; }
.outline-item.selectable { cursor: pointer; }
.outline-item.checked { background: var(--accent-soft); }
@media (max-width: 860px) {
  .study-outline { display: none; }
}
.study-stage {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  perspective: 1400px;
  min-height: 0;
  user-select: none;
  touch-action: pan-y;
}
.card-stage-actions {
  position: absolute;
  top: 8px; right: 8px;
  z-index: 5;
  display: flex;
  gap: 6px;
}
.card-corner-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-muted);
  font-size: 15px;
  cursor: pointer;
  opacity: 0.35;
  transition: opacity .12s, color .12s, background .12s;
}
.card-corner-btn:hover { opacity: 1; background: var(--bg-panel); }
.card-corner-btn:disabled { opacity: 0.15; }
.card-delete-btn:hover { color: var(--danger, #b3261e); }

/* ゴミ箱モーダル */
.trash-list { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow-y: auto; }
.trash-empty { padding: 24px 8px; text-align: center; color: var(--text-muted); }
.trash-item { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.trash-item-main { flex: 1; min-width: 0; }
.trash-item-term { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trash-item-meta { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trash-item-actions { display: flex; gap: 6px; flex-shrink: 0; }
.card-stack {
  position: relative;
  width: min(100%, 480px);
  aspect-ratio: 3/4;
  max-height: 100%;
}
.study-card {
  border-radius: var(--radius-lg);
  background: var(--bg-elev);
  box-shadow: var(--shadow-md);
  transform-style: preserve-3d;
  will-change: transform;
}
.stack-card {
  position: absolute;
  inset: 0;
  transition: transform .35s cubic-bezier(.4,0,.2,1), box-shadow .25s, opacity .25s;
}
.stack-card-2 {
  transform: translateY(16px) scale(0.92);
  opacity: 0.55;
  z-index: 1;
}
.stack-card-1 {
  transform: translateY(8px) scale(0.96);
  opacity: 0.85;
  z-index: 2;
}
.stack-card-0 {
  z-index: 3;
  cursor: grab;
  transition: transform .35s cubic-bezier(.4,0,.2,1), box-shadow .2s;
}
.stack-card-0.dragging { transition: none; cursor: grabbing; }
.stack-card-0.flipped { transform: rotateY(180deg); }
.stack-card-0.fly-right {
  transition: transform .45s cubic-bezier(.4,0,.2,1), opacity .35s;
  transform: translate(140vw, 40px) rotate(35deg);
  opacity: 0;
}
.stack-card-0.fly-left {
  transition: transform .45s cubic-bezier(.4,0,.2,1), opacity .35s;
  transform: translate(-140vw, 40px) rotate(-35deg);
  opacity: 0;
}
.stack-card-0.fly-down {
  transition: transform .45s cubic-bezier(.4,0,.2,1), opacity .35s;
  transform: translate(0, 110vh) scale(0.9);
  opacity: 0;
}
.stack-card-1 .card-face,
.stack-card-2 .card-face {
  color: transparent;
  pointer-events: none;
}
.card-face {
  position: absolute; inset: 0;
  padding: 32px 28px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  backface-visibility: hidden;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  text-align: center;
}
.card-back { transform: rotateY(180deg); background: var(--bg-elev); }
.card-term {
  font-family: var(--font-serif);
  font-size: clamp(28px, 7vw, 48px);
  font-weight: 500;
  line-height: 1.3;
  word-break: break-word;
  margin-bottom: 24px;
}
.card-meaning {
  font-size: clamp(15px, 3.6vw, 17px);
  line-height: 1.7;
  margin-bottom: 14px;
  word-break: break-word;
  text-align: left;
  width: 100%;
  max-width: 380px;
}
.card-memo {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  max-width: 320px;
  white-space: pre-wrap;
  margin-bottom: 16px;
}
.card-back-scroll {
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  display: flex; flex-direction: column; align-items: center;
  padding: 4px 2px 36px;
}
.card-reading {
  font-family: var(--font-serif);
  font-size: clamp(17px, 4.6vw, 26px);
  font-weight: 500;
  color: var(--text);
  line-height: 1.4;
  letter-spacing: 0.01em;
  margin-bottom: 12px;
  word-break: break-word;
  text-align: left;
  width: 100%;
  max-width: 380px;
}
.card-reading:empty { display: none; }
.card-details {
  width: 100%;
  max-width: 380px;
  display: flex; flex-direction: column; gap: 11px;
  margin-top: 2px;
  text-align: left;
}
.card-details:empty { display: none; }
.card-detail {
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}
.card-hint {
  position: absolute; bottom: 20px; left: 0; right: 0;
  font-size: 11px;
  color: var(--text-muted);
}
.swipe-overlay {
  position: absolute; inset: 0;
  pointer-events: none;
  border-radius: var(--radius-lg);
  opacity: 0;
  transition: opacity .15s;
}
.swipe-overlay.show-right { background: rgba(47,125,74,0.3); opacity: 1; }
.swipe-overlay.show-left { background: rgba(179,38,30,0.3); opacity: 1; }
.swipe-overlay.show-up { background: rgba(201,100,66,0.2); opacity: 1; }
.swipe-overlay.show-down { background: rgba(150,143,134,0.25); opacity: 1; }

.answer-bar {
  display: flex; gap: 8px;
  padding: 10px 4px 2px;
}
.answer-btn {
  flex: 1;
  padding: 12px 8px;
  border-radius: var(--radius-md);
  font-size: 15px; font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  transition: transform .05s, filter .12s, background .12s;
}
.answer-btn:active { transform: scale(0.97); }
.answer-btn.answer-known { color: var(--success); border-color: rgba(47,125,74,0.4); background: rgba(47,125,74,0.08); }
.answer-btn.answer-missed { color: var(--danger); border-color: rgba(179,38,30,0.4); background: rgba(179,38,30,0.07); }
.answer-btn.answer-skip { color: var(--text-muted); }
.answer-btn:hover { filter: brightness(1.04); }

.study-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 4px 6px;
}
.study-bar .ghost-btn { min-width: 56px; padding: 10px; font-size: 18px; }
.progress { flex: 1; display: flex; flex-direction: column; gap: 6px; align-items: center; min-width: 0; }
.progress-meta {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
  gap: 8px;
}
.progress-meta #progressText { font-size: 12px; color: var(--text-muted); }
.session-stats { display: flex; gap: 6px; }
.stat-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.stat-pill.stat-known { background: rgba(47,125,74,0.12); color: var(--success); }
.stat-pill.stat-missed { background: rgba(179,38,30,0.12); color: var(--danger); }
.progress-bar {
  width: 100%;
  height: 3px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width .25s;
}
.study-tools {
  display: flex; gap: 8px; justify-content: center; padding-bottom: 4px;
  flex-wrap: wrap; align-items: center;
}
.chip {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-muted);
}
.chip:hover { color: var(--text); }
.chip.active {
  background: var(--accent, #c96442);
  color: #fff;
  border-color: var(--accent, #c96442);
}
.auto-sec-wrap {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--text-muted);
}
.auto-sec {
  width: 44px; text-align: center;
  padding: 5px 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 12px;
}

/* ===== Quiz view (四択) ===== */
.quiz-view { display: flex; flex-direction: column; }
.quiz-stage {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  min-height: 0;
}
.quiz-play {
  width: min(100%, 520px);
  display: flex; flex-direction: column; gap: 22px;
}
.quiz-needmore { text-align: center; padding: 24px; }
.quiz-needmore h2 {
  font-family: var(--font-serif); font-weight: 500; font-size: 20px; margin-bottom: 8px;
}
.quiz-question {
  text-align: center;
  padding: 28px 20px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.quiz-q-label { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }
.quiz-q-term {
  font-family: var(--font-serif);
  font-size: clamp(26px, 6vw, 42px);
  font-weight: 500;
  line-height: 1.3;
  word-break: break-word;
}
.quiz-options { display: flex; flex-direction: column; gap: 10px; }
.quiz-option {
  display: flex; align-items: center; gap: 10px;
  text-align: left;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  font-size: 15px;
  line-height: 1.4;
  color: var(--text);
  transition: border-color .12s, background .12s, transform .05s;
}
.quiz-option:hover:not(:disabled) { border-color: var(--accent); }
.quiz-option:active:not(:disabled) { transform: scale(0.99); }
.quiz-option .opt-key {
  flex-shrink: 0;
  width: 24px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px;
  background: var(--bg-panel);
  font-size: 12px; font-weight: 600;
  color: var(--text-muted);
}
.quiz-option.correct {
  border-color: var(--success);
  background: rgba(47,125,74,0.12);
}
.quiz-option.correct .opt-key { background: var(--success); color: #fff; }
.quiz-option.wrong {
  border-color: var(--danger);
  background: rgba(179,38,30,0.1);
}
.quiz-option.wrong .opt-key { background: var(--danger); color: #fff; }
.quiz-option:disabled { cursor: default; }

/* ===== Edit view ===== */
.edit-view { display: flex; flex-direction: column; gap: 12px; max-width: 720px; margin: 0 auto; }
.edit-form {
  display: flex; flex-direction: column; gap: 8px;
  padding: 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.edit-form input, .edit-form textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: 15px;
  resize: vertical;
  outline: none;
  transition: border-color .12s;
}
.edit-form input:focus, .edit-form textarea:focus { border-color: var(--accent); }
.edit-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }

.term-search { display: flex; align-items: center; gap: 8px; }
.term-search input {
  flex: 1; min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  font-size: 14px;
  outline: none;
}
#selectModeBtn { flex-shrink: 0; }
#selectModeBtn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* 一括操作バー */
.bulk-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  border: 1px solid var(--border);
}
.bulk-bar .bulk-all {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 13px; color: var(--text);
}
.bulk-bar .bulk-all input { accent-color: var(--accent); width: 16px; height: 16px; }
.bulk-bar .bulk-count { font-size: 13px; color: var(--text-muted); }
.bulk-bar .ghost-btn, .bulk-bar .danger-btn { padding: 7px 12px; font-size: 13px; }
.bulk-bar button:disabled { opacity: 0.4; cursor: not-allowed; }
.bulk-bar .danger-btn { border-color: var(--danger); }

.term-check {
  width: 18px; height: 18px; margin-top: 2px;
  accent-color: var(--accent);
  flex-shrink: 0;
}
.term-row.is-selectable .term-main { cursor: pointer; }

.term-list-foot { margin-top: 14px; text-align: center; padding-bottom: 8px; }
.link-btn.danger { color: var(--danger); }

.term-list { display: flex; flex-direction: column; gap: 4px; }
.term-row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  transition: border-color .12s;
}
.term-row:hover { border-color: var(--accent); }
.term-row .term-main {
  flex: 1; min-width: 0;
  display: block;
  text-align: left;
  background: none; border: none; padding: 0;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: opacity .12s;
}
.term-row .term-main:hover .term-front { color: var(--accent); }
.term-row.is-editing { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: var(--accent-soft); }
.editing-badge {
  display: inline-block; margin-left: 8px; font-size: 11px; font-weight: 600;
  color: #fff; background: var(--accent);
  border-radius: 4px; padding: 0 6px; vertical-align: middle;
}
.term-row .term-front { font-weight: 600; font-size: 15px; word-break: break-word; }
.term-row .term-back { font-size: 13px; color: var(--text-muted); word-break: break-word; margin-top: 2px; line-height: 1.4; }
.term-row .term-reading { font-size: 12px; color: var(--text-muted); margin-left: 8px; font-weight: 400; }
.term-row .term-stats { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.term-row .term-stats .stat-wrong { color: var(--danger); font-weight: 600; }
.term-row .term-acts { display: flex; gap: 4px; }
.term-row .icon-btn { width: 32px; height: 32px; font-size: 16px; }
.term-row.is-hidden { opacity: 0.5; background: var(--bg-panel); }
.term-row .hidden-badge {
  display: inline-block; margin-left: 8px; font-size: 11px; font-weight: 600;
  color: var(--text-muted); border: 1px solid var(--border);
  border-radius: 4px; padding: 0 5px; vertical-align: middle;
}

/* ===== Session complete ===== */
.session-complete {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  border-radius: var(--radius-lg);
  z-index: 5;
  animation: fade-in .25s;
}
.complete-card {
  text-align: center;
  padding: 28px 24px;
  max-width: 360px;
  width: 100%;
}
.complete-emoji {
  font-size: 56px;
  margin-bottom: 8px;
  animation: bounce-in .5s cubic-bezier(.34,1.56,.64,1);
}
@keyframes bounce-in {
  from { transform: scale(0.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.complete-card h2 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 22px;
  margin-bottom: 20px;
}
.complete-stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 24px;
}
.stat {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.stat-num {
  font-family: var(--font-serif);
  font-size: 28px;
  font-weight: 500;
  color: var(--accent);
}
.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.complete-actions {
  display: flex; flex-direction: column; gap: 8px;
}

/* ===== Paste textarea ===== */
#pasteArea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: 13px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  resize: vertical;
  outline: none;
  margin-bottom: 12px;
  min-height: 180px;
}
#pasteArea:focus { border-color: var(--accent); }

/* ===== Modal ===== */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  z-index: 100;
  animation: fade-in .15s;
}
.modal.hidden { display: none; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal-content {
  background: var(--bg-elev);
  border-radius: var(--radius-md);
  padding: 22px;
  width: min(440px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-content h3 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 18px;
  margin-bottom: 16px;
}
.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-row label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.form-row input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: 14px;
  outline: none;
}
.form-row input:focus { border-color: var(--accent); }
.form-row select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.form-row select:focus { border-color: var(--accent); }
.emoji-picker, .color-picker {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.emoji-picker button {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  font-size: 20px;
  border: 1px solid transparent;
  background: var(--bg);
}
.emoji-picker button.selected { border-color: var(--accent); background: var(--accent-soft); }
.color-picker button {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
}
.color-picker button.selected { border-color: var(--text); }
.modal-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  z-index: 200;
  animation: toast-in .2s;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== 用語検索オーバーレイ ===== */
.search-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 120;
  display: flex; align-items: flex-start; justify-content: center;
  padding: calc(64px + env(safe-area-inset-top, 0)) 14px 14px;
}
.search-box {
  width: min(620px, 100%);
  max-height: 80vh;
  display: flex; flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.search-input-row {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.search-input-row .search-icon { color: var(--text-muted); flex-shrink: 0; }
#globalSearchInput {
  flex: 1; min-width: 0;
  border: none; background: none; outline: none;
  font-size: 16px; color: var(--text);
}
.search-scope {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--text-muted);
  white-space: nowrap; flex-shrink: 0;
}
.search-scope input { accent-color: var(--accent); }
.search-results {
  overflow-y: auto;
  padding: 6px;
}
.search-empty {
  padding: 24px 12px; text-align: center;
  color: var(--text-muted); font-size: 13px;
}
.search-result {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s;
}
.search-result:hover { background: var(--bg-panel); }
.sr-head {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  margin-bottom: 2px;
}
.sr-term { font-weight: 600; font-size: 15px; color: var(--text); }
.sr-reading { font-size: 12px; color: var(--text-muted); }
.sr-deck {
  font-size: 11px; color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 1px 7px;
}
.sr-hidden {
  font-size: 11px; color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 0 5px;
}
.sr-meaning {
  font-size: 13px; color: var(--text-muted);
  line-height: 1.5;
  overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

/* ===== カードタイプバッジ (カード表面・左上) ===== */
.card-type-badge {
  position: absolute;
  top: 14px; left: 14px;
  display: inline-flex;
  align-items: center; gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px; font-weight: 600;
  border: 1px solid transparent;
  letter-spacing: 0.03em;
  pointer-events: none;
}

/* ===== タイプセレクター (編集フォーム) ===== */
.type-selector-row {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 0 0 4px;
}
.type-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 12px; font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-muted);
  transition: all .14s;
  cursor: pointer;
}
.type-btn:hover { border-color: currentColor; color: var(--text); }
.type-btn.active {
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
.type-btn-icon { font-size: 14px; }
.type-btn-label { font-size: 12px; }

/* 動的タイプフィールド */
#typeFields { display: flex; flex-direction: column; gap: 8px; }
.type-field {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: 14px;
  resize: vertical;
  outline: none;
  font-family: inherit;
  color: inherit;
  transition: border-color .12s;
}
.type-field:focus { border-color: var(--accent); }

/* ===== 編集フォーム内の共通 input/textarea フォーカス ===== */
#termInput, #meaningInput { width: 100%; }

/* ===== リッチ裏面 (アイコン + テキスト行) ===== */
.card-detail-rich {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
}
.detail-icon {
  flex-shrink: 0;
  font-size: 16px;
  margin-top: 1px;
}
.detail-text { flex: 1; color: var(--text); }

/* 発言者: 少し強調 */
.detail-speaker .detail-text { font-weight: 600; font-size: 15px; }

/* 出典・書籍: 斜体ぽく */
.detail-book .detail-text { font-style: italic; color: var(--text-muted); }
.detail-era .detail-text  { color: var(--text-muted); font-size: 13px; }
.detail-memo .detail-text { color: var(--text-muted); font-size: 13px; }

/* 英単語: 発音 + 品詞ヘッダー */
.detail-eng-header {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 2px;
}
.eng-pron {
  font-family: "Courier New", monospace;
  font-size: 14px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}
.eng-pos {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px; font-weight: 600;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* 例文: 斜体 */
.detail-example .detail-text { font-style: italic; }

/* 英単語カードの発音エリアはモノスペース */
#studyCard[data-card-type="english"] .card-reading {
  font-family: "Courier New", monospace;
  font-size: clamp(14px, 3vw, 18px);
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

/* 名言・哲学は長文なのでカード表面のフォントを小さく */
#studyCard[data-card-type="quote"] .card-term,
#studyCard[data-card-type="philosophy"] .card-term {
  font-size: clamp(16px, 3.5vw, 22px);
  line-height: 1.65;
}
#studyCard[data-card-type="quote"] .card-hint,
#studyCard[data-card-type="philosophy"] .card-hint { bottom: 12px; }

/* ===== 用語リストのタイプバッジ ===== */
.term-type-badge {
  display: inline-flex; align-items: center; gap: 3px;
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px; font-weight: 600;
  border: 1px solid transparent;
  vertical-align: middle;
}

/* ===== Responsive ===== */
@media (min-width: 900px) {
  .side-panel {
    position: fixed;
    transform: translateX(0);
    box-shadow: none;
  }
  .backdrop { display: none !important; }
  #openSide { display: none; }
  .top-bar, .empty-view, .study-view, .quiz-view, .edit-view {
    left: min(320px, 85vw);
  }
}
