/* =====================
   Page reset / wrapper
   ===================== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --ink: #080704;
  --void: #0c0b09;
  --stone: #17140f;
  --stone-2: #211c14;
  --line: #5c5039;
  --line-dim: #342d22;
  --brass: #c49a4a;
  --brass-bright: #f0d081;
  --blood: #b84a3d;
  --steel: #9aa6ad;
  --rune: #d8d0bc;
}

body {
  background:
    radial-gradient(circle at center, #1a1610 0, #070604 58%, #000 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  overflow: hidden;
}

#game-wrapper {
  position: relative;
  display: inline-block;
  background: #000;
  border: 2px solid #4e412d;
  box-shadow:
    0 0 0 2px #080604,
    0 0 0 5px #221b12,
    0 24px 70px rgba(0, 0, 0, 0.75),
    inset 0 0 32px rgba(196, 154, 74, 0.08);
}

canvas { display: block; }

#battle-panel,
#shop-modal,
#respawn-overlay,
#result-screen,
#restart-confirm,
#title-screen {
  contain: layout paint style;
}

/* =====================
   Battle Panel
   ===================== */
#battle-panel[hidden] { display: none; }

#battle-panel {
  position: absolute;
  left: 0; top: 0;
  width: 740px; height: 500px;
  background:
    linear-gradient(180deg, rgba(24, 20, 15, 0.98), rgba(7, 7, 7, 0.98)),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.025) 0 1px, transparent 1px 4px);
  color: var(--rune);
  font-family: "Consolas", "Courier New", monospace;
  display: flex;
  flex-direction: column;
  padding: 12px;
  box-sizing: border-box;
  border-right: 2px solid var(--line);
  box-shadow: inset 0 0 0 1px #0a0805, inset 0 0 45px rgba(0, 0, 0, 0.75);
  z-index: 10;
}

#battle-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 16px;
  color: var(--brass-bright);
  font-weight: bold;
  padding: 7px 10px 9px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #211b12, #0f0d0a);
  margin-bottom: 8px;
  flex-shrink: 0;
  letter-spacing: 0.08em;
  text-shadow: 0 1px 0 #000;
}

.battle-counts {
  font-size: 12px;
  color: #b5aa8d;
  font-weight: normal;
  letter-spacing: 0.04em;
}

#battle-main {
  display: flex;
  gap: 12px;
  flex: 0 0 220px;
  overflow: hidden;
}

