/* ============================================================================
 * 簿記2級 問題集 PWA の画面スタイル。
 *
 * 解説レッスンの本文だけは docs/lesson-style.css(単一の出典)を iframe の中で使う。
 * こちらはアプリ側の外枠専用で、レッスン本文の見た目には一切関与しない。
 * 色の考え方は lesson-style.css に合わせてあるので、変えるときは両方見ること。
 * ========================================================================== */

:root {
  --fg: #1c1c1e;
  --bg: #f2f2f7;
  --card: #ffffff;
  --muted: #6b6b70;
  --accent: #0a84ff;
  --accent-fg: #ffffff;
  --rule: #d8d8dd;
  --ok: #34c759;
  --ng: #ff3b30;
  --warn: #ff9f0a;
  --skip: #8e8e93;
  --field: #ffffff;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #f2f2f7;
    --bg: #000000;
    --card: #1c1c1e;
    --muted: #98989f;
    --accent: #64d2ff;
    --accent-fg: #00121c;
    --rule: #38383c;
    --ok: #30d158;
    --ng: #ff453a;
    --warn: #ffd60a;
    --skip: #98989f;
    --field: #2c2c2e;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font: 17px/1.55 -apple-system, BlinkMacSystemFont, 'Hiragino Sans', sans-serif;
  color: var(--fg);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  /* ホーム画面から起動したときに引っぱって画面全体が動くのを防ぐ */
  overscroll-behavior-y: contain;
}

/* ---- 画面の骨格(固定ヘッダ + スクロールする本体) ---- */

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

header {
  flex: none;
  display: grid;
  /* 「スキップ」が入る幅を確保する(狭いと右端で切れる) */
  grid-template-columns: 80px 1fr 80px;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  padding-top: calc(6px + env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--rule);
}

header .title {
  text-align: center;
  min-width: 0;
}
header .title b {
  display: block;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
header .title small {
  display: block;
  font-size: 11px;
  color: var(--muted);
}

header button {
  background: none;
  border: 0;
  color: var(--accent);
  font-size: 15px;
  padding: 8px 4px;
  cursor: pointer;
  white-space: nowrap;
}
header button:disabled { visibility: hidden; }
header .right { text-align: right; }

main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
}

/* ---- 部品 ---- */

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin: 12px 0;
}

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 11px; }
.center { text-align: center; }
.bold { font-weight: 600; }
.pre { white-space: pre-wrap; }

button.btn {
  display: block;
  width: 100%;
  font: inherit;
  font-weight: 600;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--rule);
  background: var(--card);
  color: var(--accent);
  cursor: pointer;
  /* iOSのダブルタップ拡大とテキスト選択を抑える */
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
button.btn.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: transparent;
}
button.btn:disabled { opacity: 0.4; cursor: default; }
button.btn .sub {
  display: block;
  font-weight: 400;
  font-size: 12px;
  opacity: 0.75;
  margin-top: 2px;
}

.badge {
  display: inline-block;
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--ng);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}
.badge.tag { background: var(--accent); color: var(--accent-fg); }

/* モード切替(商業/工業) */
.segmented {
  display: flex;
  background: var(--rule);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}
.segmented button {
  flex: 1;
  font: inherit;
  font-size: 15px;
  padding: 7px 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  touch-action: manipulation;
}
.segmented button[aria-selected='true'] {
  background: var(--card);
  font-weight: 600;
}

