:root {
  /* 夜の攻城戦：藍(indigo) × 朱(vermilion) × 金(gold) */
  --bg: #080b12;
  --bg-soft: #101725;
  --panel: #141d2c;
  --panel-2: #1a2436;
  --line: #2b3750;
  --line-gold: rgba(232,182,76,0.28);
  --field: #0d1624;
  --text: #eaf0f8;
  --text-dim: #8093ad;
  --gold: #e8b64c;
  --gold-soft: #f2cf82;
  --vermilion: #e8483a;
  --indigo: #6d7fe8;
  --jade: #57c98a;
  --accent: var(--gold);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN",
    "Yu Gothic", "Noto Sans JP", Meiryo, sans-serif;

  --c-yumi: #57c98a;
  --c-teppo: #6ea8ff;
  --c-ohzutsu: #f0894a;
  --c-makibishi: #46c2c8;
  --c-noroshi: #b98cff;
  --c-samurai: #e05a5a;

  --e-ashigaru: #c9a06a;
  --e-kiba: #e0663a;
  --e-musha: #6fae86;
  --e-shinobi: #9c8ad6;
  --e-souhei: #d6b24a;
  --e-taisho: #c85ad0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* 夜空＋朱の陣気配＋麻の葉風の微細テクスチャ */
body {
  background:
    radial-gradient(1200px 520px at 50% -240px, #1b2b47 0%, rgba(8,11,18,0) 60%),
    radial-gradient(760px 380px at 88% 8%, rgba(232,72,58,0.10) 0%, rgba(8,11,18,0) 58%),
    repeating-linear-gradient(60deg, rgba(255,255,255,0.014) 0 1px, transparent 1px 22px),
    repeating-linear-gradient(-60deg, rgba(255,255,255,0.014) 0 1px, transparent 1px 22px),
    var(--bg);
  min-height: 100vh;
}

.app {
  max-width: 640px;
  margin-inline: auto;
  padding: 14px 14px 44px;
}

/* ---- topbar / brand ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.back {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 12.5px;
  white-space: nowrap;
}
.back:hover { color: var(--gold); }

.brand {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.crest {
  width: 26px;
  height: 26px;
  color: var(--gold);
  flex: 0 0 auto;
  filter: drop-shadow(0 0 6px rgba(232,182,76,0.35));
}

.title {
  margin: 0;
  font-family: "BrushTitle", var(--font);
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 0.18em;
  background: linear-gradient(180deg, #fff4dc, var(--gold) 65%, #b9832a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 2px 10px rgba(0,0,0,0.4);
}
.title .accent { -webkit-text-fill-color: transparent; }

.sub {
  font-family: "BrushTitle", var(--font);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.42em;
  color: var(--vermilion);
  padding-left: 2px;
  align-self: center;
  text-shadow: 0 0 8px rgba(232,72,58,0.4);
}

.icon-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 34px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--gold); }

/* 青海波の飾り罫 */
.wa-divider {
  display: block;
  width: 100%;
  height: 12px;
  margin-bottom: 12px;
  opacity: 0.8;
}

/* ---- 共通パネル質感 ---- */
.hud, .wavebar, .actives, .stat-box, .tower-btn, .act-btn,
.sel-card, .legend, .ranking, .btn, .icon-btn {
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

/* ---- HUD ---- */
.hud { display: flex; gap: 8px; margin-bottom: 10px; }

.stat-box {
  flex: 1;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-top-color: var(--line-gold);
  border-radius: var(--radius);
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  position: relative;
}
.stat-box.gold { border-color: rgba(232,182,76,0.45); }

.label { font-size: 10px; color: var(--text-dim); letter-spacing: 0.14em; }
.value { font-size: 21px; font-weight: 900; font-variant-numeric: tabular-nums; }
.stat-box.gold .value { color: var(--gold); }
#base-hp.low { color: var(--vermilion); }

/* ---- wave bar ---- */
.wavebar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-bottom: 10px;
}
.wave-info { flex: 1; min-width: 0; }
.wave-note { font-size: 12.5px; color: var(--text-dim); line-height: 1.4; }
.wave-note b { color: var(--text); }
.wave-note .em { color: var(--gold); font-weight: 800; }
.wave-note .boss { color: var(--vermilion); font-weight: 900; }
.wave-ctrl { display: flex; gap: 6px; align-items: center; }

/* ---- stage ---- */
.stage-wrap {
  position: relative;
  margin-bottom: 10px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 10px 34px rgba(0,0,0,0.5), 0 0 0 1px var(--line-gold);
}
.stage {
  display: block;
  width: 100%;
  background: var(--field);
  border-radius: var(--radius);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 11, 18, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 5;
  text-align: center;
  padding: 20px;
}

/* スタート画面 */
.start-overlay { gap: 11px; }
.start-kicker {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.3em;
  color: var(--gold);
}
.start-title {
  margin: 0;
  font-family: "BrushTitle", var(--font);
  font-weight: 400;
  font-size: clamp(42px, 13vw, 62px);
  line-height: 1;
  letter-spacing: 0.06em;
  color: var(--gold-soft);
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.35em;
}
.start-title .start-sub {
  font-size: 0.42em;
  letter-spacing: 0.24em;
  color: var(--text-dim);
}
.start-lead {
  margin: 4px 0 0;
  max-width: 300px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-dim);
}
.start-tips {
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
  max-width: 330px;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--text-dim);
}
.start-tips li { margin: 3px 0; }
.start-btn { min-width: 180px; margin-top: 6px; font-size: 16px; padding: 13px 28px; }
.start-note { margin: 2px 0 0; font-size: 11px; color: var(--text-dim); opacity: 0.8; }

