/* 起業経営ゲーム：スマホ縦画面（幅360〜430px）を基本にしたスタイル */

:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --ink: #1b1b1a;
  --ink-2: #52514e;
  --ink-3: #85847e;
  --line: #e2e0da;
  --accent: #2a78d6;
  --accent-soft: rgba(42, 120, 214, 0.12);
  --on-accent: #ffffff;
  --good: #1f8a4c;
  --warn: #a86400;
  --danger: #d03b3b;
  --danger-soft: rgba(208, 59, 59, 0.1);
  --warn-soft: rgba(168, 100, 0, 0.1);
  --good-soft: rgba(31, 138, 76, 0.1);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --bs-asset: #2a78d6;
  --bs-liab: #eb6834;
  --bs-equity: #1baf7a;
  --placeholder: #fbfaf8;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.04);
  --radius: 14px;
  --tabbar-h: 60px;
  --turnbar-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1c1c1b;
    --surface-2: #262624;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --ink-3: #8f8e86;
    --line: #34332f;
    --accent: #3987e5;
    --accent-soft: rgba(57, 135, 229, 0.18);
    --good: #3cb371;
    --warn: #e0a030;
    --danger: #e66767;
    --danger-soft: rgba(230, 103, 103, 0.15);
    --warn-soft: rgba(224, 160, 48, 0.14);
    --good-soft: rgba(60, 179, 113, 0.14);
    --series-1: #3987e5;
    --series-2: #d95926;
    --bs-asset: #3987e5;
    --bs-liab: #d95926;
    --bs-equity: #199e70;
    --placeholder: #222220;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1c1c1b;
  --surface-2: #262624;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --ink-3: #8f8e86;
  --line: #34332f;
  --accent: #3987e5;
  --accent-soft: rgba(57, 135, 229, 0.18);
  --good: #3cb371;
  --warn: #e0a030;
  --danger: #e66767;
  --danger-soft: rgba(230, 103, 103, 0.15);
  --warn-soft: rgba(224, 160, 48, 0.14);
  --good-soft: rgba(60, 179, 113, 0.14);
  --series-1: #3987e5;
  --series-2: #d95926;
  --bs-asset: #3987e5;
  --bs-liab: #d95926;
  --bs-equity: #199e70;
  --placeholder: #222220;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.3; }

.app {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 12px 16px calc(var(--tabbar-h) + var(--turnbar-h) + 24px + env(safe-area-inset-bottom));
}
.app.no-bars { padding-bottom: 32px; }
.boot { padding: 40vh 0; text-align: center; color: var(--ink-3); }

/* ---------- 共通部品 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 15px; margin-bottom: 8px; }
.card h3 { font-size: 14px; margin-bottom: 6px; }
.label { font-size: 12.5px; color: var(--ink-2); }
.muted { color: var(--ink-3); font-size: 12.5px; }
.big { font-size: 26px; font-weight: 700; letter-spacing: 0.01em; font-variant-numeric: tabular-nums; }
.mid { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; }
.neg { color: var(--danger); }
.pos { color: var(--good); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row + .row { margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 .card { margin-bottom: 0; }
.stack > * + * { margin-top: 8px; }
.section-title { font-size: 13px; color: var(--ink-2); font-weight: 600; margin: 18px 2px 8px; }
.topbar { display: flex; align-items: baseline; justify-content: space-between; margin: 4px 2px 12px; }
.topbar h1 { font-size: 19px; }
.topbar .status { font-size: 12.5px; color: var(--ink-2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 22px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 600;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13.5px; border-radius: 18px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }

.pills { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; scrollbar-width: none; }
.pill {
  flex: none; min-height: 36px; padding: 0 16px; border-radius: 18px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font-weight: 600; font-size: 14px;
}
.pill.on { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }

.chip { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 10px; background: var(--surface-2); color: var(--ink-2); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.good { background: var(--good-soft); color: var(--good); }

.alert { border-radius: 12px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 10px; display: flex; gap: 8px; }
.alert::before { font-weight: 700; flex: none; }
.alert.danger { background: var(--danger-soft); color: var(--danger); }
.alert.danger::before { content: "！"; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.warn::before { content: "！"; }
.alert.good { background: var(--good-soft); color: var(--good); }
.alert.good::before { content: "✓"; }
.alert.info { background: var(--surface-2); color: var(--ink-2); }
.alert.info::before { content: "i"; font-style: italic; }

/* 画像（未作成のうちは点線の枠のプレースホルダー） */
.pic {
  position: relative; flex: none; overflow: hidden;
  border: 1.5px dashed var(--line); border-radius: 10px; background: var(--placeholder);
  display: flex; align-items: center; justify-content: center; text-align: center;
  color: var(--ink-3); font-size: 11px; line-height: 1.3; padding: 4px;
}
.pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.pic.loaded { border-style: solid; border-color: transparent; background: none; }
.pic.s48 { width: 48px; height: 48px; }
.pic.s64 { width: 64px; height: 64px; }
.pic.s72 { width: 72px; height: 72px; }
.pic.s96 { width: 96px; height: 96px; }
.pic.wide { width: 100%; aspect-ratio: 16 / 9; }
.pic.hero { width: 100%; aspect-ratio: 4 / 3; }