/* 入力欄 */
input[type='text'], input[type='number'], textarea, select {
  font: inherit;
  color: var(--fg);
  background: var(--field);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 9px 10px;
  width: 100%;
  /* iOSは16px未満の入力欄にフォーカスすると自動でズームするため下回らせない */
  font-size: 16px;
}
textarea { resize: vertical; min-height: 96px; }
select { -webkit-appearance: none; appearance: none; padding-right: 26px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 12px center, right 7px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* 仕訳の1行(科目 + 金額 + 行削除) */
.jline { display: grid; grid-template-columns: 1fr 120px auto; gap: 6px; align-items: center; margin: 6px 0; }
.jline .icon-btn { border: 0; background: none; font-size: 20px; line-height: 1; color: var(--ng); padding: 4px; cursor: pointer; }
.jside { border: 1px solid var(--rule); border-radius: 10px; padding: 10px; margin: 8px 0; }
.jside > .spread { margin-bottom: 2px; }
.jside .add { border: 0; background: none; color: var(--accent); font-size: 22px; line-height: 1; padding: 2px 6px; cursor: pointer; }
.jside .add:disabled { opacity: 0.3; }

/* 金額欄 + 電卓ボタン */
.amount { display: grid; grid-template-columns: 1fr auto; gap: 4px; align-items: center; }
.amount .calc { border: 1px solid var(--rule); background: var(--card); border-radius: 8px; padding: 8px 10px; font-size: 15px; cursor: pointer; color: var(--fg); }

/* 問題文 */
.qtext { white-space: pre-wrap; }

/* 正誤の表示 */
.verdict { text-align: center; font-size: 28px; font-weight: 700; margin: 8px 0 4px; }
.verdict.ok { color: var(--ok); }
.verdict.ng { color: var(--ng); }
.verdict.skip { color: var(--skip); }
.mark { font-weight: 700; }
.mark.ok { color: var(--ok); }
.mark.ng { color: var(--ng); }
.mark.skip { color: var(--skip); }

/* 借方・貸方の対照表 */
table.jt { width: 100%; border-collapse: collapse; font-size: 15px; }
table.jt th { font-size: 11px; color: var(--muted); font-weight: 400; text-align: left; padding-bottom: 2px; }
table.jt td { padding: 2px 0; vertical-align: top; }
table.jt td + td, table.jt th + th { padding-left: 12px; }

/* 一覧 */
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.list button {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--rule);
  padding: 12px 14px;
  cursor: pointer;
}
.list button:last-child { border-bottom: 0; }

/* 難易度の星 */
.stars { color: var(--warn); font-size: 12px; letter-spacing: 1px; white-space: nowrap; }

/* 状態表示(読込中・エラー・空) */
.state { text-align: center; padding: 48px 16px; color: var(--muted); }
.state .big { font-size: 40px; display: block; margin-bottom: 8px; }

/* レッスン本文(iframe)。スクロールはiframe側に任せる */
.lesson-frame { flex: 1; width: 100%; border: 0; background: transparent; }

/* 電卓シート */
.sheet-bg {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  z-index: 10;
}
.sheet {
  width: 100%;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: 14px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  max-height: 92%;
  overflow-y: auto;
}
.calc-display {
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px 14px;
  min-height: 58px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.calc-display .value { font-size: 32px; font-weight: 600; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.calc-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.calc-keys button {
  font: inherit;
  font-size: 20px;
  padding: 14px 0;
  border-radius: 10px;
  border: 1px solid var(--rule);
  background: var(--card);
  color: var(--fg);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.calc-keys button.op { color: var(--warn); font-weight: 600; }
.calc-keys button.fn { color: var(--muted); }
.calc-keys button.wide { grid-column: span 2; }

/* 折りたたみ(大問の資料) */
details.ctx { background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin: 12px 0; }
details.ctx > summary { font-weight: 600; cursor: pointer; list-style: none; }
details.ctx > summary::-webkit-details-marker { display: none; }
details.ctx > summary::before { content: '▸ '; color: var(--muted); }
details.ctx[open] > summary::before { content: '▾ '; }
details.ctx .body { white-space: pre-wrap; margin-top: 10px; font-size: 15px; }

/* 送信状態 */
.sending { text-align: center; font-size: 14px; padding: 6px; }
.sending.ok { color: var(--ok); }
.sending.err { color: var(--warn); }

/* レッスン本文の画面。余白なしで領域いっぱいに使い、スクロールはiframe側に任せる */
main.flush { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
