:root {
  --bg: #0f1720;
  --panel: #1b2733;
  --panel2: #16202b;
  --border: #2c3a48;
  --text: #d7e0ea;
  --muted: #8aa0b4;
  --accent: #36c2a8;
  --accent2: #4aa3ff;
  --term-bg: #0a0e14;
  --term-text: #c8f7c5;
  --ok: #2fbf71;
  --fail: #e5534b;
  --warn: #e3b341;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Yu Gothic UI", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.app-header h1 { font-size: 18px; margin: 0; letter-spacing: .5px; }
.header-right { display: flex; align-items: center; gap: 16px; }
.back-btn {
  background: #33485b; color: var(--text); font-weight: 600;
  padding: 7px 14px; font-size: 13px;
}
.progress-wrap { display: flex; flex-direction: column; gap: 4px; min-width: 160px; }
.progress-indicator { color: var(--accent); font-size: 12px; font-weight: 600; text-align: right; }
.progress-bar { width: 100%; height: 6px; background: #243240; border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .4s ease; }

/* ===== 目次カタログ ===== */
.catalog { flex: 1; overflow-y: auto; padding: 22px 28px 40px; }
.catalog-lead { color: var(--muted); font-size: 14px; line-height: 1.8; max-width: 820px; margin: 0 0 24px; }
.catalog-lead code { background: #233140; padding: 1px 6px; border-radius: 4px; color: var(--accent); }
.cat-section { margin-bottom: 30px; }
.cat-level { font-size: 16px; display: flex; align-items: center; gap: 10px; margin: 0 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.lvl-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.lvl-初級 { background: #2fbf71; }
.lvl-中級 { background: #4aa3ff; }
.lvl-上級 { background: #e3b341; }
.lvl-応用 { background: #e5534b; }
.lvl-練習 { background: #a06cff; }
.lvl-トラブル { background: #ff7a45; }
.practice-lead { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.lab-card.practice { border-color: #6b4fb0; background: linear-gradient(180deg, #1d1a2b, var(--panel)); }
.lab-card.practice .card-code { color: #b79bff; }
.card-random { color: #b79bff; font-size: 11px; font-weight: 700; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.lab-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; display: flex; flex-direction: column; gap: 10px;
  transition: transform .12s ease, border-color .12s ease;
}
.lab-card:not(.locked):hover { transform: translateY(-3px); border-color: var(--accent2); }
.lab-card.done { border-color: var(--ok); }
.lab-card.locked { opacity: .55; }
.card-top { display: flex; justify-content: space-between; align-items: center; }
.card-code { font-family: "Consolas", monospace; font-weight: 700; color: var(--accent2); font-size: 13px; letter-spacing: 1px; }
.card-done { color: var(--ok); font-size: 12px; font-weight: 700; }
.card-soon { color: var(--muted); font-size: 11px; border: 1px solid var(--border); padding: 1px 7px; border-radius: 12px; }
.card-title { font-size: 15px; font-weight: 700; line-height: 1.4; min-height: 42px; }
.card-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.stars { color: var(--warn); letter-spacing: 1px; }
.card-tags { display: flex; flex-wrap: wrap; gap: 6px; min-height: 22px; }
.tag { background: #233140; color: #9fc4dd; font-size: 11px; padding: 2px 8px; border-radius: 12px; }
.card-action button { width: 100%; }
.card-action button:disabled { cursor: default; opacity: .7; }

.layout {
  flex: 1; display: grid; grid-template-columns: minmax(480px, 1.15fr) minmax(0, 0.85fr);
  gap: 12px; padding: 12px; min-height: 0;
}
.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden; min-height: 0;
}
.panel.left { padding: 16px; overflow-y: auto; }
.panel.right { display: flex; flex-direction: column; }

/* シナリオ */
.lab-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lab-head h2 { font-size: 17px; margin: 6px 0; }
.lab-code {
  background: var(--accent2); color: #04203f; font-weight: 800;
  font-family: "Consolas", monospace; font-size: 13px; letter-spacing: 1px;
  padding: 3px 10px; border-radius: 6px;
}
.badge {
  background: var(--accent); color: #06251f; font-weight: 700;
  font-size: 12px; padding: 3px 9px; border-radius: 20px;
}
.done-badge {
  background: var(--ok); color: #05210f; font-weight: 700;
  font-size: 11px; padding: 2px 8px; border-radius: 20px; margin-left: auto;
}
.progress-indicator { color: var(--accent); font-size: 13px; font-weight: 600; }
.summary { color: var(--muted); font-size: 13px; line-height: 1.6; margin: 4px 0 12px; }

.topo-wrap {
  background: var(--panel2); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px; margin-bottom: 14px;
}
#topo { width: 100%; height: 130px; display: block; }
.topo-link { stroke: #5b7387; stroke-width: 2; }
.topo-box { fill: #233140; stroke: #3a4d60; stroke-width: 1.5; }
.topo-node.selectable { cursor: pointer; }
.topo-node.selectable:hover .topo-box { stroke: var(--accent2); }
.topo-node.active .topo-box { stroke: var(--accent); stroke-width: 2.5; fill: #1d3a36; }
.topo-label { fill: var(--text); font-size: 11px; font-weight: 600; }
.topo-iflabel { fill: var(--muted); font-size: 9px; }

details { margin-bottom: 10px; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; background: var(--panel2); }
details summary { cursor: pointer; font-weight: 600; font-size: 13px; }
.info-list { margin: 8px 0 4px; padding-left: 18px; font-size: 13px; line-height: 1.7; color: #c4d2df; }

/* 採点 */
.check-area { margin-top: 14px; }
.check-buttons { display: flex; gap: 8px; }
button {
  background: var(--accent); color: #06251f; border: none;
  padding: 9px 16px; border-radius: 7px; font-weight: 700; cursor: pointer; font-size: 14px;
}
button:hover { filter: brightness(1.08); }
button.secondary { background: #33485b; color: var(--text); }
.check-banner { margin: 12px 0 8px; font-weight: 700; font-size: 14px; min-height: 18px; }
.check-banner.ok { color: var(--ok); }
.check-banner.partial { color: var(--warn); }
#check-list { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.check-item { padding: 5px 8px; border-radius: 6px; margin-bottom: 4px; background: var(--panel2); }
.check-item.pass { color: var(--ok); }
.check-item.fail { color: #f0a59f; }
.check-mark { display: inline-block; width: 18px; font-weight: 700; }

/* ターミナル */
.term-titlebar {
  background: #11181f; padding: 8px 14px; font-size: 13px; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
#terminal {
  flex: 1; background: var(--term-bg); padding: 12px 14px;
  font-family: "Consolas", "SFMono-Regular", "Courier New", monospace;
  font-size: 13.5px; line-height: 1.45; color: var(--term-text);
  overflow-y: auto; cursor: text; min-height: 0;
}
.term-line { white-space: pre-wrap; word-break: break-word; }
.term-more { background: #1f2a36; color: #d7e0ea; display: inline-block; }
.term-inputline { display: flex; align-items: baseline; }
.term-prompt { white-space: pre; color: #7fe0ff; }
#term-input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--term-text); font-family: inherit; font-size: inherit;
  padding: 0 0 0 2px; caret-color: var(--term-text);
}

@media (max-width: 900px) {
  /* スマホ/タブレット縦: 高さ固定の2枠をやめ、ページ全体を自然にスクロールさせる。
     問題文パネルは内容に合わせて広がり、ターミナルはその下に十分な高さで置く。 */
  html, body { height: auto; min-height: 100%; }
  .layout {
    display: block;          /* 2カラムグリッド→縦積み */
    flex: none; height: auto;
    padding: 10px;
  }
  .panel { margin-bottom: 12px; }
  .panel.left {
    overflow: visible;       /* 小さなスクロール枠ではなく内容ぶん広げる */
    padding: 14px;
  }
  .panel.right { min-height: 0; }
  #terminal { height: 60vh; flex: none; }  /* ターミナルは画面6割の高さを確保 */

  /* 端末で読みやすいよう本文を少し大きく */
  .summary { font-size: 14px; }
  .info-list { font-size: 14.5px; line-height: 1.75; }
  details summary { font-size: 14px; }
  .lab-head h2 { font-size: 18px; }
}
