/* デザイントークン：資料作成キットのテーマD（緑＋黄）の役割分担を踏襲し、地色をコズミックラテにしたもの */
:root {
  /* ライト面 */
  --bg: #FFF8E7;            /* 地（コズミックラテ） */
  --surface: #FFFFFF;       /* カード・パネル面 */
  --surface-2: #FBF2DC;     /* 一段沈んだ面 */
  --ink: #232323;           /* 主テキスト */
  --sub: #5C594F;           /* 副テキスト */
  --dim: #8A8474;           /* 補助ラベルのみ（本文には使わない） */
  --line: #E6DCC4;          /* 罫線 */

  /* アクセント */
  --accent: #1E8A3C;        /* 面・図形（発電中） */
  --accent-deep: #14682C;   /* 文字用・白文字を載せる塗り */
  --accent-tint: #E3EFE4;   /* 淡い面 */
  --spark: #FFD84D;         /* 太陽・売電額のマーカー（面専用） */

  /* 状態色 */
  --danger: #D9342B;
  --danger-deep: #B3261E;
  --danger-tint: #FBE3DF;
  --fire: #F07C1E;
  --repair: #8A6A2E;
  --dc: #3A7BD5;
  --ac: #E8A317;

  --radius: 6px;
  --shadow: 0 1px 2px rgba(60, 50, 20, 0.06), 0 4px 14px rgba(60, 50, 20, 0.06);
  --font: "Yu Gothic UI", "Yu Gothic", "YuGothic", "Meiryo", system-ui, sans-serif;
  --font-num: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: Consolas, "Cascadia Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
}

button { font-family: inherit; color: inherit; }

kbd {
  display: inline-block;
  padding: 0 7px;
  margin: 0 2px;
  border: 1px solid var(--line);
  border-bottom-width: 3px;
  border-radius: 5px;
  background: var(--surface);
  font-family: var(--mono);
  font-size: 0.85em;
  color: var(--ink);
}

#app { position: relative; height: 100vh; }
.screen { display: none; height: 100%; }
.screen.active { display: flex; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.logo {
  margin: 0;
  font-size: clamp(28px, 3.4vw, 46px);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.04em;
}
.logo span {
  color: var(--accent-deep);
  font-size: 1.12em;
  background: linear-gradient(transparent 62%, var(--spark) 62%);
}

.mascot-img { display: block; user-select: none; -webkit-user-drag: none; filter: drop-shadow(0 8px 12px rgba(60, 50, 20, 0.18)); }

.bubble {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  font-weight: 700;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-line;
}

.marker { background: linear-gradient(transparent 58%, var(--spark) 58%); padding: 0 2px; }

/* ---- モバイル案内 ---- */
#screen-mobile { align-items: center; justify-content: center; padding: 20px; }
.mobile-card { text-align: center; max-width: 420px; line-height: 1.8; }
.mobile-card .mascot-img { width: 60%; margin: 0 auto 8px; }
.mobile-card .logo { font-size: 26px; margin-bottom: 12px; }

/* ---- タイトル ---- */
#screen-title { align-items: center; justify-content: center; padding: 24px; overflow-y: auto; }
.title-layout { display: flex; align-items: center; gap: 32px; max-width: 1180px; width: 100%; margin: auto; }
.title-hero { flex: 0 0 32%; }
.title-hero .mascot-img { width: 100%; max-width: 400px; margin: 0 auto; }
.title-main { flex: 1; }
.eyebrow { margin: 0 0 6px; color: var(--accent-deep); font-weight: 700; font-size: 14px; letter-spacing: 0.1em; }
.lead { color: var(--sub); font-size: 16px; line-height: 1.8; margin: 14px 0 22px; }

.course-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.course-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  padding: 18px 16px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent);
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
}
.course-card:hover { transform: translateY(-3px); box-shadow: 0 8px 22px rgba(60, 50, 20, 0.12); }
.course-key {
  position: absolute; top: -13px; right: 12px;
  background: var(--accent-deep); color: #fff;
  font-weight: 700; font-family: var(--mono);
  border-radius: 4px; padding: 0 8px;
}
.course-name { font-size: 20px; font-weight: 700; }
.course-plant { font-size: 12px; color: var(--accent-deep); font-weight: 700; }
.course-desc { font-size: 13px; color: var(--sub); line-height: 1.5; }
.course-best { font-size: 12px; color: var(--sub); margin-top: 4px; padding-top: 6px; border-top: 1px dashed var(--line); }

