:root {
  --ink: #23262b; --soft: #6b7078; --blue: #2f7de1; --blue-dark: #1f63bd; --red: #e2483d; --gold: #f2b632;
  --panel: #fffffff2; --line: #e4e6ea;
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  color: var(--ink); background: #fbf7ee;
}
* { box-sizing: border-box; }
html, body, #app { width: 100%; height: 100%; margin: 0; overflow: hidden; touch-action: none; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button { font: inherit; cursor: pointer; border: 0; color: inherit; touch-action: manipulation; }
button:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
[hidden] { display: none !important; }
#field { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

header { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 16px; right: 12px; display: flex;
  justify-content: space-between; align-items: center; z-index: 10; pointer-events: none; }
.brand { font-weight: 900; font-size: 17px; letter-spacing: 1px; }
.brand span { color: var(--blue); }
.tools { display: flex; gap: 8px; pointer-events: auto; }
.tools button { background: #ffffffd8; border: 2px solid var(--ink); border-radius: 50px; height: 36px; min-width: 44px;
  padding: 0 12px; font-size: 12px; font-weight: bold; }

/* ── 戦闘中の表示 ── */
#hud { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.hud-top { position: absolute; top: max(52px, calc(env(safe-area-inset-top) + 44px)); left: 16px; right: 16px;
  display: flex; justify-content: space-between; align-items: center; }