.battle-side {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.battle-side-label {
  font-size: 11px;
  color: var(--brass);
  padding: 0 4px 5px;
  letter-spacing: 0.12em;
  border-bottom: 1px solid var(--line-dim);
  margin-bottom: 4px;
}

#battle-enemy-list,
#battle-ally-list {
  overflow-y: hidden;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ユニットカード */
.battle-unit {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 7px;
  border: 1px solid var(--line-dim);
  border-radius: 2px;
  margin-bottom: 3px;
  background: linear-gradient(180deg, #181510, #0d0c0a);
  height: 38px;
  box-sizing: border-box;
  flex-shrink: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.unit-sprite {
  width: 32px !important;
  height: 32px !important;
}

.battle-unit.dead {
  opacity: 0.38;
  text-decoration: line-through;
  filter: grayscale(0.8);
}

/* 空きスロット（グレーの空白カード） */
.battle-unit.empty {
  background: #100f0c;
  border: 1px dashed #3b3325;
  pointer-events: none;
}

.battle-unit.target-btn {
  cursor: pointer;
}

.battle-unit.target-btn:hover {
  background: linear-gradient(180deg, #261814, #140d0b);
  border-color: #986848;
}

.battle-unit.selected {
  border-color: var(--blood);
  background: linear-gradient(180deg, #351410, #170907);
  box-shadow:
    inset 0 0 0 1px rgba(240, 208, 129, 0.2),
    0 0 12px rgba(184, 74, 61, 0.45);
  animation: targetPulse 1.4s ease-in-out infinite;
}

/* 選択カード：右端にターゲットマーカー */
.battle-unit.selected::before {
  content: '>';
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--brass-bright);
  font-size: 16px;
  text-shadow: 0 0 8px rgba(240, 208, 129, 0.8);
  pointer-events: none;
}

@keyframes targetPulse {
  0%, 100% { box-shadow: inset 0 0 0 1px rgba(240, 208, 129, 0.18), 0 0 8px rgba(184, 74, 61, 0.35); }
  50%      { box-shadow: inset 0 0 0 1px rgba(240, 208, 129, 0.34), 0 0 15px rgba(184, 74, 61, 0.75); }
}

.battle-unit.player {
  border-color: #51697d;
  background: linear-gradient(180deg, #141a1f, #090c0f);
}

/* スプライトキャンバス */
.unit-sprite {
  flex-shrink: 0;
  image-rendering: pixelated;
}

/* ユニット情報 */
.unit-info {
  flex: 1;
  min-width: 0;
}

.unit-name {
  font-size: 13px;
  color: #e4ddc9;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unit-stats {
  font-size: 12px;
  color: #a99f86;
}

.unit-hpbar {
  height: 4px;
  background: #090807;
  border: 1px solid #2c251b;
  border-radius: 0;
  margin-top: 3px;
}

.unit-hpbar-fill {
  height: 100%;
  border-radius: 0;
}

/* 行動情報欄 */
#battle-action-info {
  display: flex;
  gap: 8px;
  margin: 8px 0 7px;
  padding: 8px 10px;
  background: linear-gradient(180deg, #17130e, #0a0907);
  border: 1px solid var(--line);
  border-radius: 2px;
  flex-shrink: 0;
}

#battle-action-info .ai-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

#battle-action-info .ai-label {
  font-size: 10px;
  color: #887a5b;
  letter-spacing: 0.12em;
}

#battle-action-info .ai-value {
  font-size: 13px;
  color: #e2dcc9;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#battle-action-info .ai-value.ai-dmg {
  color: var(--brass-bright);
}

/* コマンドボタン */
#battle-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 4px;
  flex-shrink: 0;
}

.battle-btn {
  flex: 1;
  padding: 8px 10px;
  background: linear-gradient(180deg, #211b12, #0c0a07);
  border: 1px solid var(--line);
  color: #bfb59d;
  cursor: pointer;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 13px;
  font-weight: bold;
  border-radius: 2px;
  letter-spacing: 0.1em;
  transition: opacity 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.battle-btn:not(.kb-selected):not(:hover) {
  opacity: 0.5;
}

.battle-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.battle-btn:hover:not(:disabled) {
  background: linear-gradient(180deg, #332817, #15100a);
  border-color: var(--brass);
  color: #fff1c3;
}

.battle-btn.kb-selected {
  background: linear-gradient(180deg, #3b2a17, #181008);
  border-color: var(--brass-bright);
  color: #fff1c3;
  box-shadow: inset 0 0 0 1px rgba(240, 208, 129, 0.3), 0 0 12px rgba(196, 154, 74, 0.22);
}

/* 操作ヒント */
#battle-hint {
  font-size: 10px;
  color: #8a806b;
  text-align: center;
  padding: 2px 0 5px;
  flex-shrink: 0;
  letter-spacing: 0.08em;
}

/* バトルログ */
#battle-log {
  flex: 1;
  min-height: 0;
  overflow-y: hidden;
  background: #070604;
  border: 1px solid var(--line-dim);
  padding: 5px 9px;
  font-size: 10px;
  border-radius: 2px;
}

#battle-log p {
  padding: 2px 0 3px;
  border-bottom: 1px dotted #2b241a;
  margin: 0;
  font-size: 12px;
  color: #cfc5ae;
  line-height: 1.25;
}

/* =====================
   Shop Modal
   ===================== */
#shop-modal[hidden] { display: none; }

#shop-modal {
  position: absolute;
  left: 0; top: 0;
  width: 740px; height: 500px;
  background:
    radial-gradient(circle at center, rgba(48, 37, 20, 0.28), rgba(0, 0, 0, 0.88) 62%),
    rgba(0, 0, 0, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 20;
}

.shop-modal-inner {
  background:
    linear-gradient(180deg, #211b13, #0c0a07 45%, #090806),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.025) 0 1px, transparent 1px 6px);
  border: 2px solid var(--line);
  padding: 18px;
  width: 500px;
  font-family: "Consolas", "Courier New", monospace;
  color: var(--rune);
  border-radius: 3px;
  box-shadow:
    0 20px 50px rgba(0, 0, 0, 0.7),
    inset 0 0 0 1px #0a0805,
    inset 0 0 40px rgba(0, 0, 0, 0.55);
}

.shop-modal-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 16px;
  color: var(--brass-bright);
  font-weight: bold;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 9px;
  letter-spacing: 0.12em;
}

.shop-gold-label {
  color: #d6c49b;
  font-size: 13px;
  font-weight: normal;
  letter-spacing: 0.06em;
}

.shop-modal-note {
  font-size: 11px;
  color: #9b917a;
  margin-bottom: 12px;
}

.shop-item {
  position: relative;
  background: linear-gradient(180deg, #17130e, #0b0a08);
  border: 1px solid var(--line-dim);
  padding: 8px 10px;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  border-radius: 2px;
  min-height: 54px;
}
.shop-item:not(.cant-afford) {
  border-color: #6e5d3c;
  box-shadow: inset 3px 0 0 rgba(240, 208, 129, 0.75);
}
.shop-item:hover { background: linear-gradient(180deg, #251d12, #110d08); border-color: var(--brass); }
.shop-item.cant-afford {
  background: linear-gradient(180deg, #0e0c09, #070604);
  border-color: #282116;
  color: #6c6251;
  cursor: not-allowed;
  filter: grayscale(0.75);
}
.shop-item.cant-afford:hover { background: linear-gradient(180deg, #0e0c09, #070604); border-color: #282116; }
.shop-item.kb-selected { background: linear-gradient(180deg, #302313, #130d07); border-color: var(--brass-bright); outline: 1px solid rgba(240, 208, 129, 0.65); }
.shop-item.cant-afford.kb-selected { background: #12100c; border-color: #5a4630; outline: 1px solid #5a4630; }

.shop-slot {
  display: inline-block;
  min-width: 84px;
  text-align: center;
  background: #090806;
  color: var(--brass);
  border: 1px solid #3a3022;
  font-size: 11px;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 0;
  margin-right: 8px;
}
.shop-effect { color: #b9b09a; font-size: 12px; margin-top: 4px; }
.shop-price  { color: var(--brass-bright); font-weight: bold; font-size: 14px; white-space: nowrap; margin-left: 14px; }
.shop-item.cant-afford .shop-slot {
  color: #665b45;
  border-color: #2b2419;
  background: #070604;
}
.shop-item.cant-afford .shop-effect,
.shop-item.cant-afford > div:first-child {
  color: #6b6252;
}
.shop-item.cant-afford .shop-price {
  color: #7d5e4e;
}
.shop-item.cant-afford .shop-price::before {
  content: "NEED ";
  color: #a35a4c;
  font-size: 11px;
  font-weight: normal;
}

.shop-close-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 8px 10px;
  background: linear-gradient(180deg, #211b12, #0c0a07);
  border: 1px solid var(--line);
  color: #cfc5ae;
  cursor: pointer;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 12px;
  border-radius: 2px;
  text-align: center;
  letter-spacing: 0.08em;
}
.shop-close-btn:hover {
  background: linear-gradient(180deg, #332817, #15100a);
  border-color: var(--brass);
  color: #fff1c3;
}

/* =====================
   Result Screen
   ===================== */
/* =====================
   Respawn Overlay（死亡 → 復活待機）
   ===================== */
#respawn-overlay[hidden] { display: none; }

#respawn-overlay {
  position: absolute;
  left: 0; top: 0;
  width: 740px; height: 500px;
  background:
    radial-gradient(circle at center, rgba(95, 25, 20, 0.24), rgba(0, 0, 0, 0.82) 60%),
    rgba(0, 0, 0, 0.72);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 28;
  font-family: "Consolas", "Courier New", monospace;
  pointer-events: none;
}

.respawn-inner { text-align: center; color: #ccc; }

.respawn-title {
  font-size: 32px;
  font-weight: bold;
  color: #d75a4f;
  margin-bottom: 18px;
  text-shadow: 0 0 14px rgba(184, 74, 61, 0.55);
}

.respawn-countdown {
  font-size: 22px;
  color: #ddd;
  margin-bottom: 14px;
}

.respawn-countdown #respawn-counter {
  display: inline-block;
  min-width: 32px;
  font-size: 36px;
  font-weight: bold;
  color: var(--brass-bright);
  margin-left: 4px;
}

.respawn-hint {
  font-size: 12px;
  color: #888;
}

#result-screen[hidden] { display: none; }

#result-screen {
  position: absolute;
  left: 0; top: 0;
  width: 740px; height: 500px;
  background:
    radial-gradient(circle at center, rgba(54, 42, 21, 0.24), rgba(0, 0, 0, 0.9) 62%),
    rgba(0, 0, 0, 0.88);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 30;
  font-family: "Consolas", "Courier New", monospace;
}

.result-inner {
  text-align: center;
  color: var(--rune);
  border: 2px solid var(--line);
  background: linear-gradient(180deg, #1b160f, #080705);
  padding: 30px 48px;
  min-width: 430px;
  box-shadow: 0 18px 55px rgba(0,0,0,0.7), inset 0 0 35px rgba(0,0,0,0.55);
}

.result-title {
  font-size: 36px;
  font-weight: bold;
  margin-bottom: 14px;
  letter-spacing: 0.08em;
}
.result-win  { color: #9bdc8a; }
.result-lose { color: #d75a4f; }

.result-detail {
  font-size: 14px;
  color: #b8ae98;
  margin-bottom: 24px;
}

.result-restart-btn {
  padding: 10px 30px;
  background: linear-gradient(180deg, #211b12, #0c0a07);
  border: 1px solid var(--line);
  color: #cfc5ae;
  cursor: pointer;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 14px;
  border-radius: 2px;
}
.result-restart-btn:hover {
  background: linear-gradient(180deg, #332817, #15100a);
  border-color: var(--brass);
  color: #fff1c3;
}

/* =====================
   全体マップ専用キャンバス
   ===================== */
#fullmap-c[hidden] { display: none; }
#fullmap-c {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 50;
  display: block;
}

/* =====================
   リセット確認ダイアログ
   ===================== */
#restart-confirm[hidden] { display: none; }

#restart-confirm {
  position: absolute;
  left: 0; top: 0;
  width: 1000px; height: 700px;
  background: rgba(0, 0, 0, 0.76);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 60;
  font-family: "Consolas", "Courier New", monospace;
}

.restart-confirm-inner {
  background: linear-gradient(180deg, #1b160f, #080705);
  border: 2px solid var(--line);
  border-radius: 3px;
  padding: 28px 40px;
  text-align: center;
  box-shadow: 0 18px 55px rgba(0,0,0,0.7), inset 0 0 35px rgba(0,0,0,0.55);
}

.restart-confirm-title {
  font-size: 19px;
  font-weight: bold;
  color: var(--brass-bright);
  margin-bottom: 8px;
}

.restart-confirm-hint {
  font-size: 12px;
  color: #9b917a;
  margin-bottom: 22px;
}

.restart-confirm-btns {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.restart-confirm-btn {
  padding: 8px 28px;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 14px;
  border-radius: 2px;
  cursor: pointer;
}

.restart-confirm-btn.yes {
  background: linear-gradient(180deg, #342116, #130d08);
  border: 1px solid #9c5f4d;
  color: #f0b6a6;
}
.restart-confirm-btn.yes:hover {
  background: linear-gradient(180deg, #47291a, #1d110b);
  border-color: #d0846a;
  color: #ffe0d6;
}

.restart-confirm-btn.no {
  background: linear-gradient(180deg, #211b12, #0c0a07);
  border: 1px solid var(--line);
  color: #cfc5ae;
}
.restart-confirm-btn.no:hover {
  background: linear-gradient(180deg, #332817, #15100a);
  border-color: var(--brass);
  color: #fff1c3;
}

/* =====================
   タイトル画面（##17 で導入）
   ===================== */
#title-screen[hidden] { display: none; }

#title-screen {
  position: absolute;
  left: 0; top: 0;
  width: 1000px; height: 700px;
  z-index: 100;
  background: #000;
  overflow: hidden;
}

#title-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(0,0,0,0.15), rgba(0,0,0,0.45)),
    radial-gradient(circle at center, transparent 40%, rgba(0,0,0,0.62) 100%);
  pointer-events: none;
}

#title-art {
  position: absolute;
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

#title-menu {
  position: absolute;
  left: 0; right: 0;
  bottom: 50px;
  text-align: center;
  font-family: "Consolas", "Courier New", monospace;
  color: #e0d4b6;
  text-shadow: 0 0 8px rgba(0, 0, 0, 0.85);
  z-index: 1;
}

.title-toggle {
  display: inline-flex;
  align-items: center;
  padding: 8px 18px;
  margin: 0 auto;
  background: rgba(8, 6, 4, 0.7);
  border: 1px solid rgba(196, 154, 74, 0.45);
  border-radius: 2px;
  cursor: pointer;
  font-size: 13px;
  user-select: none;
  transition: background 0.15s, border-color 0.15s;
}
.title-toggle:hover {
  background: rgba(28, 20, 12, 0.82);
  border-color: rgba(240, 208, 129, 0.7);
}
.title-toggle input {
  margin-right: 8px;
  cursor: pointer;
  width: 14px;
  height: 14px;
  accent-color: var(--brass);
}

#title-start-btn {
  display: block;
  margin: 0 auto 14px;
  padding: 14px 56px;
  background: linear-gradient(180deg, rgba(47, 35, 18, 0.92), rgba(10, 8, 5, 0.92));
  border: 1.5px solid var(--brass);
  color: #fff1c3;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  font-weight: bold;
  letter-spacing: 0.2em;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
#title-start-btn:hover:not(:disabled) {
  background: linear-gradient(180deg, rgba(69, 49, 24, 0.96), rgba(18, 12, 6, 0.96));
  border-color: var(--brass-bright);
  color: #fff;
  box-shadow: 0 0 18px rgba(196, 154, 74, 0.45);
}
#title-start-btn:disabled {
  background: rgba(20, 18, 14, 0.7);
  border-color: rgba(130, 112, 84, 0.4);
  color: rgba(190, 180, 154, 0.58);
  cursor: progress;
  letter-spacing: 0.1em;
}