.overlay-title {
  margin: 0;
  font-family: "BrushTitle", var(--font);
  font-size: 38px;
  font-weight: 900;
  letter-spacing: 0.2em;
  color: var(--gold);
  text-shadow: 0 0 26px rgba(232,182,76,0.45);
}
.overlay-title.lose { color: var(--vermilion); text-shadow: 0 0 26px rgba(232,72,58,0.45); }
.overlay-score { margin: 0; color: var(--text-dim); font-size: 14px; }
.overlay-score b { color: var(--text); }
.overlay-rank { margin: 0; font-size: 16px; font-weight: 800; color: var(--gold); letter-spacing: 0.06em; }

.overlay-name { display: flex; align-items: center; gap: 8px; }
.overlay-name label { font-size: 12px; color: var(--text-dim); }
.overlay-name input {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 7px 10px;
  width: 140px;
  text-align: center;
}
.overlay-name input:focus { outline: none; border-color: var(--gold); }
.overlay-actions { display: flex; gap: 10px; }
.overlay-actions .btn { min-width: 0; padding: 12px 20px; }

.hidden { display: none !important; }

/* ---- actives（計略） ---- */
.actives { display: flex; gap: 8px; margin-bottom: 10px; }
.act-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 10px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: border-color 0.15s ease, transform 0.06s ease;
}
.act-btn:hover:not(:disabled) { border-color: var(--gold); }
.act-btn:active:not(:disabled) { transform: translateY(1px); }
.act-btn:disabled { opacity: 0.42; cursor: not-allowed; }
.act-btn.ready { border-color: rgba(232,182,76,0.55); box-shadow: 0 0 12px rgba(232,182,76,0.14) inset; }
.act-icon { font-size: 19px; line-height: 1; }
.act-body { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.act-name { font-size: 13px; font-weight: 800; }
.act-desc { font-size: 10px; color: var(--text-dim); }
.act-cost { font-size: 13px; font-weight: 900; color: var(--gold); font-variant-numeric: tabular-nums; white-space: nowrap; }
.act-cost.cd { color: var(--indigo); }

/* ---- palette（木札風・3列） ---- */
.palette {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-bottom: 10px;
}
.tower-btn {
  background: linear-gradient(180deg, #202b3e, #16202f);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.06s ease;
}
.tower-btn:hover:not(:disabled) { border-color: var(--gold); }
.tower-btn:active:not(:disabled) { transform: translateY(1px); }
.tower-btn.active {
  border-color: var(--gold);
  background: linear-gradient(180deg, rgba(232,182,76,0.20), rgba(232,182,76,0.05));
}
.tower-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.tw-mark {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 900;
  color: #0b0f17;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.22);
}
.tw-yumi { background: var(--c-yumi); }
.tw-teppo { background: var(--c-teppo); }
.tw-ohzutsu { background: var(--c-ohzutsu); }
.tw-makibishi { background: var(--c-makibishi); }
.tw-noroshi { background: var(--c-noroshi); }
.tw-samurai { background: var(--c-samurai); color: #fff; }

.tw-body { flex: 1; display: flex; flex-direction: column; min-width: 0; text-align: left; gap: 1px; }
.tw-name { font-size: 12px; font-weight: 800; white-space: nowrap; }
.tw-role { font-size: 9.5px; color: var(--text-dim); white-space: nowrap; }
.tw-cost { font-size: 12px; font-weight: 900; color: var(--gold); font-variant-numeric: tabular-nums; }

/* ---- selection card ---- */
.sel-card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 10px;
}
.sel-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.sel-name { font-size: 15px; font-weight: 900; }
.sel-lv {
  font-size: 11px; font-weight: 800; color: var(--gold);
  background: var(--bg-soft); border: 1px solid var(--line);
  padding: 1px 8px; border-radius: 999px;
}
.sel-tag {
  font-size: 10px; font-weight: 800; color: var(--jade);
  background: rgba(87,201,138,0.12); border: 1px solid rgba(87,201,138,0.4);
  padding: 1px 7px; border-radius: 999px;
}
.sel-close { margin-left: auto; background: none; border: none; color: var(--text-dim); font-size: 15px; cursor: pointer; }
.sel-close:hover { color: var(--text); }
.sel-desc { margin: 0 0 8px; font-size: 11.5px; color: var(--text-dim); line-height: 1.5; }
.sel-stats { display: flex; gap: 12px; font-size: 12px; color: var(--text-dim); margin-bottom: 10px; flex-wrap: wrap; }
.sel-stats b { color: var(--text); font-variant-numeric: tabular-nums; }
.sel-stats .up { color: var(--jade); }
.sel-actions { display: flex; gap: 8px; }
.sel-actions .btn { flex: 1; }
#sel-upgrade:disabled, #sel-upgrade.maxed { opacity: 0.45; cursor: not-allowed; }

/* ---- buttons ---- */
.btn {
  text-align: center;
  padding: 10px 14px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s ease, transform 0.06s ease;
}
.btn:hover { border-color: var(--gold); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(180deg, var(--gold-soft), var(--gold) 60%, #c68a2b);
  color: #201404;
  border-color: var(--gold);
  text-shadow: 0 1px 0 rgba(255,255,255,0.25);
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-mini { padding: 8px 10px; font-size: 13px; min-width: 42px; }
.btn-sally { padding: 10px 22px; letter-spacing: 0.12em; }
.btn-sally:disabled { opacity: 0.4; cursor: not-allowed; filter: none; }
.overlay .btn { min-width: 160px; padding: 12px 28px; }

/* ---- legend ---- */
.legend {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 11px;
  color: var(--text-dim);
}
.legend-title { font-weight: 800; color: var(--text); letter-spacing: 0.1em; }
.lg-item { display: inline-flex; align-items: center; gap: 5px; }
.lg-dot {
  width: 18px; height: 18px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 900; color: #0b0f17;
}
.lg-dot[data-e="ashigaru"] { background: var(--e-ashigaru); }
.lg-dot[data-e="kiba"] { background: var(--e-kiba); }
.lg-dot[data-e="musha"] { background: var(--e-musha); }
.lg-dot[data-e="shinobi"] { background: var(--e-shinobi); }
.lg-dot[data-e="souhei"] { background: var(--e-souhei); }
.lg-dot[data-e="arabushi"] { background: #e0663a; color: #fff; }
.lg-dot[data-e="taisho"] { background: var(--e-taisho); color: #fff; }

/* 施設ホバーの説明ポップアップ */
.tip {
  position: fixed;
  z-index: 50;
  max-width: 220px;
  pointer-events: none;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--gold);
  border-radius: 10px;
  padding: 8px 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  color: var(--text);
}
.tip .tip-name { font-size: 13px; font-weight: 900; }
.tip .tip-name .lv { color: var(--gold); font-size: 11px; margin-left: 4px; }
.tip .tip-role { font-size: 10.5px; color: var(--gold); margin: 1px 0 4px; }
.tip .tip-desc { font-size: 11px; color: var(--text-dim); line-height: 1.45; }
.tip .tip-stats { font-size: 11px; margin-top: 4px; display: flex; gap: 10px; flex-wrap: wrap; }
.tip .tip-stats b { color: var(--text); font-variant-numeric: tabular-nums; }

.hint { margin-top: 14px; color: var(--text-dim); font-size: 11.5px; text-align: center; line-height: 1.7; }
.hint b { color: var(--gold); font-weight: 800; }

/* ---- ranking ---- */
.ranking {
  margin-top: 22px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
}
.ranking-title {
  margin: 0 0 12px;
  font-family: "BrushTitle", var(--font);
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0.2em;
  color: var(--text);
  display: inline-block;
  position: relative;
  padding-bottom: 6px;
}
.ranking-title::after {
  content: "";
  position: absolute;
  left: 0; bottom: 0;
  width: 100%; height: 2px;
  background: linear-gradient(90deg, var(--vermilion), transparent);
  border-radius: 2px;
}
.rank-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.rank-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 8px;
  background: var(--bg-soft); font-size: 13px;
}
.rank-row.latest { border: 1px solid var(--gold); background: rgba(232,182,76,0.1); }
.rank-no { width: 2em; font-weight: 800; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.rank-row:nth-child(1) .rank-no { color: var(--gold); }
.rank-row:nth-child(2) .rank-no { color: #cfd6e2; }
.rank-row:nth-child(3) .rank-no { color: #d8863b; }
.rank-name { flex: 1; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 8em; }
.rank-score { flex: 1; font-weight: 800; font-variant-numeric: tabular-nums; }
.rank-row.world .rank-score { flex: 0 0 auto; }
.rank-wave {
  font-size: 11px; color: var(--gold);
  background: var(--bg-soft); border: 1px solid var(--line);
  padding: 2px 8px; border-radius: 999px; font-variant-numeric: tabular-nums;
}
.rank-date { font-size: 11px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.rank-empty { margin: 0; color: var(--text-dim); font-size: 12px; }

.credits {
  margin: 16px 0 0;
  text-align: center;
  font-size: 10.5px;
  color: var(--text-dim);
  letter-spacing: 0.06em;
  opacity: 0.75;
}

/* ---- about / SEO ---- */
.about {
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.85;
}
.about h2 {
  margin: 0 0 8px;
  font-size: 16px;
  color: var(--text);
  letter-spacing: 0.02em;
}
.about h3 {
  margin: 16px 0 4px;
  font-size: 13px;
  color: var(--accent);
  letter-spacing: 0.04em;
}
.about p { margin: 0; }

@media (max-width: 420px) {
  .act-desc { display: none; }
  .tw-name { font-size: 10.5px; }
  .sub { display: none; }
}

/* ---- PC（広幅）ではゲームを大きく表示。スマホは今のまま。 ---- */
@media (min-width: 760px) {
  .app { max-width: 880px; }
  .title { font-size: 34px; }
  .value { font-size: 26px; }
  .label { font-size: 11px; }
  .wave-note { font-size: 14px; }
  .tw-name { font-size: 13px; }
  .tw-role { font-size: 11px; }
  .hint { font-size: 13px; }
}
