/* ============================================================
   日商簿記3級 最短合格ナビ - 電卓不要・思考式仕訳 スマホCSS
   ============================================================ */

:root {
  --primary: #1060ea;
  --primary-light: #e8f0fe;
  --primary-dark: #0a46b0;
  --success: #138844;
  --success-bg: #e6f4ea;
  --danger: #d93025;
  --danger-bg: #fce8e6;
  --warning: #f29900;
  
  --debit-color: #0b57d0;   /* 借方カラー（青系） */
  --credit-color: #b3261e;  /* 貸方カラー（赤系） */
  
  --bg-app: #f4f6f9;
  --bg-card: #ffffff;
  --text-main: #1f2328;
  --text-muted: #656d76;
  --border-color: #d0d7de;
  --border-focus: #1060ea;
  
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.14);
  
  --font-base: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'Roboto Mono', monospace;
  
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
  font-family: var(--font-base);
  background-color: #202124; /* PC閲覧時の背景 */
  color: var(--text-main);
  line-height: 1.5;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  overflow-x: hidden;
}

/* アプリ全体のスマホコンテナ */
.app-container {
  width: 100%;
  max-width: 440px;
  background-color: var(--bg-app);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 0 30px rgba(0,0,0,0.3);
  overflow: hidden;
}

/* ヘッダー */
.app-header {
  height: 50px;
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-badge {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
}

.question-progress {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.star-icon {
  fill: #c4c7c5;
  transition: fill 0.2s, transform 0.2s;
}

.icon-btn.active .star-icon {
  fill: #f9ab00;
  transform: scale(1.15);
}

/* プログレスバー */
.progress-bar-bg {
  width: 100%;
  height: 4px;
  background-color: #e0e2e5;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #1a73e8, #34a853);
  transition: width 0.3s ease;
}

/* 広告コンテナ */
.ad-container {
  display: flex;
  justify-content: center;
  padding: 4px 12px;
  background: #fdfdfd;
  border-bottom: 1px dashed #e1e4e8;
}

.ad-placeholder {
  text-align: center;
  width: 100%;
}

.ad-label {
  display: block;
  font-size: 9px;
  color: #9aa0a6;
  margin-bottom: 2px;
  text-transform: uppercase;
}

.ad-mock-banner {
  background: #f1f3f4;
  border: 1px dashed #c6c6c6;
  border-radius: 4px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #70757a;
}

.ad-mock-rect {
  background: #f8f9fa;
  border: 1px dashed #c0c4c8;
  border-radius: 6px;
  height: 250px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #5f6368;
  gap: 4px;
}

.ad-mock-rect p {
  font-weight: 700;
  font-size: 13px;
}

.ad-mock-rect span {
  font-size: 11px;
  color: #80868b;
}

/* メインスクロールエリア */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  padding-bottom: 85px; /* 下部固定バー分の余白 */
  -webkit-overflow-scrolling: touch;
}

/* ステップインジケーター */
.step-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
}

.step-tab {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  border-radius: 16px;
  background: #e2e8f0;
  color: #64748b;
  font-size: 12px;
  font-weight: 700;
  transition: all 0.2s;
}

.step-tab.active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(16, 96, 234, 0.25);
}

.step-num {
  font-size: 13px;
}

.step-arrow {
  font-size: 11px;
  color: #94a3b8;
}

/* 問題カード */
.question-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  border: 1px solid #e1e4e8;
  margin-bottom: 12px;
}

.question-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.category-tag {
  font-size: 11px;
  font-weight: 700;
  background: #eef3fc;
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 4px;
}

.diff-tag {
  font-size: 10px;
  color: #d97706;
  font-weight: 700;
}

.question-text {
  font-size: 13.5px;
  line-height: 1.6;
  font-weight: 500;
  color: #24292f;
  user-select: text;
}

/* ガイドボックス */
.step-guide-box {
  background: #eff6ff;
  border-left: 3px solid var(--primary);
  border-radius: 0 8px 8px 0;
  padding: 8px 12px;
  margin-bottom: 12px;
  font-size: 12px;
  color: #1e3a8a;
  line-height: 1.5;
}

.guide-badge {
  display: inline-block;
  background: var(--primary);
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  margin-bottom: 4px;
}

.guide-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.back-step-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
  padding: 2px 4px;
}

/* ============================================================
   STEP 1: 勘定科目スロット＆チップ
   ============================================================ */
.journal-slots-board {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow-sm);
  border: 1px solid #e1e4e8;
  margin-bottom: 12px;
}

.slots-header {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid #eaecef;
}

.debit-title { color: var(--debit-color); }
.credit-title { color: var(--credit-color); }

.slots-grid {
  display: flex;
  gap: 8px;
}