.stage-label { font-weight: 900; font-size: 13px; background: #fff; border: 2px solid var(--ink); border-radius: 8px; padding: 2px 10px; }
.money { position: relative; display: flex; align-items: center; gap: 6px; background: #fff; border: 3px solid var(--ink); border-radius: 14px;
  padding: 2px 14px 8px 8px; font-weight: 900; box-shadow: 0 3px 0 var(--ink); }
.money .coin { width: 24px; height: 24px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ffe28a, var(--gold) 60%, #c98f12);
  border: 2px solid var(--ink); flex: none; }
.money b { font-size: 28px; line-height: 1.1; color: #b07a00; font-variant-numeric: tabular-nums; }
.money small { font-size: 12px; color: var(--soft); align-self: flex-end; margin-bottom: 4px; }
.money-bar { position: absolute; left: 8px; right: 8px; bottom: 3px; height: 4px; border-radius: 4px; background: #eee6cf; overflow: hidden; }
.money-bar i { display: block; height: 100%; width: 0; background: var(--gold); }
#toast { position: absolute; top: 34%; left: 0; right: 0; text-align: center; font-weight: 900; font-size: 28px;
  letter-spacing: 3px; opacity: 0; transition: opacity .3s; text-shadow: 0 2px 0 #fff, 0 -2px 0 #fff, 2px 0 0 #fff, -2px 0 0 #fff; }
#toast.on { opacity: 1; }

.bar { position: absolute; left: 0; right: 0; bottom: 0; max-width: 820px; margin: 0 auto; padding: 8px max(10px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-bottom));
  display: flex; gap: 8px; align-items: stretch; pointer-events: auto; background: linear-gradient(#fbf7ee00, #fbf7eef0 30%); }
#units { flex: 1; display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; min-width: 0; }
/* 兵ボタン＝丸い顔＋待ち時間の輪（時計回り）＋秒数。絵は待っている間もはっきり見せる */
.unit { position: relative; background: none; padding: 2px 0 0; display: flex; flex-direction: column; align-items: center; min-width: 0; }
.unit .face { position: relative; width: 58px; height: 58px; border-radius: 50%; background: #fff; border: 3px solid var(--ink);
  box-shadow: 0 3px 0 var(--ink); display: grid; place-items: center; }
.unit canvas { width: 40px; height: 40px; position: relative; z-index: 1; }
.unit .ring { position: absolute; inset: -3px; border-radius: 50%; --p: 1;
  background: conic-gradient(var(--blue) calc(var(--p) * 1turn), #d3d7de 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 7px), #000 calc(100% - 6px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 7px), #000 calc(100% - 6px)); }
.unit:not(.wait) .ring { background: none; }
.unit .sec { position: absolute; z-index: 2; right: -8px; top: -6px; min-width: 26px; padding: 1px 5px; border-radius: 10px; background: var(--ink);
  color: #fff; font-size: 12px; font-weight: 900; font-variant-numeric: tabular-nums; text-align: center; }
.unit .sec:empty { display: none; }
.unit .nm { font-size: 11px; font-weight: 900; line-height: 1.2; margin-top: 4px; }
.unit .cost { font-size: 12px; font-weight: 900; color: #8a5f00; line-height: 1; background: #fff6d8; border: 2px solid var(--ink); border-radius: 10px;
  padding: 2px 7px; margin-top: 2px; }
.unit .key { position: absolute; top: 0; left: 2px; font-size: 9px; color: var(--soft); z-index: 2; }
.unit.wait .face { background: #f1f3f6; }
.unit.poor .cost { background: #fde3e1; color: var(--red); }
.unit.locked .face { background: #eceef1; border-color: #a6abb3; box-shadow: 0 3px 0 #a6abb3; }
.unit.locked .cost { background: #eceef1; color: var(--soft); border-color: #a6abb3; font-size: 10px; }
.unit.just .face { animation: ready .6s ease-out; }
@keyframes ready { 0% { box-shadow: 0 3px 0 var(--ink), 0 0 0 0 #f2b632cc; transform: scale(1.12); } 100% { box-shadow: 0 3px 0 var(--ink), 0 0 0 14px #f2b63200; transform: scale(1); } }
.unit:active .face { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.side { display: flex; flex-direction: column; gap: 6px; width: 96px; flex: none; }
.side button { position: relative; flex: 1; border: 2px solid var(--ink); border-radius: 10px; background: #fff; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2px; }
.side .t { font-weight: 900; font-size: 13px; position: relative; z-index: 1; }
.side small { font-size: 10px; color: var(--soft); position: relative; z-index: 1; }
.wallet.poor { opacity: .45; }
.cannon i { position: absolute; left: 0; bottom: 0; top: 0; background: #f2b63266; width: 0; }
.cannon.ready { background: var(--gold); animation: pulse 0.9s infinite alternate; }
.cannon.ready small { color: var(--ink); font-weight: bold; }
@keyframes pulse { to { transform: scale(1.04); } }

/* ── 画面（タイトル・地図・結果） ── */
.overlay { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; overflow-y: auto;
  padding: max(54px, calc(env(safe-area-inset-top) + 46px)) 8px 10px; }
#title { background: linear-gradient(90deg, #fbf7eef5 0%, #fbf7eee0 40%, #fbf7ee40 75%); justify-content: flex-start; padding: 0; }
.intro { margin-left: 7%; max-width: 480px; padding: 64px 16px 24px; }
.eyebrow { font-size: 11px; letter-spacing: 2px; font-weight: bold; color: var(--soft); }
h1 { font-size: 54px; line-height: 1.1; letter-spacing: 2px; margin: 10px 0 6px; font-weight: 900; }
h1 span { color: var(--blue); }
.subtitle { font-size: 13px; letter-spacing: 3px; margin: 0 0 14px; }
.rules { font-size: 13px; line-height: 1.7; margin: 0 0 18px; }
.rules p { margin: 4px 0; }
.rules b { color: var(--blue-dark); }
.primary { background: var(--blue); color: #fff; min-width: 220px; padding: 14px 24px; border-radius: 12px; font-weight: 900;
  font-size: 17px; letter-spacing: 3px; border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink); }
.primary:hover { background: var(--blue-dark); }
.primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.secondary { background: #fff; min-width: 180px; padding: 10px 18px; border-radius: 12px; font-weight: 900; border: 3px solid var(--ink);
  box-shadow: 0 3px 0 var(--ink); }
.text-button { background: none; color: var(--soft); text-decoration: underline; padding: 8px; font-size: 13px; }
.instructions { font-size: 11px; line-height: 1.7; margin-top: 14px; color: var(--soft); }
.instructions p { margin: 3px 0; }
.instructions b { margin-right: 6px; color: var(--ink); }
.best { font-size: 12px; letter-spacing: 1px; margin-top: 10px; font-weight: bold; }
.back { display: inline-block; margin-top: 10px; padding-block: .35rem; font-size: 12px; color: var(--soft); }

.shade { background: #fbf7eecc; }
.panel { background: var(--panel); border: 3px solid var(--ink); border-radius: 16px; padding: 20px 22px; text-align: center;
  width: min(92vw, 380px); max-height: 100%; overflow-y: auto; box-shadow: 0 6px 0 var(--ink); margin: auto; }
.panel.wide { width: min(94vw, 640px); }
.panel h2 { margin: 6px 0 12px; font-size: 24px; font-weight: 900; }
.panel .primary, .panel .secondary { display: block; margin: 10px auto 0; }

#stages { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 6px 0 12px; }
.stage { background: #fff; border: 2px solid var(--ink); border-radius: 10px; padding: 8px 2px; font-weight: 900; font-size: 18px; }
.stage small { display: block; font-size: 11px; color: var(--gold); letter-spacing: 1px; min-height: 1.2em; }
.stage.locked { background: #eceef1; color: #a6abb3; cursor: not-allowed; }
.stage.boss { border-color: var(--red); }
.map-foot { display: flex; flex-direction: column; align-items: center; }

.stars-left { margin: 0 0 10px; font-weight: bold; }
.stars-left b { color: #b07a00; font-size: 20px; }
#up-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; text-align: left; }
.up { text-align: left; background: #fff; border: 2px solid var(--ink); border-radius: 10px; padding: 8px 10px; display: grid; grid-template-columns: auto 1fr; column-gap: 8px; row-gap: 1px; align-items: center; }
.up > :not(canvas) { grid-column: 2; }
.up canvas { grid-row: 1 / span 3; width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--ink); background: #f4f7fb; }
.up .st { font-size: 11px; font-weight: bold; color: var(--ink); }
.up b { font-size: 14px; }
.up small { font-size: 11px; color: var(--soft); line-height: 1.4; }
.up .lv { font-size: 12px; font-weight: bold; color: var(--blue-dark); }
.up.poor { opacity: .5; }
.up.max { background: #f4f6f8; }

.stars { font-size: 34px; letter-spacing: 6px; color: #d6d9de; margin-bottom: 6px; }
.stars .on { color: var(--gold); text-shadow: 0 2px 0 var(--ink); display: inline-block; animation: star-pop .45s cubic-bezier(.3,1.6,.5,1) backwards; }
.stars .on:nth-child(1) { animation-delay: .25s; } .stars .on:nth-child(2) { animation-delay: .55s; } .stars .on:nth-child(3) { animation-delay: .85s; }
@keyframes star-pop { from { transform: scale(0) rotate(-40deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }
.stats { display: flex; justify-content: center; gap: 14px; margin: 6px 0; }
.stats div { display: flex; flex-direction: column; }
.stats small { font-size: 11px; color: var(--soft); }
.stats b { font-size: 18px; }
.note { font-size: 13px; color: var(--blue-dark); font-weight: bold; min-height: 1em; margin: 6px 0; }

/* スマホ縦：下のボタンを2段に */
@media (max-width: 560px) {
  h1 { font-size: 40px; }
  .intro { margin: 0 auto; }
  #title { background: #fbf7eee8; justify-content: center; }
  .bar { flex-direction: column; }
  .side { flex-direction: row; width: auto; height: 46px; }
  .unit .face { width: 52px; height: 52px; }
  #stages { grid-template-columns: repeat(5, 1fr); gap: 6px; }
}
/* 背の低い画面（スマホ横・PC 600px） */
@media (max-height: 520px) {
  .intro { padding-top: 46px; }
  h1 { font-size: 36px; margin: 4px 0; }
  .rules { font-size: 12px; margin-bottom: 10px; }
  .instructions { display: none; }
  .primary { padding: 10px 20px; }
  .unit .face { width: 46px; height: 46px; }
  .unit canvas { width: 32px; height: 32px; }
  .unit .nm { display: none; }
  .money b { font-size: 22px; }
  .hud-top { top: max(48px, env(safe-area-inset-top)); }
  .panel { padding: 12px 16px; }
  .panel h2 { margin: 2px 0 8px; font-size: 20px; }
  .up { padding: 4px 8px; }
  .up small { display: none; }
  #up-cards { grid-template-columns: repeat(4, 1fr); }
}
