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

:root {
  --bg:         #f0f4f8;
  --card:       #ffffff;
  --text:       #1e293b;
  --text-sub:   #64748b;
  --border:     #e2e8f0;
  --accent:     #2563eb;
  --accent-h:   #1d4ed8;
  --next:       #16a34a;
  --next-h:     #15803d;
  --debit-fg:   #b91c1c;
  --debit-bg:   #fef2f2;
  --credit-fg:  #15803d;
  --credit-bg:  #f0fdf4;
  --tag-bg:     #eff6ff;
  --tag-fg:     #1d4ed8;
  --radius:     14px;
  --shadow:     0 2px 12px rgba(0,0,0,.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:         #0f172a;
    --card:       #1e293b;
    --text:       #e2e8f0;
    --text-sub:   #94a3b8;
    --border:     #334155;
    --accent:     #3b82f6;
    --accent-h:   #60a5fa;
    --next:       #22c55e;
    --next-h:     #4ade80;
    --debit-fg:   #f87171;
    --debit-bg:   #1c1010;
    --credit-fg:  #4ade80;
    --credit-bg:  #0d1f14;
    --tag-bg:     #1e3a5f;
    --tag-fg:     #93c5fd;
    --shadow:     0 2px 16px rgba(0,0,0,.4);
  }
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 0 0 env(safe-area-inset-bottom);
}

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 32px;
}