.slots-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.slots-divider {
  width: 1px;
  background: #e1e4e8;
}

.account-slot-cell {
  background: #f8fafc;
  border: 1.5px solid #cbd5e1;
  border-radius: 8px;
  padding: 10px 8px;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: all 0.15s;
}

.account-slot-cell.active {
  border-color: var(--border-focus);
  background: #eff6ff;
  box-shadow: 0 0 0 2px rgba(16, 96, 234, 0.2);
}

.account-slot-cell.active::after {
  content: '';
  position: absolute;
  top: -3px;
  right: -3px;
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
}

.account-slot-cell .slot-name {
  font-size: 13px;
  font-weight: 700;
  color: #0f172a;
}

.account-slot-cell.empty .slot-placeholder {
  font-size: 12px;
  color: #94a3b8;
  font-weight: 500;
}

.slot-clear-icon {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  background: #e2e8f0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #64748b;
  cursor: pointer;
}

/* チップパネル */
.chips-panel-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow-sm);
  border: 1px solid #e1e4e8;
}

.panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}

.panel-title {
  font-size: 12px;
  font-weight: 700;
  color: #334155;
}

.panel-sub {
  font-size: 10px;
  color: var(--text-muted);
}

.chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip-btn {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 20px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  color: #1e293b;
  cursor: pointer;
  transition: all 0.15s;
}

.chip-btn:active {
  transform: scale(0.95);
  background: #e2e8f0;
}

.chip-btn.selected-debit {
  background: #dbeafe;
  border-color: #93c5fd;
  color: #1d4ed8;
}

.chip-btn.selected-credit {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #b91c1c;
}

/* ============================================================
   STEP 2: 金額（計算式）ビルダー
   ============================================================ */
.amount-cards-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.amount-card {
  background: var(--bg-card);
  border: 1.5px solid #cbd5e1;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}

.amount-card.active {
  border-color: var(--border-focus);
  background: #eff6ff;
  box-shadow: 0 0 0 2px rgba(16, 96, 234, 0.2);
}

.amount-card.active::before {
  content: '▶ 入力中';
  position: absolute;
  top: 6px;
  right: 10px;
  font-size: 10px;
  font-weight: 700;
  color: var(--primary);
}

.amount-card-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.side-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
}

.side-badge.debit {
  background: #dbeafe;
  color: var(--debit-color);
}

.side-badge.credit {
  background: #fee2e2;
  color: var(--credit-color);
}

.card-account-name {
  font-size: 13px;
  font-weight: 700;
  color: #0f172a;
}

/* 式表示エリア */
.formula-display-area {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 6px 10px;
  min-height: 38px;
}

.formula-tokens {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: #1e293b;
}

.token-num {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid #cbd5e1;
}

.token-op {
  color: var(--primary);
  font-weight: 900;
  padding: 0 2px;
}

.formula-placeholder {
  font-size: 11px;
  color: #94a3b8;
  font-style: italic;
}

.eval-preview {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: #059669;
  white-space: nowrap;
}

/* 貸借合計ステータスバー */
.balance-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #f1f5f9;
  border-radius: 8px;
  font-size: 12px;
  font-family: var(--font-mono);
  font-weight: 600;
  margin-bottom: 12px;
}

.balance-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.balance-val { color: #334155; }
.balance-diff { color: #64748b; font-size: 11px; }

.balance-status.matched {
  background: #ecfdf5;
  color: #065f46;
}

.balance-status.matched .balance-diff {
  color: #059669;
  font-weight: 700;
}

.balance-status.mismatch .balance-diff {
  color: var(--danger);
  font-weight: 700;
}

/* 式パレットカード */
.formula-palette-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow-sm);
  border: 1px solid #e1e4e8;
}

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

.palette-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  background: #eff6ff;
  padding: 2px 8px;
  border-radius: 4px;
}

.palette-actions {
  display: flex;
  gap: 6px;
}

.palette-mini-btn {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  color: #475569;
  cursor: pointer;
}

.palette-mini-btn:active {
  background: #e2e8f0;
}

.chips-group-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.op-chip {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: var(--primary);
  font-size: 15px;
  font-weight: 900;
  min-width: 42px;
  text-align: center;
}

.num-chip {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
}

/* ============================================================
   固定下部アクションバー
   ============================================================ */
.bottom-action-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: #ffffff;
  border-top: 1px solid #d0d7de;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.08);
  padding: 10px 14px calc(10px + var(--safe-bottom)) 14px;
  z-index: 20;
}