.title-help { margin-top: 16px; font-size: 14px; color: var(--sub); }
.title-help p { margin: 6px 0; }
.ime-note { color: var(--danger-deep); }

/* あそびかた：FAQのように下へなめらかに開く */
.accordion { margin-top: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.accordion-head {
  width: 100%;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  background: none; border: 0; cursor: pointer;
  font-size: 15px; font-weight: 700; text-align: left;
}
.chevron {
  width: 10px; height: 10px;
  border-right: 2px solid var(--sub); border-bottom: 2px solid var(--sub);
  transform: rotate(45deg); transition: transform 0.3s ease; margin-right: 4px;
}
.accordion.open .chevron { transform: rotate(-135deg); }
.accordion-body { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.35s ease; }
.accordion.open .accordion-body { grid-template-rows: 1fr; }
.accordion-inner { overflow: hidden; }
.accordion-inner ul { margin: 0; padding: 0 20px 14px 34px; line-height: 1.8; font-size: 14px; color: var(--sub); }
.accordion-inner strong { color: var(--ink); }

/* ---- プレイ画面 ---- */
#screen-play { flex-direction: column; padding: 12px 16px; gap: 10px; position: relative; }

.hud {
  display: grid;
  grid-template-columns: 1.1fr 2fr 1fr 1.25fr 0.9fr 0.8fr auto;
  gap: 14px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 14px;
}
.hud-label { font-size: 12px; color: var(--sub); white-space: nowrap; }
.hud-date { font-size: 16px; font-weight: 700; white-space: nowrap; }
.hud-value { font-family: var(--font-num); font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hud-small { font-size: 12px; color: var(--sub); font-variant-numeric: tabular-nums; }
.hud-value.loss { color: var(--danger-deep); }
.hud-value.strikes span { color: var(--line); margin-right: 3px; }
.hud-value.strikes span.on { color: var(--danger); }
.hud-money .hud-value { font-size: 24px; }
.bump { display: inline-block; animation: bump 0.35s ease-out; }
@keyframes bump { 40% { transform: scale(1.15); } }

.curve-legend { margin-left: 6px; }
.curve-legend i { display: inline-block; width: 14px; height: 0; margin: 0 3px 3px 6px; vertical-align: middle; }
.curve-legend .plan { border-top: 2px dashed var(--dim); }
.curve-legend .actual { height: 8px; background: var(--spark); border: 1px solid var(--ac); }
.curve { display: block; width: 100%; height: 44px; background: var(--surface-2); border-radius: 4px; }
.curve-plan { fill: none; stroke: var(--dim); stroke-width: 1.5; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }
.curve-actual { fill: rgba(255, 216, 77, 0.75); stroke: var(--ac); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.curve-now { stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.curve-times { display: flex; justify-content: space-between; font-size: 11px; color: var(--dim); }
.curve-times #hud-time { color: var(--ink); font-weight: 700; font-size: 12px; }

.icon-btn {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius); font-size: 20px; width: 42px; height: 42px; cursor: pointer;
}

.play-main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(380px, 1fr);
  gap: 12px;
}

/* ---- 発電所マップ ---- */
.plant { position: relative; padding: 8px; min-height: 0; display: flex; align-items: center; }
.plant-svg { width: 100%; height: 100%; display: block; font-family: var(--font); }
.plant-svg text { dominant-baseline: middle; }

.ground rect { fill: #EEF3E3; stroke: none; }
/* 区画バッジ：緑＝発電中／赤＝停止・対応中／茶＝修理中 */
.row-badge { fill: var(--accent); transition: fill 0.2s; }
.row-letter { font-size: 15px; font-weight: 700; fill: #fff; text-anchor: middle; font-family: var(--font-num); }
.row.stopped .row-badge, .row.targeted .row-badge { fill: var(--danger); }
.row.targeted .row-badge { stroke: var(--danger-deep); stroke-width: 4; stroke-opacity: 0.35; }
.row.repair .row-badge { fill: var(--repair); }
.pv { fill: #2F5FA8; stroke: #1D3F78; stroke-width: 1; transition: fill 0.3s; }
.row.running .pv { fill: #3567B5; }

.line { fill: none; stroke-width: 4; stroke-linecap: round; transition: stroke 0.3s; }
.line.dc { stroke: var(--dc); }
.line.ac { stroke: var(--ac); }
.row.running .line { stroke-dasharray: 10 6; animation: flow 0.9s linear infinite; opacity: var(--flow, 1); }
.row:not(.running) .line { stroke: #CFC8B6; }
.bus { stroke-width: 5; }
@keyframes flow { to { stroke-dashoffset: -16; } }

.box rect { fill: var(--surface); stroke: #9C9480; stroke-width: 1.5; transition: fill 0.2s, stroke 0.2s; }
.box .label { font-size: 13px; font-weight: 700; fill: var(--ink); text-anchor: middle; }
.box .label-sub { font-size: 10px; fill: var(--sub); text-anchor: middle; }
.grid-box rect { fill: var(--accent-tint); stroke: var(--accent); }
.divider { stroke: var(--line); stroke-dasharray: 4 4; }
.legend { font-size: 12px; fill: var(--sub); }
.lg-dc { fill: var(--dc); }
.lg-ac { fill: var(--ac); }

.row:not(.running) .pv { fill: #8C97AA; stroke: #6E7889; }

/* 機器の状態：異常 → 煙 → 炎 → 焼損 */
.fx { display: none; font-size: 22px; text-anchor: middle; pointer-events: none; }
.comp.alert rect, .comp.smoke rect, .comp.fire rect { stroke: var(--danger); stroke-width: 3; fill: var(--danger-tint); }
.comp.alert { animation: alert 1s ease-in-out infinite; }
.comp.smoke .fx-smoke { display: block; animation: smoke 1.2s ease-out infinite; }
.comp.fire rect { fill: #FFD9C2; stroke: var(--fire); }
.comp.fire .fx-fire { display: block; font-size: 28px; animation: flame 0.4s ease-in-out infinite alternate; }
.comp.burnt rect { fill: #4A4038; stroke: #2A241F; }
.comp.burnt .label, .comp.burnt .label-sub { fill: #F3E9D6; }
.comp.burnt .fx-wrench { display: block; }
.modules.alert .pv, .modules.smoke .pv, .modules.fire .pv { fill: #E9A49B; stroke: var(--danger); }
.modules.burnt .pv { fill: #4A4038; }
.ground.alert rect, .ground.smoke rect, .ground.fire rect { fill: var(--danger-tint); stroke: var(--danger); stroke-width: 3; }
.ground.burnt rect { fill: #CDBFA6; }
.wire.alert .line, .wire.smoke .line, .wire.fire .line { stroke: var(--danger) !important; stroke-width: 6; animation: none; }
.wire.burnt .line { stroke: #4A4038 !important; }
@keyframes alert { 50% { opacity: 0.55; } }
@keyframes smoke { from { opacity: 0.9; transform: translateY(4px); } to { opacity: 0; transform: translateY(-14px); } }
@keyframes flame { from { transform: scale(0.9); } to { transform: scale(1.12); } }
.fx { transform-box: fill-box; transform-origin: center; }

/* 復旧ポップ */
.popups { position: absolute; inset: 8px; pointer-events: none; }
.popup {
  position: absolute;
  transform: translate(-50%, -50%);
  text-align: center;
  animation: popup 1.6s ease-out forwards;
  white-space: nowrap;
}
.pop-kw { font-weight: 700; font-size: 15px; color: var(--accent-deep); background: var(--accent-tint); border: 1px solid var(--accent); border-radius: 20px; padding: 2px 12px; }
.pop-yen { margin-top: 4px; font-family: var(--font-num); font-weight: 700; font-size: 18px; }
.pop-yen::before { content: ""; }
@keyframes popup {
  0% { opacity: 0; transform: translate(-50%, -30%); }
  15% { opacity: 1; transform: translate(-50%, -60%); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -110%); }
}

/* ---- 入力コンソール ---- */
.console { position: relative; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.target {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 16px 22px;
  border-top: 4px solid var(--danger);
  min-height: 0;
}
.target.miss { animation: miss 0.18s; }
@keyframes miss {
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.target-head { display: flex; gap: 10px; align-items: center; font-size: 13px; flex-wrap: wrap; justify-content: center; }
.target-kind { color: var(--danger-deep); font-weight: 700; }
.chip { background: var(--danger-deep); color: #fff; font-weight: 700; border-radius: 4px; padding: 1px 10px; }
.target-queue { color: var(--sub); }
.target-timer { width: 80%; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.target-timer-bar { height: 100%; background: var(--accent); transition: background 0.2s; }
.target-timer-bar.danger { background: var(--danger); }
.target-text { font-size: clamp(28px, 3.3vw, 48px); font-weight: 700; letter-spacing: 0.04em; line-height: 1.2; }
.target-kana { font-size: 16px; color: var(--sub); letter-spacing: 0.08em; }
.target-romaji { font-family: var(--mono); font-size: clamp(22px, 2.2vw, 30px); letter-spacing: 0.05em; word-break: break-all; }
.target-romaji .typed { color: var(--accent-deep); font-weight: 700; }
.target-romaji .rest { color: var(--dim); }
.target-desc {
  margin: 6px 0 0;
  max-width: 34em;
  font-size: 13px;
  line-height: 1.6;
  color: var(--sub);
  border-top: 1px dashed var(--line);
  padding-top: 8px;
}
.target-desc::before { content: "📘 "; }

.target.idle { border-top-color: var(--accent); color: var(--sub); font-size: 17px; }
.idle-icon { font-size: 48px; color: var(--ac); }

.buddy { display: flex; align-items: center; gap: 10px; height: 96px; flex-shrink: 0; }
.buddy .mascot-img { height: 100%; width: auto; }
.buddy .bubble { flex: 1; }
.buddy .bubble::before {
  content: ""; position: absolute; left: -8px; top: 50%; transform: translateY(-50%) rotate(45deg);
  width: 12px; height: 12px; background: var(--surface); border-left: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.combo { min-width: 92px; text-align: center; font-size: 18px; font-weight: 700; color: var(--accent-deep); }

.mascot-idle { animation: bob 2.4s ease-in-out infinite; }
.mascot-img.jump { animation: jump 0.45s ease-out; }
.mascot-img.shake { animation: shake 0.5s; }
.mascot-img.panic { animation: panic 0.35s infinite; }
@keyframes bob { 50% { transform: translateY(-5px); } }
@keyframes jump { 40% { transform: translateY(-16px) scale(1.06); } }
@keyframes shake {
  20% { transform: translateX(-8px) rotate(-4deg); }
  40% { transform: translateX(8px) rotate(4deg); }
  60% { transform: translateX(-6px) rotate(-3deg); }
  80% { transform: translateX(6px) rotate(3deg); }
}
@keyframes panic {
  25% { transform: translateX(-3px) rotate(-2deg); }
  75% { transform: translateX(3px) rotate(2deg); }
}

.ime-warning {
  display: none;
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  background: var(--danger-deep); color: #fff;
  padding: 8px 16px; border-radius: var(--radius); font-weight: 700; font-size: 14px; white-space: nowrap;
}
.ime-warning.show { display: block; }

/* 処置した用語のログ */
.knowledge { display: flex; gap: 14px; align-items: flex-start; height: 78px; padding: 8px 14px; overflow: hidden; }
.knowledge-title { font-size: 12px; color: var(--sub); white-space: nowrap; padding-top: 2px; }
.knowledge ul { list-style: none; margin: 0; padding: 0; flex: 1; font-size: 13px; line-height: 1.6; min-width: 0; }
.knowledge li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--sub); }
.knowledge li:first-child { color: var(--ink); animation: fadein 0.4s; }
.knowledge li:nth-child(3) { opacity: 0.6; }
.knowledge li strong { color: var(--accent-deep); margin-right: 8px; }
@keyframes fadein { from { opacity: 0; transform: translateY(-4px); } }

/* オーバーレイ */
.overlay {
  display: none;
  position: absolute; inset: 0;
  background: rgba(255, 248, 231, 0.82);
  backdrop-filter: blur(2px);
  align-items: center; justify-content: center;
  z-index: 10;
}
.overlay.show { display: flex; }
.intro-card { text-align: center; padding: 28px 44px; min-width: 420px; border-top: 4px solid var(--accent); }
.intro-date { font-size: 32px; font-weight: 700; margin-bottom: 10px; }
.intro-tip { color: var(--accent-deep); font-size: 16px; font-weight: 700; margin-bottom: 14px; }
.intro-go { color: var(--sub); font-size: 14px; }

/* ---- 精算・投資・ゲームオーバー ---- */
#screen-day, #screen-over { align-items: center; justify-content: center; padding: 20px; }
.day-layout, .over-layout { display: grid; grid-template-columns: 1fr 1.2fr; gap: 16px; width: 100%; max-width: 1180px; max-height: 100%; }
.day-summary, .shop, .over-summary, .over-words { padding: 20px 24px; }
.day-summary h2, .shop h2, .over-summary h2, .over-words h2 { margin: 0 0 12px; font-size: 21px; }
.rank-row { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
.rank { font-family: var(--font-num); font-size: 60px; font-weight: 800; line-height: 1; width: 76px; text-align: center; }
.rank-S { color: var(--accent-deep); background: linear-gradient(transparent 60%, var(--spark) 60%); }
.rank-A { color: var(--accent-deep); }
.rank-B { color: var(--sub); }
.rank-C { color: var(--danger-deep); }
.rank-caption { color: var(--sub); }
.rank-caption strong { color: var(--ink); font-size: 22px; margin-left: 6px; font-family: var(--font-num); }
.day-curve { height: 56px; margin-bottom: 8px; }

.money-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.money-table th { text-align: left; font-weight: 400; color: var(--sub); padding: 5px 0; }
.money-table td { text-align: right; font-weight: 700; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.money-table tr.total th, .money-table tr.total td { color: var(--ink); font-size: 17px; border-top: 1px solid var(--line); padding-top: 8px; }
.money-table tr.loss td { color: var(--danger-deep); }

.day-mascot { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.day-mascot .mascot-img { width: 96px; }
.day-mascot .bubble { flex: 1; }

.cash { float: right; font-size: 14px; font-weight: 400; color: var(--sub); }
.cash strong { color: var(--ink); font-size: 20px; margin-left: 6px; font-family: var(--font-num); }
.shop-help { margin: 0 0 10px; font-size: 13px; color: var(--sub); }
.shop-list { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.shop-item {
  display: flex; align-items: center; gap: 12px;
  padding: 7px 12px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  cursor: pointer; transition: border-color 0.12s, background 0.12s;
}
.shop-item:hover { border-color: var(--accent); background: var(--accent-tint); }
.shop-item.poor { opacity: 0.5; }
.shop-item.maxed { opacity: 0.45; cursor: default; }
.shop-key { font-family: var(--mono); font-weight: 700; background: var(--accent-deep); color: #fff; border-radius: 4px; padding: 0 8px; }
.shop-body { flex: 1; }
.shop-name { font-weight: 700; }
.shop-name .lv { color: var(--accent-deep); font-size: 13px; margin-left: 6px; }
.shop-effect { font-size: 13px; color: var(--accent-deep); }
.shop-note { font-size: 12px; color: var(--sub); }
.shop-cost { font-weight: 700; font-family: var(--font-num); font-variant-numeric: tabular-nums; white-space: nowrap; }

.day-buttons, .over-buttons { display: flex; gap: 10px; }
.primary-btn, .secondary-btn {
  border: 0; border-radius: var(--radius); padding: 12px 20px; font-size: 15px; font-weight: 700; cursor: pointer;
}
.primary-btn { background: var(--accent-deep); color: #fff; flex: 1.3; }
.primary-btn:hover { background: #0F5222; }
.secondary-btn { background: var(--surface); border: 1px solid var(--line); flex: 1; }
.secondary-btn:hover { background: var(--surface-2); }

.over-summary h2 { color: var(--danger-deep); }
.over-summary h2.retired { color: var(--accent-deep); }
.over-title { font-size: 17px; margin-bottom: 10px; }
.over-title strong { font-size: 24px; background: linear-gradient(transparent 60%, var(--spark) 60%); }
.over-best { margin: 10px 0 0; color: var(--accent-deep); font-weight: 700; }
.over-buttons { margin-top: 16px; }
.over-words { display: flex; flex-direction: column; min-height: 0; max-height: calc(100vh - 40px); }
.over-words .count { font-size: 14px; color: var(--sub); font-weight: 400; }
.word-list { list-style: none; margin: 0; padding: 0 6px 0 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.word-list li { background: var(--surface-2); border-radius: var(--radius); padding: 8px 12px; }
.word-list strong { color: var(--accent-deep); margin-right: 8px; }
.word-list .kana { font-size: 12px; color: var(--sub); }
.word-list p { margin: 4px 0 0; font-size: 13px; line-height: 1.6; color: var(--ink); }
.word-list .empty { color: var(--sub); }

/* ---- 画面の低いPC向け ---- */
@media (max-height: 760px) {
  .knowledge { height: 66px; font-size: 12px; }
  .hud-value { font-size: 18px; }
  .hud-money .hud-value { font-size: 20px; }
  .buddy { height: 80px; }
  .target-desc { font-size: 12px; }
}