/* 秘書のひとこと */
.secretary { display: flex; gap: 10px; align-items: flex-start; }
.bubble {
  position: relative; flex: 1; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px 12px; font-size: 14px; min-height: 64px;
}
.bubble::before {
  content: ""; position: absolute; left: -7px; top: 22px; width: 12px; height: 12px;
  background: var(--surface); border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); transform: rotate(45deg);
}
.bubble.trouble { border-color: var(--danger); }
.bubble.trouble::before { border-color: var(--danger); }

/* 年商の進み具合 */
.progress { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; margin: 8px 0 4px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 5px; }

/* 事業の画像の帯 */
.strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
.strip .item { flex: none; width: 76px; text-align: center; font-size: 11px; color: var(--ink-2); }
.strip .item .pic { margin: 0 auto 4px; }

/* 事業カード */
.biz { display: flex; gap: 12px; align-items: flex-start; }
.biz .body { flex: 1; min-width: 0; }
.biz .name { font-weight: 700; font-size: 15px; }
.biz .meta { font-size: 12.5px; color: var(--ink-2); }
.biz.locked { opacity: 0.7; }
.card.locked { border-style: dashed; box-shadow: none; }
.lock { font-size: 12px; color: var(--ink-3); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 13px; margin-top: 6px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* 表（PL・返済表） */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.table th:first-child, .table td:first-child { text-align: left; white-space: normal; }
.table thead th { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.table tr.sum td { font-weight: 700; }
.table tr.sub td:first-child { padding-left: 14px; color: var(--ink-2); }
.table tr.total td { font-weight: 700; border-top: 2px solid var(--ink-3); }
.scroll-y { max-height: 260px; overflow-y: auto; }

/* BS の左右の棒 */
.bs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
.bs .col { display: flex; flex-direction: column; gap: 2px; }
.bs .col-title { font-size: 12px; color: var(--ink-2); text-align: center; margin-bottom: 4px; }
.bs .seg {
  border-radius: 6px; padding: 4px 6px; font-size: 11.5px; color: #fff; overflow: hidden;
  display: flex; flex-direction: column; justify-content: center; min-height: 0; line-height: 1.25;
}
.bs .seg b { font-weight: 700; font-size: 12px; }
.bs .seg.asset { background: var(--bs-asset); }
.bs .seg.asset.alt { background: color-mix(in srgb, var(--bs-asset) 70%, var(--surface)); }
.bs .seg.liab { background: var(--bs-liab); }
.bs .seg.liab.alt { background: color-mix(in srgb, var(--bs-liab) 70%, var(--surface)); }
.bs .seg.equity { background: var(--bs-equity); }
.bs .seg.deficit {
  background: repeating-linear-gradient(45deg, var(--danger-soft), var(--danger-soft) 6px, transparent 6px, transparent 12px);
  border: 1.5px dashed var(--danger); color: var(--danger);
}
.bs .seg.tiny { padding: 0 6px; font-size: 0; }

/* 推移グラフ */
.chart-wrap { overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; }
.chart-wrap svg { display: block; }
.chart-wrap .bar { cursor: pointer; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); margin-bottom: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* フォーム */
.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 4px; }
.field input, .field select {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); font-variant-numeric: tabular-nums;
}
.seg-select { display: flex; gap: 6px; flex-wrap: wrap; }
.seg-select button {
  flex: 1; min-width: 56px; min-height: 40px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); font-size: 13.5px; color: var(--ink-2); font-weight: 600;
}
.seg-select button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.seg-select button:disabled { opacity: 0.4; }

/* 四半期を進めるバー＋下部タブ */
.turnbar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  z-index: 20; display: flex; justify-content: center; pointer-events: none;
}
.turnbar .inner {
  pointer-events: auto; width: 100%; max-width: 430px; padding: 6px 16px;
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(to bottom, transparent, var(--bg) 30%);
}
.turnbar .when { font-size: 12px; color: var(--ink-2); line-height: 1.3; flex: none; }
.turnbar .btn { flex: 1; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar .inner { max-width: 430px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); height: var(--tabbar-h); }
.tab {
  border: 0; background: none; color: var(--ink-3); font-size: 11px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.tab svg { width: 22px; height: 22px; }
.tab.on { color: var(--accent); }

/* 重ねて出す画面 */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.15s ease-out;
}
.sheet {
  width: 100%; max-width: 430px; max-height: 92dvh; overflow-y: auto;
  background: var(--bg); border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  animation: up 0.2s ease-out;
}
.sheet h2 { font-size: 18px; margin-bottom: 10px; }
.sheet .hero-title { text-align: center; font-size: 22px; margin: 12px 0 4px; }
.sheet .center { text-align: center; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); opacity: 0.6; } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--turnbar-h) + 20px); transform: translateX(-50%);
  max-width: 398px; width: calc(100% - 32px); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 12px; font-size: 13.5px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.toast.show { opacity: 0.95; }

/* 開始画面 */
.choice { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 10px; margin-bottom: 8px; }
.choice.on { border-color: var(--accent); background: var(--accent-soft); }
.chara-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.chara-row .choice { flex-direction: column; text-align: center; padding: 8px; margin: 0; }
.chara-row .pic { width: 100%; aspect-ratio: 3 / 4; height: auto; }
.steps { font-size: 12px; color: var(--ink-3); margin-bottom: 10px; }
.steps b { color: var(--accent); }

/* ホームの会社の見た目 */
.pic.office { aspect-ratio: 16 / 7; border: 0; border-radius: 0; }