/* ── Header ── */
header {
  padding: 20px 16px 12px;
  text-align: center;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.site-title {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -.5px;
  color: var(--accent);
}

.site-subtitle {
  font-size: .8rem;
  color: var(--text-sub);
  margin-top: 2px;
}

/* ── Site nav（練習する / 論点解説）── */
.site-nav {
  display: flex;
  max-width: 320px;
  margin: 10px auto 0;
  padding: 3px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.site-nav-tab {
  flex: 1;
  padding: 7px 0;
  font-size: .85rem;
  font-weight: 700;
  text-align: center;
  color: var(--text-sub);
  border-radius: 999px;
  text-decoration: none;
  transition: background .15s, color .15s;
}
.site-nav-tab:hover { color: var(--text); }
.site-nav-tab.is-current {
  background: var(--accent);
  color: #fff;
}

/* ── Intro ── */
.intro {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
  font-size: .875rem;
  line-height: 1.7;
  color: var(--text-sub);
}

.intro p + p { margin-top: 8px; }

/* 折りたたみ版（アプリのトップ）: 閉じていれば1行 */
.intro-fold { padding: 0; margin-top: 10px; }
.intro-fold summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  font-size: .8rem;
  line-height: 1.4;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.intro-fold summary::-webkit-details-marker { display: none; }
.intro-fold-text { flex: 1; color: var(--text-sub); }
.intro-fold-arrow { display: inline-block; font-size: .6rem; color: var(--text-sub); transition: transform .15s; }
.intro-fold[open] .intro-fold-arrow { transform: rotate(180deg); }
.intro-fold-link {
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}
.intro-fold-body { padding: 0 14px 14px; border-top: 1px solid var(--border); }
.intro-fold-body p:first-child { margin-top: 12px; }

.intro strong {
  color: var(--text);
  font-weight: 600;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.badge {
  background: var(--tag-bg);
  color: var(--tag-fg);
  font-size: .75rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
}

/* ── Question card ── */
.question-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  margin-top: 16px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.topic-tag {
  background: var(--tag-bg);
  color: var(--tag-fg);
  font-size: .8rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
}

.card-header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.question-count {
  font-size: .8rem;
  color: var(--text-sub);
}

.score-display {
  font-size: .8rem;
  font-weight: 700;
  color: var(--accent);
}

.question-text {
  font-size: 1.05rem;
  line-height: 1.75;
  font-weight: 500;
  min-height: 64px;
}

/* ── Buttons ── */
.btn {
  display: block;
  width: 100%;
  padding: 16px;
  margin-top: 16px;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
  min-height: 56px;
}

.btn:active { transform: scale(.97); }

.btn-check {
  background: #7c3aed;
  color: #fff;
}
.btn-check:hover  { background: #6d28d9; }
.btn-check:disabled { background: #a0a0b0; cursor: not-allowed; transform: none; }

.btn-next {
  background: var(--next);
  color: #fff;
}
.btn-next:hover { background: var(--next-h); }

.btn-skip {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 10px;
  background: none;
  border: none;
  color: var(--text-sub);
  font-size: .85rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.btn-skip:hover { color: var(--text); }

/* ── 解答入力エリア（借方・貸方 横並び） ── */
.journal-input-wrap {
  display: flex;
  flex-direction: row;
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.journal-input-block {
  flex: 1;
  min-width: 0;
  padding: 10px 10px 8px;
}

.journal-input-block + .journal-input-block {
  border-left: 1px solid var(--border);
}

/* 縦の仕切り（不要になったが互換維持） */
.input-divider { display: none; }

.input-side-label {
  font-size: .8rem;
  font-weight: 800;
  letter-spacing: .05em;
  text-align: center;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.debit-label  { color: var(--debit-fg); }
.credit-label { color: var(--credit-fg); }

/* 1行 = 科目 + 金額 + × ボタン（横一列） */
.entry-input-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}

.account-select {
  flex: 1;
  min-width: 0;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  padding: 0 4px;
  -webkit-appearance: none;
  appearance: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.amount-input {
  flex-shrink: 0;
  width: 68px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  padding: 0 5px;
  text-align: right;
}

.btn-remove-row {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: none;
  color: var(--text-sub);
  font-size: .8rem;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}
.btn-remove-row:hover { background: var(--debit-bg); color: var(--debit-fg); }

.btn-add-row {
  display: block;
  width: 100%;
  font-size: .8rem;
  color: var(--accent);
  background: none;
  border: 1px dashed var(--border);
  border-radius: 6px;
  cursor: pointer;
  padding: 5px 0;
  margin-top: 2px;
  text-align: center;
}
.btn-add-row:hover { border-color: var(--accent); }

/* ── 正解/不正解バッジ ── */
.result-badge {
  display: inline-block;
  font-size: 1rem;
  font-weight: 800;
  padding: 6px 16px;
  border-radius: 20px;
  margin-bottom: 12px;
}
.badge-correct   { background: #eff6ff; color: #1d4ed8; }
.badge-incorrect { background: #fefce8; color: #854d0e; }
.badge-skip      { background: var(--bg); color: var(--text-sub); border: 1px solid var(--border); }

@media (prefers-color-scheme: dark) {
  .badge-correct   { background: #1e3a5f; color: #93c5fd; }
  .badge-incorrect { background: #2d1f00; color: #fcd34d; }
}

/* ── Answer section ── */
#answer-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 2px dashed var(--border);
  animation: fadeIn .2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.answer-label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-sub);
  margin-bottom: 10px;
}

/* ── Journal table ── */
.journal-wrapper { overflow-x: auto; }

.journal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}

.journal-table thead th {
  padding: 6px 10px;
  font-size: .75rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: .03em;
}

.journal-table thead th:nth-child(1),
.journal-table thead th:nth-child(2) {
  color: var(--debit-fg);
  background: var(--debit-bg);
}

.journal-table thead th:nth-child(3),
.journal-table thead th:nth-child(4) {
  color: var(--credit-fg);
  background: var(--credit-bg);
}

.journal-table tbody td {
  padding: 8px 10px;
  border-top: 1px solid var(--border);
}

td.debit-account, td.debit-amount {
  color: var(--debit-fg);
  background: var(--debit-bg);
}
td.debit-account { font-weight: 600; border-right: 1px solid var(--border); }
td.debit-amount  { text-align: right; padding-right: 12px; }

td.credit-account, td.credit-amount {
  color: var(--credit-fg);
  background: var(--credit-bg);
}
td.credit-account { font-weight: 600; padding-left: 16px; }
td.credit-amount  { text-align: right; padding-right: 12px; }

/* ── Explanation ── */
.explanation-box {
  background: var(--bg);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  padding: 12px 14px;
  margin-top: 14px;
  font-size: .875rem;
  line-height: 1.7;
  color: var(--text);
}

/* ── Footer ── */
/* ── 論点ページへの導線 ── */
.topics-link {
  margin: 12px 0 0;
  font-size: .9rem;
}
.topics-link a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

/* ── AIに質問 ── */
.ask-ai {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.ask-ai-label {
  font-size: .78rem;
  color: var(--text-sub);
  margin-bottom: 8px;
}
.ask-ai-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.ask-ai-btn {
  flex: 1 1 auto;
  min-width: 96px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--accent);
  font-size: .85rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
}
.ask-ai-btn:active { transform: scale(.97); }

/* ── 教材・講座（PR） ── */
.promo { margin-top: 20px; }
.promo-card {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}
.promo-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.promo-head .section-title { margin: 0; }
.promo-card .promo-head .section-title {
  font-size: .95rem;
  border-left: none;
  padding-left: 0;
}
.pr-tag {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .04em;
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid var(--text-sub);
  color: var(--text-sub);
}
.promo-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.promo-list a {
  display: block;
  padding: 11px 13px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
}
.promo-list a:active { transform: scale(.98); }
.promo-list .promo-banner a { padding: 8px; }
.promo-banner .promo-micro { margin-bottom: 6px; text-align: center; }
.promo-head-slim { justify-content: flex-end; }
.promo-head-slim + .promo-list { margin-top: 6px; }
.promo-card .promo-head + .promo-list { margin-top: 10px; }
.promo-banner img { display: block; max-width: 100%; height: auto; margin: 0 auto; }
.promo-pixel { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.promo-label {
  display: block;
  font-weight: 700;
  font-size: .9rem;
  color: var(--accent);
}
.promo-lead {
  display: block;
  font-size: .8rem;
  color: var(--text-sub);
  margin-top: 2px;
}
/* マイクロコピー＋ボタン */
.promo-btn-wrap { text-align: center; }
.promo-micro {
  font-size: .8rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 6px;
}
.promo-list a.promo-btn {
  display: block;
  padding: 13px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-weight: 700;
  font-size: .95rem;
  box-shadow: 0 2px 6px rgba(37, 99, 235, .25);
}

footer {
  text-align: center;
  padding: 24px 16px 16px;
  font-size: .75rem;
  color: var(--text-sub);
}
footer a { color: var(--text-sub); }
header .site-disclosure { margin: 8px 0 0; font-size: .875rem; color: var(--text); }
html[data-internal="1"] header::after {
  content: "計測除外中（内部アクセス）";
  display: block;
  margin-top: 6px;
  font-size: .72rem;
  color: #b45309;
}

/* ── Genre filter row ── */
.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px 0;
}

.btn-genre-filter {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: .875rem;
  cursor: pointer;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.btn-genre-filter.has-filter {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.genre-filter-arrow { font-size: .8rem; color: var(--text-sub); margin-left: 6px; }

.btn-weak-filter {
  flex-shrink: 0;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--debit-fg);
  background: var(--debit-bg);
  color: var(--debit-fg);
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn-weak-filter.active {
  background: var(--debit-fg);
  color: #fff;
}

/* ── Difficulty chips ── */
.difficulty-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px 0;
  flex-wrap: wrap;
}
.difficulty-label {
  font-size: .75rem;
  color: var(--text-sub);
  margin-right: 2px;
}
.diff-chip {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-sub);
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .12s, color .12s, border-color .12s;
}
.diff-chip.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

/* ── Genre sheet ── */
.genre-sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
}
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.45);
}
.sheet-panel {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: var(--card);
  border-radius: 16px 16px 0 0;
  max-height: 72vh;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
}

.genre-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.genre-item:active { background: var(--bg); }

.genre-checkbox {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  color: transparent;
}
.genre-item.checked .genre-checkbox {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.genre-item-name { flex: 1; font-size: .9rem; }
.genre-weak-badge {
  font-size: .72rem;
  font-weight: 700;
  color: var(--debit-fg);
  background: var(--debit-bg);
  padding: 2px 6px;
  border-radius: 10px;
}

/* ── 金額コピー ── */
.amt-copy {
  display: inline-block;
  background: var(--tag-bg);
  color: var(--tag-fg);
  border-radius: 4px;
  padding: 0 5px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.amt-copy:active { background: var(--accent); color: #fff; }

/* ── コピーヒント ── */
.copy-hint {
  font-size: .72rem;
  color: var(--text-sub);
  text-align: right;
  margin-top: 6px;
}

/* ── トースト ── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #1e293b;
  color: #fff;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: .85rem;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 100;
  white-space: nowrap;
}
.toast-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── あなたの解答テーブル ── */
.user-answer-table thead th {
  background: var(--bg);
  color: var(--text-sub);
}

/* ── 間違いノート FAB ── */
.history-fab {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  right: 16px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: .68rem;
  font-weight: 700;
  line-height: 1.3;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.history-fab:active { transform: scale(.94); }

.fab-badge {
  position: absolute;
  top: 0; right: 0;
  background: var(--debit-fg);
  color: #fff;
  font-size: .6rem;
  font-weight: 800;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid var(--bg);
}

/* ── 間違いノートパネル ── */
#history-panel {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 20;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}
.panel-title { font-size: 1rem; font-weight: 700; }

.btn-panel-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--text-sub);
  padding: 4px 8px;
  line-height: 1;
}

.history-empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-sub);
  font-size: .9rem;
}

.history-entry {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 10px 16px;
  font-size: .875rem;
}
.history-entry-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.result-badge-sm {
  font-size: .78rem;
  padding: 3px 10px;
  margin: 0;
}
.history-entry-q {
  font-weight: 500;
  line-height: 1.6;
  margin-bottom: 4px;
}
.history-entry-date {
  font-size: .75rem;
  color: var(--text-sub);
  margin-top: 4px;
}
.btn-practice {
  margin-top: 10px;
  font-size: .8rem;
  padding: 6px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.btn-practice:hover { background: var(--accent-h); }

/* ── 小画面: 借方・貸方を縦積み ── */
@media (max-width: 360px) {
  .journal-input-wrap { flex-direction: column; }
  .journal-input-block + .journal-input-block {
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

/* ── Utility ── */
[hidden] { display: none !important; }
