:root {
  --bg: #11151d;
  --bg-2: #171d28;
  --panel: #202837;
  --panel-2: #273246;
  --text: #f2f5fb;
  --muted: #aeb8c9;
  --line: rgba(255, 255, 255, 0.12);
  --accent: #79d0ff;
  --target: #ff5a6a;
  --target-soft: rgba(255, 90, 106, 0.18);
  --protect: #52d48f;
  --protect-soft: rgba(82, 212, 143, 0.18);
  --warn: #ffd166;
  --bad: #ff6b6b;
  --good: #71e39b;
  --tile-size: 76px;
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(121, 208, 255, 0.13), transparent 32rem),
    linear-gradient(135deg, #0e1219 0%, #151b26 56%, #0f141d 100%);
  color: var(--text);
}

button {
  border: 0;
  color: var(--text);
  cursor: pointer;
  border-radius: 14px;
  font-weight: 700;
  transition: transform .12s ease, filter .12s ease, background .12s ease, border-color .12s ease;
}
button:hover { transform: translateY(-1px); filter: brightness(1.08); }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.primary {
  background: linear-gradient(135deg, #168eea, #6a5cff);
  padding: 12px 16px;
  box-shadow: 0 12px 24px rgba(35, 122, 255, 0.22);
}
.secondary {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  padding: 11px 14px;
}
.small { padding: 8px 12px; font-size: 13px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

#app { min-height: 100vh; padding: 20px; }

.topbar {
  max-width: 1320px;
  margin: 0 auto 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.topbar h1 { margin: 0; font-size: 26px; letter-spacing: .04em; }
.topbar h1 span { color: var(--accent); font-size: 16px; }
.topbar p { margin: 6px 0 0; color: var(--muted); }
.top-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.screen { max-width: 1320px; margin: 0 auto; }
.title-screen { display: grid; place-items: center; min-height: 68vh; }
.hero-card, .panel, .board-panel, .modal-card {
  background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.045));
  border: 1px solid var(--line);
  box-shadow: 0 24px 80px rgba(0,0,0,.28);
  border-radius: 28px;
}
.hero-card { width: min(860px, 100%); padding: 44px; }
.hero-card-public { width: min(1100px, 100%); display: grid; grid-template-columns: minmax(0, 1.15fr) 360px; gap: 28px; align-items: center; }
.hero-kicker, .modal-kicker, .mission-label { color: var(--accent); font-weight: 800; letter-spacing: .16em; font-size: 12px; }
.hero-card h2 { margin: 14px 0 14px; font-size: clamp(30px, 5vw, 54px); line-height: 1.15; }
.hero-card p { line-height: 1.9; color: var(--muted); font-size: 17px; }
.hero-buttons { display: flex; gap: 12px; margin-top: 26px; flex-wrap: wrap; }

.game-layout {
  display: grid;
  grid-template-columns: 300px minmax(540px, 1fr) 300px;
  gap: 16px;
  align-items: start;
}
.panel { padding: 18px; background-color: var(--panel); }
.left-panel, .right-panel { position: sticky; top: 16px; }
.wide-panel { padding: 24px; }
.panel-title-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.stage-header { border-bottom: 1px solid var(--line); padding-bottom: 14px; margin-bottom: 16px; }
.stage-number { color: var(--accent); font-weight: 800; font-size: 13px; letter-spacing: .12em; }
.stage-header h2 { margin: 5px 0 0; font-size: 23px; }

.mission-summary {
  background: rgba(0,0,0,.16);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  margin-bottom: 14px;
}
h3 { margin: 0 0 10px; font-size: 15px; }
.mission-summary p { margin: 0 0 12px; line-height: 1.7; color: #d8deeb; }
.legend-row { display: grid; grid-template-columns: 92px 1fr; gap: 8px; align-items: center; margin: 8px 0; color: var(--muted); font-size: 13px; }
.legend-badge { display: inline-flex; justify-content: center; align-items: center; padding: 4px 7px; border-radius: 999px; font-weight: 900; color: #fff; }
.legend-badge.target { background: var(--target-soft); border: 1px solid rgba(255,90,106,.6); }
.legend-badge.protect { background: var(--protect-soft); border: 1px solid rgba(82,212,143,.55); }
.rule-note { margin-top: 12px; padding: 10px; border-radius: 12px; background: rgba(255, 209, 102, .1); border: 1px solid rgba(255, 209, 102, .28); color: #ffe6a6; font-size: 12px; line-height: 1.55; }

.status-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.status-grid div { background: rgba(0,0,0,.18); border: 1px solid var(--line); border-radius: 14px; padding: 10px; }
.status-grid span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.status-grid strong { font-size: 17px; }

.tools-box { margin: 16px 0; }
.tool-buttons { display: grid; gap: 9px; }
.tool-button {
  text-align: left;
  padding: 12px;
  background: rgba(255,255,255,.06);
  border: 1px solid var(--line);
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  align-items: center;
}
.tool-button .tool-icon { font-size: 24px; }
.tool-button .tool-name { display: block; font-size: 14px; }
.tool-button .tool-short { display: block; font-weight: 500; color: var(--muted); font-size: 12px; margin-top: 2px; }
.tool-button.selected { outline: 2px solid var(--accent); background: rgba(121,208,255,.16); }
.tool-description { color: var(--muted); line-height: 1.65; min-height: 58px; font-size: 13px; }
.action-buttons { display: grid; gap: 9px; }
.action-buttons button { width: 100%; }
.action-buttons span { color: rgba(255,255,255,.75); font-size: 11px; margin-left: 4px; }

.board-panel { padding: 18px; background-color: var(--bg-2); min-height: 620px; }
.mission-card {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 12px;
  align-items: start;
  background: linear-gradient(135deg, rgba(255, 90, 106, .14), rgba(82, 212, 143, .1));
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 18px;
  padding: 14px;
  margin-bottom: 12px;
}
.mission-card p { margin: 4px 0 0; color: #d6deef; line-height: 1.55; }
.message-banner {
  min-height: 43px;
  border-radius: 15px;
  padding: 12px 14px;
  margin-bottom: 14px;
  background: rgba(121,208,255,.11);
  border: 1px solid rgba(121,208,255,.25);
  color: #dff4ff;
  line-height: 1.45;
}
.message-banner.warn { background: rgba(255,209,102,.12); border-color: rgba(255,209,102,.35); color: #ffe7a9; }
.message-banner.fail { background: rgba(255,90,106,.13); border-color: rgba(255,90,106,.38); color: #ffd2d8; }
.message-banner.success { background: rgba(82,212,143,.13); border-color: rgba(82,212,143,.38); color: #d5ffe8; }

.board {
  display: grid;
  gap: 7px;
  justify-content: center;
  padding: 16px;
  border-radius: 20px;
  background: rgba(0,0,0,.2);
  border: 1px solid var(--line);
  overflow-x: auto;
}
.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  position: relative;
  border-radius: 16px;
  border: 2px solid rgba(255,255,255,.12);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  user-select: none;
  overflow: hidden;
  isolation: isolate;
  box-shadow: inset 0 -10px 20px rgba(0,0,0,.18);
  transition: transform .12s ease, filter .12s ease, opacity .12s ease, border-color .12s ease;
}
.tile:hover { transform: translateY(-2px); filter: brightness(1.08); }
.tile.void { visibility: hidden; pointer-events: none; }
.tile.roof { background: linear-gradient(145deg, #677082, #3a4558); clip-path: polygon(50% 4%, 96% 42%, 88% 96%, 12% 96%, 4% 42%); }
.tile.wall { background: linear-gradient(145deg, #5e6878, #3d4658); }
.tile.column { background: linear-gradient(90deg, #343c4c 0 18%, #6c7788 18% 38%, #3e4858 38% 62%, #7b8594 62% 82%, #343c4c 82%); }
.tile.floor { background: linear-gradient(180deg, #6a5b48, #433729); }
.tile.foundation { background: repeating-linear-gradient(45deg, #3c3e45 0 8px, #2b3039 8px 16px); border-bottom-width: 5px; }
.tile .part-icon { font-size: 23px; line-height: 1; z-index: 2; }
.tile .part-name { font-size: 11px; font-weight: 800; margin-top: 4px; color: rgba(255,255,255,.88); z-index: 2; }
.tile .role-label {
  position: absolute;
  top: 5px;
  left: 5px;
  right: 5px;
  border-radius: 999px;
  padding: 2px 4px;
  text-align: center;
  font-size: 10px;
  font-weight: 900;
  z-index: 4;
  letter-spacing: .04em;
}
.tile.target { border-color: rgba(255,90,106,.95); box-shadow: 0 0 0 2px rgba(255,90,106,.28), 0 0 22px rgba(255,90,106,.18), inset 0 -10px 20px rgba(0,0,0,.18); }
.tile.target .role-label { background: rgba(255,90,106,.95); color: #fff; }
.tile.protect { border-color: rgba(82,212,143,.95); box-shadow: 0 0 0 2px rgba(82,212,143,.24), 0 0 22px rgba(82,212,143,.16), inset 0 -10px 20px rgba(0,0,0,.18); }
.tile.protect .role-label { background: rgba(82,212,143,.95); color: #061a10; }
.tile.protect.danger { animation: pulseProtect .65s ease-in-out infinite alternate; }
.tile.target::after, .tile.protect::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
.tile.target::after { background: radial-gradient(circle, rgba(255,90,106,.18), transparent 58%); }
.tile.protect::after { background: radial-gradient(circle, rgba(82,212,143,.15), transparent 58%); }
@keyframes pulseProtect { from { filter: brightness(1); } to { filter: brightness(1.28); } }

.tile.can-place { outline: 3px solid rgba(121,208,255,.85); outline-offset: 2px; cursor: pointer; box-shadow: 0 0 0 2px rgba(121,208,255,.25), inset 0 0 0 3px rgba(121,208,255,.42), 0 0 16px rgba(121,208,255,.35); filter: brightness(1.12); }
.tile.roof.can-place { filter: drop-shadow(0 0 9px rgba(121,208,255,.95)) brightness(1.18); }
.place-badge { position: absolute; right: 5px; top: 5px; z-index: 5; padding: 1px 5px; border-radius: 999px; border: 1px solid rgba(188,233,255,.95); background: rgba(20,92,130,.88); color: #eafaff; font-size: 10px; font-weight: 800; line-height: 1.4; letter-spacing: .03em; pointer-events: none; box-shadow: 0 2px 8px rgba(0,0,0,.28); }
.tile.roof .place-badge { top: 20px; right: 8px; }
.tile.unplaceable { opacity: .42; filter: grayscale(.3); }
.tile.unplaceable:hover { transform: none; }
.tile.broken { background: #151922 !important; border-color: rgba(255,255,255,.08) !important; clip-path: none; color: #7c8595; box-shadow: inset 0 0 22px rgba(0,0,0,.55); }
.tile.broken .part-icon::after { content: "💥"; }
.tile.damaged-low::before,
.tile.damaged-mid::before,
.tile.damaged-high::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
.tile.damaged-low::before { background: repeating-linear-gradient(120deg, transparent 0 10px, rgba(255,209,102,.14) 10px 12px); }
.tile.damaged-mid::before { background: repeating-linear-gradient(120deg, transparent 0 8px, rgba(255,147,86,.22) 8px 11px); }
.tile.damaged-high::before { background: repeating-linear-gradient(120deg, transparent 0 7px, rgba(255,90,106,.28) 7px 11px); }
.tile.just-damaged { animation: damageShake .22s linear; }
.tile.just-broken { animation: breakPop .34s ease-out; }
@keyframes damageShake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
@keyframes breakPop { 0% { transform: scale(1); } 55% { transform: scale(1.12) rotate(-2deg); } 100% { transform: scale(1); } }

.hp-bar { position: absolute; bottom: 5px; left: 8px; right: 8px; height: 6px; background: rgba(0,0,0,.34); border-radius: 999px; overflow: hidden; z-index: 5; }
.hp-fill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--bad), var(--warn), var(--good)); border-radius: inherit; }
.effect-stack { position: absolute; right: 5px; bottom: 14px; display: grid; gap: 1px; z-index: 6; }
.effect-dot { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: rgba(0,0,0,.36); font-size: 12px; }

.info-card { background: rgba(0,0,0,.16); border: 1px solid var(--line); border-radius: 18px; padding: 14px; margin-bottom: 12px; }
.info-card p { color: var(--muted); line-height: 1.65; margin: 0; }

.part-hint-list { display: grid; gap: 8px; }
.part-hint {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 8px;
  align-items: start;
  padding: 8px 9px;
  border-radius: 12px;
  background: rgba(255,255,255,.045);
  border: 1px solid rgba(255,255,255,.08);
  font-size: 12px;
}
.part-hint strong { color: #eef5ff; white-space: nowrap; }
.part-hint span { color: var(--muted); line-height: 1.45; }
.mini-note { margin-top: 10px !important; font-size: 11px; color: var(--muted); line-height: 1.55 !important; }

.tile-info dl { margin: 0; display: grid; grid-template-columns: 82px 1fr; gap: 6px 10px; font-size: 13px; }
.tile-info dt { color: var(--muted); }
.tile-info dd { margin: 0; color: #edf3ff; }
.tile-info .cannot { color: #ffd166; font-weight: 800; }
.tile-info .can { color: #9effc1; font-weight: 800; }
.log-card { max-height: 260px; display: flex; flex-direction: column; }
.log-list { overflow: auto; display: flex; flex-direction: column; gap: 7px; padding-right: 3px; }
.log-entry { font-size: 12px; line-height: 1.45; color: #d5ddec; background: rgba(255,255,255,.045); border-left: 3px solid rgba(121,208,255,.5); padding: 7px 8px; border-radius: 8px; }
.log-entry.warn { border-left-color: var(--warn); }
.log-entry.fail { border-left-color: var(--target); }
.log-entry.success { border-left-color: var(--protect); }

.stage-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin-top: 16px; }
.stage-card {
  text-align: left;
  padding: 16px;
  min-height: 134px;
  background: rgba(255,255,255,.055);
  border: 1px solid var(--line);
}
.stage-card strong { display: block; font-size: 17px; margin-bottom: 7px; }
.stage-card p { color: var(--muted); font-weight: 500; line-height: 1.45; margin: 0 0 10px; }
.stage-card .best { color: var(--accent); font-size: 12px; font-weight: 800; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.68);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: 22px;
  z-index: 99;
}
.modal-card { width: min(620px, 100%); padding: 28px; background-color: #202838; }
.modal-card h2 { margin: 10px 0 12px; font-size: 30px; }
.modal-card p { color: #d7deeb; line-height: 1.8; margin: 0; }
.modal-extra { margin-top: 16px; background: rgba(0,0,0,.2); border: 1px solid var(--line); border-radius: 16px; padding: 14px; color: var(--muted); line-height: 1.65; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

@media (max-width: 1160px) {
  .game-layout { grid-template-columns: 1fr; }
  .left-panel, .right-panel { position: static; }
  .board { justify-content: start; }
}
@media (max-width: 720px) {
  :root { --tile-size: 62px; }
  #app { padding: 12px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .hero-card { padding: 26px; }
  .mission-card { grid-template-columns: 1fr; }
}

/* v0.5 additions */
.objective-progress {
  margin: 10px 0 0;
  padding: 9px 10px;
  border-radius: 12px;
  background: rgba(121, 208, 255, .1);
  border: 1px solid rgba(121, 208, 255, .25);
  color: #dff4ff;
  font-size: 13px;
  font-weight: 800;
}
.tool-effectiveness {
  margin-top: 8px;
  padding: 9px 10px;
  border-radius: 12px;
  background: rgba(255,255,255,.055);
  border: 1px solid var(--line);
  color: #d8deeb;
  font-size: 12px;
  line-height: 1.55;
}
.stage-card.locked {
  opacity: .55;
  cursor: not-allowed;
  filter: grayscale(.3);
}
.stage-card.locked:hover {
  transform: none;
  filter: grayscale(.3);
}
.stage-card .stage-status {
  display: inline-flex;
  margin-left: 8px;
  color: #d7e6ff;
  font-size: 12px;
  font-weight: 800;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
}


/* v0.6 additions */
.muted-button { opacity: .68; }
.hero-rule-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
  margin: 22px 0 8px;
}
.hero-rule-grid div {
  background: rgba(0,0,0,.18);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  min-height: 82px;
}
.hero-rule-grid strong {
  display: inline-flex;
  width: 26px;
  height: 26px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(121,208,255,.18);
  color: var(--accent);
  margin-bottom: 8px;
}
.hero-rule-grid span { display: block; color: #dfe8f7; font-weight: 800; }
.hero-note { font-size: 14px !important; color: #c8d7ec !important; }

.result-success .modal-card {
  border-color: rgba(113, 227, 155, .55);
  box-shadow: 0 0 0 1px rgba(113,227,155,.12), 0 28px 90px rgba(27, 190, 99, .22);
}
.result-fail .modal-card {
  border-color: rgba(255, 90, 106, .55);
  box-shadow: 0 0 0 1px rgba(255,90,106,.12), 0 28px 90px rgba(255, 90, 106, .18);
}
.result-score {
  display: inline-grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-radius: 18px;
  background: rgba(113,227,155,.14);
  border: 1px solid rgba(113,227,155,.38);
  margin: 4px 0 10px;
}
.result-score span { color: var(--muted); font-weight: 700; }
.result-score strong { font-size: 42px; line-height: 1; color: #d8ffe7; }
.result-score.S strong { color: #ffe89a; }
.result-score.A strong { color: #d8ffe7; }
.result-breakdown {
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(0,0,0,.16);
  border: 1px solid var(--line);
}
.failure-reason, .failure-hint {
  display: grid;
  gap: 6px;
  margin: 8px 0;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255,90,106,.10);
  border: 1px solid rgba(255,90,106,.28);
}
.failure-hint {
  background: rgba(255,209,102,.10);
  border-color: rgba(255,209,102,.28);
}
.failure-reason strong, .failure-hint strong { color: #fff; }
.failure-reason span, .failure-hint span { color: #e8edf8; line-height: 1.7; }
.tutorial-steps {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}
.tutorial-steps div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(255,255,255,.06);
  border: 1px solid var(--line);
}
.tutorial-steps span { color: var(--muted); line-height: 1.55; }
body.flash-success::after,
body.flash-fail::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  animation: resultFlash .6s ease-out forwards;
}
body.flash-success::after { background: rgba(113,227,155,.18); }
body.flash-fail::after { background: rgba(255,90,106,.18); }
@keyframes resultFlash {
  from { opacity: 1; }
  to { opacity: 0; }
}
.board-shake { animation: boardShake .42s ease-in-out; }
@keyframes boardShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(4px); }
}
@media (max-width: 760px) {
  .hero-rule-grid { grid-template-columns: 1fr 1fr; }
}


/* v0.8 additions */
.stage-card-kicker {
  display: inline-flex;
  margin-bottom: 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .12em;
}
.stage-meta-row {
  display: grid;
  gap: 5px;
  margin: 10px 0;
  color: #dbe7f7;
  font-size: 12px;
  font-weight: 700;
}
.stage-card-footer {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
.stage-card.difficulty-3 { border-color: rgba(255, 209, 102, .24); }
.stage-card.difficulty-4 { border-color: rgba(255, 90, 106, .28); }
.detail-result {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}
.detail-result div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(255,255,255,.045);
}
.detail-result span { color: var(--muted); }
.detail-result strong { color: #edf4ff; text-align: right; }
.next-rank-advice {
  display: grid;
  gap: 5px;
  margin-top: 10px;
  padding: 11px 12px;
  border-radius: 14px;
  background: rgba(255, 209, 102, .1);
  border: 1px solid rgba(255, 209, 102, .25);
}
.next-rank-advice strong { color: #ffe6a6; }
.next-rank-advice span { color: #f2ead4; line-height: 1.55; }


/* v0.8.1 clear preview */
.clear-preview-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid rgba(82,212,143,.46);
  background: linear-gradient(135deg, rgba(82,212,143,.18), rgba(130,214,255,.10));
  border-radius: 16px;
  box-shadow: 0 12px 28px rgba(0,0,0,.22), 0 0 0 1px rgba(255,255,255,.03) inset;
  animation: clearPreviewIn .25s ease-out both;
}
.clear-preview-bar strong { color: #d8ffe7; display: block; margin-bottom: 2px; }
.clear-preview-bar span { color: var(--muted); font-size: 13px; }
.clear-preview-bar button { white-space: nowrap; }
@keyframes clearPreviewIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* v0.8 layout / public-play polish */
.stage-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}
.stage-chapter {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(0,0,0,.12);
  padding: 14px;
}
.chapter-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 14px;
  padding: 2px 4px 12px;
  border-bottom: 1px solid rgba(255,255,255,.09);
  margin-bottom: 12px;
}
.chapter-heading h3 { margin: 0; font-size: 18px; color: #f4f8ff; }
.chapter-heading p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; text-align: right; }
.chapter-stage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}
.settings-panel { display: grid; gap: 14px; margin-top: 10px; }
.settings-row {
  display: grid;
  grid-template-columns: 120px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.045);
}
.settings-row span { color: #e9f2ff; font-weight: 800; }
.settings-row input[type="range"] { width: 100%; accent-color: #79d0ff; }
.settings-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.danger-button {
  padding: 11px 14px;
  background: rgba(255,90,106,.18);
  border: 1px solid rgba(255,90,106,.42);
}
.result-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}
.top-actions button, .tool-button, .action-buttons button, .stage-card {
  touch-action: manipulation;
}
@media (max-width: 1180px) {
  .game-layout {
    grid-template-columns: 290px minmax(440px, 1fr);
  }
  .right-panel {
    grid-column: 1 / -1;
    position: static;
    display: grid;
    grid-template-columns: repeat(2, minmax(260px, 1fr));
    gap: 12px;
  }
  .log-card { grid-column: 1 / -1; }
}
@media (max-width: 900px) {
  :root { --tile-size: clamp(46px, 10.4vw, 66px); }
  .game-layout { grid-template-columns: 1fr; }
  .left-panel, .right-panel { position: static; }
  .right-panel { grid-template-columns: 1fr; }
  .board-panel { min-height: auto; overflow-x: auto; }
  .board { min-width: max-content; }
  .tool-buttons { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
  .action-buttons { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
  .chapter-heading { flex-direction: column; align-items: flex-start; }
  .chapter-heading p { text-align: left; }
}
@media (max-width: 560px) {
  #app { padding: 10px; }
  .topbar h1 { font-size: 22px; }
  .top-actions { width: 100%; display: grid; grid-template-columns: repeat(2, 1fr); }
  .hero-card, .panel, .board-panel, .modal-card { border-radius: 20px; }
  .hero-card { padding: 22px; }
  .hero-buttons, .settings-actions, .result-actions { display: grid; grid-template-columns: 1fr; }
  .clear-preview-bar { display: grid; grid-template-columns: 1fr; }
  .settings-row { grid-template-columns: 1fr; }
  .stage-card { min-height: auto; padding: 14px; }
  .tile .role-label { font-size: 9px; padding: 2px 5px; }
  .tile .part-name { font-size: 10px; }
  .place-badge { font-size: 9px; }
  .modal-card { padding: 22px; max-height: calc(100vh - 22px); overflow: auto; }
}


/* v0.9 public-release polish */
.hero-main-copy { min-width: 0; }
.hero-lead { font-size: 20px !important; color: #eef6ff !important; }
.game-description-card { display: grid; gap: 6px; margin: 18px 0 6px; padding: 14px 16px; border-radius: 18px; background: rgba(121,208,255,.10); border: 1px solid rgba(121,208,255,.24); }
.game-description-card strong { color: #e8f6ff; }
.game-description-card span { color: var(--muted); line-height: 1.65; }
.promo-thumbnail { position: relative; overflow: hidden; padding: 22px; border-radius: 26px; min-height: 430px; background: radial-gradient(circle at 78% 18%, rgba(255,90,106,.22), transparent 8rem), radial-gradient(circle at 18% 78%, rgba(82,212,143,.18), transparent 9rem), linear-gradient(160deg, rgba(21,27,39,.96), rgba(32,40,55,.92)); border: 1px solid rgba(255,255,255,.14); box-shadow: inset 0 0 0 1px rgba(255,255,255,.035), 0 22px 60px rgba(0,0,0,.22); }
.promo-thumbnail::after { content: ""; position: absolute; inset: auto -34px -48px auto; width: 180px; height: 180px; border-radius: 50%; background: rgba(121,208,255,.12); filter: blur(4px); }
.thumb-kicker { color: var(--accent); font-size: 12px; font-weight: 900; letter-spacing: .18em; }
.thumb-title { margin-top: 12px; font-size: 44px; font-weight: 900; letter-spacing: .06em; color: #f8fbff; }
.thumb-copy { margin-top: 8px; color: #d2ddeb; line-height: 1.55; font-weight: 700; }
.thumb-building { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(3, 76px); gap: 9px; justify-content: center; margin: 28px auto 24px; }
.thumb-tile { width: 76px; height: 58px; display: grid; place-items: center; border-radius: 16px; border: 1px solid rgba(255,255,255,.16); background: rgba(255,255,255,.08); font-weight: 900; font-size: 24px; box-shadow: inset 0 -10px 24px rgba(0,0,0,.12); }
.thumb-tile.roof { background: rgba(121,208,255,.18); clip-path: polygon(50% 6%, 94% 88%, 6% 88%); border-radius: 10px; }
.thumb-tile.wall { background: rgba(190,198,213,.14); }
.thumb-tile.column { background: rgba(151,167,190,.18); }
.thumb-tile.floor { background: rgba(255,209,102,.14); }
.thumb-tile.base { background: rgba(89,101,124,.32); }
.thumb-tile.target { outline: 3px solid rgba(255,90,106,.62); color: #ffdbe0; }
.thumb-tile.protect { outline: 3px solid rgba(82,212,143,.62); color: #d6ffe5; }
.thumb-tile.broken { background: rgba(255,90,106,.2); color: #ff9aa5; }
.thumb-tile.leak { color: #9bdcff; }
.thumb-tile.load { color: #ffe29c; }
.thumb-badges { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 8px; }
.thumb-badges span { padding: 7px 9px; border-radius: 999px; color: #eaf4ff; background: rgba(0,0,0,.24); border: 1px solid rgba(255,255,255,.12); font-size: 11px; font-weight: 900; letter-spacing: .08em; }
.help-sections { display: grid; gap: 12px; }
.help-section { padding: 12px 14px; border-radius: 16px; background: rgba(255,255,255,.05); border: 1px solid var(--line); }
.help-section h3 { margin: 0 0 8px; color: #f1f6ff; }
.help-section p, .help-section li { color: var(--muted); line-height: 1.65; }
.help-section ul { margin: 0; padding-left: 1.2em; }
.beginner-guide { display: grid; gap: 6px; margin-top: 10px; padding: 12px 14px; border-radius: 16px; background: rgba(121,208,255,.10); border: 1px solid rgba(121,208,255,.28); }
.beginner-guide strong { color: #e2f6ff; }
.beginner-guide span { color: #cfe1f4; line-height: 1.55; }
@media (max-width: 980px) { .hero-card-public { grid-template-columns: 1fr; } .promo-thumbnail { min-height: auto; } }
@media (max-width: 560px) { .thumb-building { grid-template-columns: repeat(3, 58px); gap: 7px; } .thumb-tile { width: 58px; height: 48px; font-size: 19px; } .thumb-title { font-size: 34px; } }

/* v1.0 public release: final wording/package polish. */


/* ============================================================
 * v1.1 — Mobile Overhaul (PC幅 >760px には影響しません)
 * 既存PC用CSSは1行も変更せず、スマホ用レイアウトを
 * メディアクエリ内で全面再設計したものです。
 * ============================================================ */
@media (max-width: 760px) {

  /* ---- ベース ---- */
  body {
    overscroll-behavior-y: contain;
  }
  #app { padding: 8px; }

  /* ---- ヘッダー圧縮（横並び維持） ---- */
  .topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    gap: 6px;
    flex-wrap: wrap;
  }
  .topbar > div:first-child { flex: 1 1 auto; min-width: 0; }
  .topbar h1 { font-size: 17px; letter-spacing: 0.02em; }
  .topbar h1 span { font-size: 11px; }
  .topbar p { display: none; }
  .top-actions {
    width: auto;
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
  }
  .top-actions button {
    padding: 7px 9px;
    font-size: 11px;
    border-radius: 10px;
  }

  /* ---- ゲームレイアウト：1カラム + flex order で並べ替え ---- */
  .game-layout {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  /* 表示順：盤面 → 操作（左パネル） → 情報（右パネル） */
  .board-panel { order: 1; }
  .left-panel  { order: 2; }
  .right-panel { order: 3; }

  .left-panel,
  .right-panel,
  .board-panel {
    position: static;
    padding: 12px;
    border-radius: 18px;
    min-height: auto;
  }

  /* ============================================================
   * 1. 盤面パネル（最上部に配置・最大表示）
   * ============================================================ */
  .board-panel { padding: 10px; }

  /* ミッションカード（盤面上部・コンパクト） */
  .mission-card {
    grid-template-columns: 1fr;
    padding: 9px 12px;
    margin-bottom: 7px;
    border-radius: 14px;
    gap: 4px;
  }
  .mission-card .mission-label { font-size: 9px; letter-spacing: 0.16em; }
  .mission-card strong { font-size: 12px; }
  .mission-card p { font-size: 11.5px; line-height: 1.5; margin: 2px 0 0; }

  .message-banner {
    padding: 8px 11px;
    font-size: 11.5px;
    line-height: 1.45;
    margin-bottom: 8px;
    min-height: 0;
    border-radius: 12px;
  }

  /* クリア後のプレビュー帯 */
  .clear-preview-bar {
    grid-template-columns: 1fr;
    padding: 10px;
    font-size: 12px;
    gap: 6px;
  }
  .clear-preview-bar strong { font-size: 13px; }

  /* ---- 盤面：画面幅にフィット ---- */
  /* セルサイズは画面幅と最大列数(8列想定)から動的計算 */
  :root {
    --tile-size: clamp(36px, calc((100vw - 56px) / 8), 64px);
  }
  .board {
    padding: 8px;
    gap: 4px;
    border-radius: 14px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    justify-content: center;
  }
  .tile {
    border-radius: 10px;
    border-width: 1.5px;
    box-shadow: inset 0 -7px 14px rgba(0,0,0,.18);
  }
  .tile .part-icon { font-size: 17px; }
  .tile .part-name { font-size: 8.5px; margin-top: 1px; letter-spacing: 0; }
  .tile .role-label {
    font-size: 8px;
    padding: 1px 2px;
    top: 2px;
    left: 2px;
    right: 2px;
    letter-spacing: 0;
  }
  .place-badge {
    font-size: 8px;
    padding: 0 3px;
    top: 2px;
    right: 2px;
  }
  .tile.roof .place-badge { top: 12px; right: 4px; }

  /* ホバー無効化（スマホ） */
  .tile:hover { transform: none; filter: none; }
  /* タップフィードバック */
  .tile:active:not(.unplaceable):not(.broken) { transform: scale(0.94); }

  /* ============================================================
   * 2. 左パネル（操作系）：盤面の真下に配置
   * ============================================================ */
  /* ステージヘッダー圧縮 */
  .stage-header {
    padding-bottom: 7px;
    margin-bottom: 9px;
  }
  .stage-number { font-size: 10.5px; letter-spacing: 0.14em; }
  .stage-header h2 { font-size: 16px; margin-top: 3px; }

  /* ミッション概要：補助情報は最小化 */
  .mission-summary {
    padding: 10px 11px;
    margin-bottom: 9px;
    border-radius: 14px;
  }
  .mission-summary h3 { font-size: 12px; margin-bottom: 5px; }
  .mission-summary p {
    font-size: 12px;
    line-height: 1.55;
    margin: 0 0 8px;
  }
  .objective-progress {
    font-size: 11.5px;
    padding: 6px 9px;
    margin: 6px 0 8px;
    border-radius: 10px;
  }
  .legend-row {
    grid-template-columns: 70px 1fr;
    gap: 6px;
    font-size: 10.5px;
    margin: 4px 0;
  }
  .legend-badge {
    font-size: 10px;
    padding: 2px 5px;
  }
  .rule-note {
    font-size: 10.5px;
    line-height: 1.5;
    padding: 7px 9px;
    margin-top: 7px;
    border-radius: 10px;
  }

  /* ステータス（配置/ターン/評価）：3列維持・コンパクト */
  .status-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    margin-bottom: 10px;
  }
  .status-grid div {
    padding: 7px 8px;
    border-radius: 11px;
  }
  .status-grid span { font-size: 10px; margin-bottom: 2px; }
  .status-grid strong { font-size: 13.5px; }

  /* ---- ツールボタン：2x2グリッド・タップ最適化 ---- */
  .tools-box { margin: 10px 0; }
  .tools-box h3 { font-size: 12px; margin-bottom: 7px; }
  .tool-buttons {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }
  .tool-button {
    grid-template-columns: 26px 1fr;
    gap: 7px;
    padding: 11px 9px;
    border-radius: 12px;
    min-height: 56px;  /* タップ領域確保 */
  }
  .tool-button .tool-icon { font-size: 21px; }
  .tool-button .tool-name { font-size: 12.5px; }
  .tool-button .tool-short { font-size: 10.5px; margin-top: 1px; }

  /* ツール説明：未選択時はスペースを取らない */
  .tool-description {
    min-height: 0;
    font-size: 11.5px;
    line-height: 1.55;
    margin-top: 7px;
    padding: 0;
  }
  .tool-effectiveness {
    font-size: 10.5px;
    padding: 6px 9px;
    margin-top: 6px;
    border-radius: 10px;
  }

  /* ---- アクションボタン：1ターン進行を主役に ---- */
  .action-buttons {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  /* 1ターン進行＝最初のボタン：横幅フル＋大きく */
  .action-buttons button:first-child {
    grid-column: 1 / -1;
    padding: 16px 14px;
    font-size: 15px;
    min-height: 56px;
    border-radius: 14px;
    box-shadow: 0 10px 22px rgba(35, 122, 255, 0.32);
  }
  .action-buttons button {
    padding: 11px 9px;
    font-size: 12.5px;
    border-radius: 12px;
  }
  /* キーボードヒント(Enter/R)はスマホでは隠す */
  .action-buttons button span { display: none; }

  /* ============================================================
   * 3. 右パネル（情報系）：操作の下にコンパクトに表示
   * ============================================================ */
  .right-panel {
    grid-template-columns: 1fr !important;
    gap: 7px;
  }
  .info-card {
    padding: 11px 12px;
    border-radius: 14px;
  }
  .info-card h3 { font-size: 12px; margin-bottom: 6px; }
  .tile-info {
    font-size: 11.5px;
    line-height: 1.55;
  }
  .part-hint-list { gap: 5px; }
  .part-hint {
    padding: 6px 9px;
    font-size: 10.5px;
    border-radius: 9px;
  }
  .part-hint strong { font-size: 11px; }
  .mini-note { font-size: 10px; line-height: 1.5; }

  #hintText { font-size: 11.5px; line-height: 1.55; }

  .log-card .log-list {
    max-height: 130px;
    font-size: 10.5px;
    line-height: 1.5;
  }

  /* ============================================================
   * 4. モーダル・タイトル画面・ステージ選択
   * ============================================================ */
  .modal-card {
    width: calc(100vw - 20px);
    padding: 18px 18px 20px;
    max-height: calc(100vh - 28px);
    overflow-y: auto;
    border-radius: 22px;
  }
  .modal-card h2 { font-size: 19px; }
  .modal-card p { font-size: 13px; line-height: 1.65; }
  .modal-actions {
    flex-direction: column-reverse;
    gap: 8px;
  }
  .modal-actions button { width: 100%; }

  /* タイトル画面 */
  .title-screen { min-height: auto; padding: 8px 0 24px; }
  .hero-card-public {
    padding: 20px;
    gap: 16px;
  }
  .hero-card-public h2 { font-size: 30px; }
  .hero-card-public p { font-size: 14px; line-height: 1.7; }
  .hero-buttons {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .hero-rule-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* ステージ選択画面 */
  .stage-list {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .stage-card {
    padding: 12px;
    min-height: auto;
    border-radius: 14px;
  }

  /* ボタンの一般タップフィードバック */
  button:hover { transform: none; filter: none; }
  button:active:not(:disabled) { transform: scale(0.97); }
}

/* 極狭スマホ（〜380px）追加微調整 */
@media (max-width: 380px) {
  :root {
    --tile-size: clamp(34px, calc((100vw - 50px) / 8), 56px);
  }
  .topbar h1 { font-size: 15px; }
  .top-actions button { padding: 6px 8px; font-size: 10.5px; }
  .stage-header h2 { font-size: 15px; }
  .tool-button { padding: 10px 8px; min-height: 52px; }
  .action-buttons button:first-child { font-size: 14px; padding: 14px 12px; }
}


/* ============================================================
 * v1.1.1 - スマホ時のタイル内HPバー位置調整
 * 部材名(屋根/壁/柱/床/基礎)とHPバーが重ならないよう、
 * HPバーをタイル下端に細く密着させ、part-nameに余白を確保。
 * ============================================================ */
@media (max-width: 760px) {
  /* HPバー：下端へ密着、薄く */
  .hp-bar {
    bottom: 2px;
    left: 4px;
    right: 4px;
    height: 3.5px;
    border-radius: 3px;
  }
  /* 部材名：HPバーの上に十分な隙間を確保 */
  .tile .part-name {
    margin-top: 1px;
    margin-bottom: 6px;
    line-height: 1;
  }
  /* エフェクトドット（HPバー位置変更に追従） */
  .effect-stack {
    bottom: 9px;
    right: 3px;
  }
  .effect-dot {
    width: 14px;
    height: 14px;
    font-size: 9px;
  }
}

/* ============================================================
 * v1.1 - Stage 1 guided tutorial
 * ============================================================ */
.tutorial-guide-panel {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: min(420px, calc(100vw - 28px));
  z-index: 120;
  padding: 16px 18px;
  border-radius: 22px;
  border: 1px solid rgba(121, 208, 255, .46);
  background: linear-gradient(180deg, rgba(26, 36, 52, .96), rgba(17, 22, 32, .96));
  box-shadow: 0 20px 70px rgba(0,0,0,.38), 0 0 0 1px rgba(255,255,255,.04) inset;
  backdrop-filter: blur(10px);
}
.tutorial-guide-kicker {
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .16em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.tutorial-guide-panel strong {
  display: block;
  color: #f6fbff;
  font-size: 18px;
  margin-bottom: 7px;
}
.tutorial-guide-panel p {
  margin: 0;
  color: #d3deef;
  line-height: 1.7;
  font-size: 14px;
}
.tutorial-guide-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.tutorial-highlight {
  position: relative;
  z-index: 20;
  outline: 3px solid rgba(255, 209, 102, .96) !important;
  outline-offset: 4px;
  box-shadow: 0 0 0 4px rgba(255,209,102,.20), 0 0 28px rgba(255,209,102,.44) !important;
  animation: tutorialPulse 1s ease-in-out infinite alternate;
}
.tile.tutorial-tile-focus {
  z-index: 25;
  opacity: 1 !important;
  outline: 4px solid rgba(255, 209, 102, .96) !important;
  outline-offset: 4px;
  box-shadow: 0 0 0 4px rgba(255,209,102,.20), 0 0 30px rgba(255,209,102,.50), inset 0 -10px 20px rgba(0,0,0,.18) !important;
  animation: tutorialPulse 1s ease-in-out infinite alternate;
}
.tile.tutorial-soft-dim {
  opacity: .42;
  filter: grayscale(.35) brightness(.82);
}
@keyframes tutorialPulse {
  from { transform: translateY(0); }
  to { transform: translateY(-2px); }
}

@media (max-width: 760px) {
  .tutorial-guide-panel {
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    padding: 13px 14px;
    border-radius: 18px;
  }
  .tutorial-guide-panel strong { font-size: 15px; }
  .tutorial-guide-panel p { font-size: 12.5px; line-height: 1.6; }
  .tutorial-guide-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .tutorial-guide-actions button { width: 100%; }
  .tutorial-highlight { outline-offset: 2px; }
}