.action-submit-btn {
  width: 100%;
  height: 48px;
  background: linear-gradient(135deg, #1060ea, #0a46b0);
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(16, 96, 234, 0.3);
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.action-submit-btn:active {
  transform: translateY(1px);
}

.action-submit-btn:disabled {
  background: #cbd5e1;
  color: #94a3b8;
  box-shadow: none;
  cursor: not-allowed;
}

/* ============================================================
   解説・判定ドロワー（ボトムシート）
   ============================================================ */
.explanation-drawer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 85vh;
  background: #ffffff;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 30px rgba(0,0,0,0.25);
  transform: translateY(105%);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 50;
  display: flex;
  flex-direction: column;
}

.explanation-drawer.open {
  transform: translateY(0);
}

.drawer-handle-bar {
  width: 100%;
  padding: 10px 0 4px 0;
  display: flex;
  justify-content: center;
  cursor: pointer;
}

.drawer-handle {
  width: 36px;
  height: 4px;
  background: #cbd5e1;
  border-radius: 2px;
}

.drawer-content {
  overflow-y: auto;
  padding: 12px 18px calc(24px + var(--safe-bottom)) 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* 判定バナー */
.judge-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
}

.judge-banner.correct {
  background: var(--success-bg);
  border: 1px solid #b7eb8f;
}

.judge-banner.wrong {
  background: var(--danger-bg);
  border: 1px solid #ffa39e;
}

.judge-icon {
  font-size: 32px;
  line-height: 1;
}

.judge-title {
  font-size: 18px;
  font-weight: 900;
}

.judge-banner.correct .judge-title { color: var(--success); }
.judge-banner.wrong .judge-title { color: var(--danger); }

.judge-subtitle {
  font-size: 12px;
  color: #4b5563;
  margin-top: 2px;
}

/* 模範解答テーブル */
.model-answer-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px;
}

.box-title {
  font-size: 13px;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 8px;
}

.model-answer-table {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  overflow: hidden;
  font-size: 12px;
}

.ans-row {
  display: flex;
  border-bottom: 1px solid #f1f5f9;
}

.ans-row:last-child {
  border-bottom: none;
}

.ans-side {
  flex: 1;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ans-debit {
  border-right: 1px solid #cbd5e1;
}

.ans-account-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.ans-account {
  font-weight: 700;
  color: #0f172a;
}

.ans-amount {
  font-family: var(--font-mono);
  font-weight: 700;
  color: #1e293b;
}

.ans-formula-line {
  font-size: 10px;
  color: var(--primary);
  font-family: var(--font-mono);
}

/* 解説ボックス */
.explanation-box {
  background: #f0f7ff;
  border: 1px solid #c8e1ff;
  border-radius: 10px;
  padding: 12px;
}

.explanation-body {
  font-size: 13px;
  line-height: 1.7;
  color: #1e293b;
  white-space: pre-line;
}

/* 勘定科目5要素サマリー */
.accounts-summary-box {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.acc-pill {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 12px;
  font-weight: 600;
}

.acc-pill.asset { background: #e0f2fe; color: #0369a1; }
.acc-pill.liability { background: #fef3c7; color: #b45309; }
.acc-pill.equity { background: #f3e8ff; color: #7e22ce; }
.acc-pill.expense { background: #fee2e2; color: #b91c1c; }
.acc-pill.revenue { background: #dcfce7; color: #15803d; }

/* ドロワー内アクション */
.drawer-actions {
  margin-top: 4px;
}

.next-btn {
  width: 100%;
  height: 48px;
  background: #1060ea;
  color: #ffffff;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(16, 96, 234, 0.25);
}

.next-btn:active {
  background: #0a46b0;
}

/* バックドロップ */
.drawer-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 40;
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================================
   リザルト画面
   ============================================================ */
.result-view {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.result-card {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 24px 18px;
  box-shadow: var(--shadow-sm);
  border: 1px solid #e1e4e8;
  text-align: center;
}

.result-main-title {
  font-size: 20px;
  font-weight: 900;
  color: var(--primary);
  margin-bottom: 4px;
}

.result-sub-title {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.result-score-box {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  margin-bottom: 10px;
}

.result-score-num {
  font-size: 48px;
  font-weight: 900;
  font-family: var(--font-mono);
  color: #0f172a;
  line-height: 1;
}

.result-score-total {
  font-size: 18px;
  font-weight: 700;
  color: #64748b;
}

.result-status-badge {
  display: inline-block;
  font-size: 14px;
  font-weight: 700;
  padding: 4px 14px;
  border-radius: 20px;
  margin-bottom: 24px;
}

.result-status-badge.pass {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.result-status-badge.fail {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.primary-action-btn {
  width: 100%;
  height: 48px;
  background: linear-gradient(135deg, #1060ea, #0a46b0);
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(16, 96, 234, 0.25);
}

.primary-action-btn:active {
  transform: translateY(1px);
}

.ad-result {
  border-radius: 12px;
  border: 1px solid #e1e4e8;
  padding: 12px;
}
