/* Block Commander — game UI in the CraftTheBlade pixel style */
:root {
  --bg: #0b0f1c;
  --panel: #121a2e;
  --panel-2: #1b2640;
  --steel-dark: #2b3a57;
  --steel: #5b6f8c;
  --steel-light: #9fb4d1;
  --white: #e8f1ff;
  --accent: #3d8bff;
  --accent-dark: #1f4fa3;
  --accent-glow: #7fb6ff;
  --gold: #ffd23f;
  --iron: #c9d3e0;
  --gems: #5ef0c0;
  --danger: #ff4a3a;
  --danger-dark: #a3241a;
  --ok: #5ef05e;
  --px: 4px;
  --font-pixel: "Press Start 2P", monospace;
  --font-body: "VT323", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--white);
  font-family: var(--font-body);
  font-size: 20px;
  -webkit-font-smoothing: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#app { position: fixed; inset: 0; }

#view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  cursor: grab;
}

button {
  font-family: var(--font-pixel);
  color: var(--white);
  cursor: pointer;
  border: none;
}

.hud { position: absolute; z-index: 10; }
[hidden] { display: none !important; }

/* ---------- resource bar ---------- */
#hud-top {
  top: 8px; left: 8px; right: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
#hud-top > * { pointer-events: auto; }

.res {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(11, 15, 28, 0.85);
  padding: 4px 10px 4px 6px;
  box-shadow: 0 0 0 3px #000;
  min-width: 84px;
  line-height: 1;
}
.res .val { font-size: 22px; }
.res .cap { font-size: 16px; color: var(--steel); }
.res.full .val { color: var(--gold); }

.ico {
  display: inline-block;
  width: 16px; height: 16px;
  flex-shrink: 0;
  box-shadow: inset -3px -3px 0 rgba(0,0,0,0.35), inset 3px 3px 0 rgba(255,255,255,0.35), 0 0 0 2px #000;
}
.ico.gold { background: var(--gold); }
.ico.iron { background: var(--iron); }
.ico.gems { background: var(--gems); transform: rotate(45deg) scale(0.8); }
.ico.wood { background: #b07a42; box-shadow: inset 0 -5px 0 #7a4f26, inset 0 4px 0 #d9a066, 0 0 0 2px #000; }
.ico.medal { background: #ffb02e; border-radius: 50%; }
.ico.shield { background: #7fb6ff; clip-path: polygon(50% 0, 100% 15%, 90% 70%, 50% 100%, 10% 70%, 0 15%); }
.ico.builder { background: #ff9a2e; }
.ico.time { background: var(--steel-light); border-radius: 50%; }
.ico.house { background: #c4562c; }

.icon-btn {
  margin-left: auto;
  width: 40px; height: 40px;
  font-size: 22px;
  font-family: var(--font-body);
  background: var(--panel-2);
  box-shadow: 0 0 0 3px #000, inset -3px -3px 0 var(--steel-dark), inset 3px 3px 0 var(--steel);
}

.icon-btn + .icon-btn { margin-left: 0; }
.fs-btn { display: grid; place-items: center; color: var(--steel-light); }
.fs-btn.on { color: var(--accent-glow); }
.sound-btn { position: relative; }
.sound-btn.muted { color: var(--steel); }
.sound-btn.muted::after {
  content: "";
  position: absolute;
  left: 8px; right: 8px; top: 50%;
  height: 3px;
  background: var(--danger);
  transform: rotate(-45deg);
}
.battle-btns { display: flex; gap: 12px; align-items: center; }

/* ---------- bottom buttons ---------- */
#hud-bottom {
  left: 8px; right: 8px; bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
}
#hud-bottom > * { pointer-events: auto; }
.hud-right { display: flex; gap: 10px; }

.big-btn {
  position: relative;
  font-size: 11px;
  padding: 16px 16px;
  background: var(--panel-2);
  box-shadow: 0 0 0 var(--px) #000, inset -4px -4px 0 var(--steel-dark), inset 4px 4px 0 var(--steel);
}
.big-btn:active { transform: translateY(2px); }
a.big-btn { display: inline-block; font-family: var(--font-pixel); color: var(--white); line-height: 1; }
.big-btn.attack {
  font-size: 14px;
  padding: 22px 24px;
  background: #d9482b;
  box-shadow: 0 0 0 var(--px) #000, inset -4px -4px 0 #8a2a17, inset 4px 4px 0 #ff8a5e;
}
.big-btn.primary {
  background: var(--accent);
  box-shadow: 0 0 0 var(--px) #000, inset -4px -4px 0 var(--accent-dark), inset 4px 4px 0 var(--accent-glow);
}
.big-btn.danger {
  background: var(--danger-dark);
  box-shadow: 0 0 0 var(--px) #000, inset -4px -4px 0 #5e140e, inset 4px 4px 0 var(--danger);
}
.big-btn.gem {
  background: #1e8a6a;
  box-shadow: 0 0 0 var(--px) #000, inset -4px -4px 0 #0f5a44, inset 4px 4px 0 var(--gems);
}
.big-btn[disabled], .big-btn.off { filter: grayscale(0.8) brightness(0.7); }

.badge-dot {
  position: absolute;
  top: -8px; right: -8px;
  width: 16px; height: 16px;
  background: var(--danger);
  box-shadow: 0 0 0 3px #000;
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0.3; } }

.chip {
  left: 8px;
  bottom: 96px;
  background: rgba(11, 15, 28, 0.85);
  box-shadow: 0 0 0 3px #000;
  padding: 4px 10px;
  font-size: 18px;
  pointer-events: none;
}

.weather-chip {
  bottom: 136px;
  pointer-events: auto;
  cursor: pointer;
  color: inherit;
  font-family: inherit;
  border: 0;
  display: flex; align-items: center; gap: 8px;
}
.weather-chip .wx { width: 18px; height: 18px; image-rendering: pixelated; }
.weather-chip.snow { color: #dff1ff; }
.weather-chip.thunder { color: #ffd23f; }
.weather-chip.rain { color: #9cc4ff; }

/* ---------- tutorial ---------- */
.tut {
  left: 50%; top: 100px;
  transform: translateX(-50%);
  width: min(460px, calc(100% - 32px));
  background: rgba(11, 15, 28, 0.94);
  box-shadow: 0 0 0 3px #000, 0 0 0 6px #ffd23f;
  padding: 12px 14px;
  font-size: 18px;
  line-height: 1.35;
  pointer-events: auto;
  z-index: 30;
}
.tut h3 { margin: 0 0 6px; font-size: 20px; color: #ffd23f; }
.tut p { margin: 0 0 10px; }
.tut .tut-row { display: flex; gap: 8px; justify-content: space-between; align-items: center; }
.tut .tut-step { opacity: 0.7; font-size: 15px; }
.tut .big-btn { padding: 6px 12px; font-size: 16px; }
.tut-skip {
  background: none; border: 0; padding: 4px 6px; margin-right: 6px;
  color: #9aa6c0; font: inherit; font-size: 15px; text-decoration: underline; cursor: pointer;
}
.tut-arrow {
  position: absolute;
  width: 0; height: 0;
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
  border-top: 22px solid #ffd23f;
  filter: drop-shadow(0 3px 0 #000);
  transform: translate(-50%, -100%);
  pointer-events: none;
  z-index: 29;
  animation: tut-bob 0.7s steps(2) infinite;
}
@keyframes tut-bob { 50% { margin-top: -8px; } }
.tut-glow { box-shadow: 0 0 0 3px #000, 0 0 0 6px #ffd23f !important; }

/* ---------- building sheet ---------- */
.sheet {
  position: absolute;
  z-index: 20;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 16px));
  max-height: 60vh;
  overflow-y: auto;
  background: var(--panel);
  box-shadow: 0 0 0 var(--px) #000, inset 0 0 0 var(--px) var(--steel-dark);
  padding: 14px 16px 16px;
}

.sheet h2, #modal h2 {
  font-family: var(--font-pixel);
  font-weight: normal;
  font-size: 13px;
  margin: 0 0 6px;
  line-height: 1.5;
}
.sheet h2 small { color: var(--accent-glow); font-size: 11px; }
.sheet p, #modal p { margin: 0 0 10px; color: var(--steel-light); line-height: 1.15; }

.close-x {
  position: absolute;
  top: 8px; right: 8px;
  width: 32px; height: 32px;
  font-family: var(--font-body);
  font-size: 24px;
  background: transparent;
  color: var(--steel-light);
}
.close-x:hover { color: var(--white); }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 4px 14px;
  margin: 8px 0 12px;
  font-size: 19px;
}
.stats div { display: flex; justify-content: space-between; gap: 8px; border-bottom: 2px solid var(--panel-2); }
.stats span:first-child { color: var(--steel); }
.stats .up { color: var(--ok); }

.actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.actions .big-btn { display: inline-flex; align-items: center; gap: 8px; }
.why { color: var(--danger); font-size: 18px; }
.hint { color: var(--steel); font-size: 17px; }

.progress {
  height: 14px;
  background: #000;
  padding: 2px;
  margin: 6px 0 10px;
}
.progress > i { display: block; height: 100%; background: var(--gold); }

/* ---------- modal ---------- */
#modal-back {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: rgba(5, 8, 15, 0.7);
  display: grid;
  place-items: center;
  padding: 12px;
}
#modal {
  position: relative;
  width: min(760px, 100%);
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  background: var(--panel);
  box-shadow: 0 0 0 var(--px) #000, inset 0 0 0 var(--px) var(--steel-dark);
  padding: 20px;
}
#modal h1 {
  font-family: var(--font-pixel);
  font-weight: normal;
  font-size: clamp(14px, 3.5vw, 20px);
  margin: 0 0 14px;
  line-height: 1.4;
  text-shadow: 3px 3px 0 var(--accent-dark);
}

.tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.tab {
  font-size: 10px;
  padding: 10px 12px;
  background: var(--panel-2);
  color: var(--steel-light);
  box-shadow: 0 0 0 3px #000;
}
.tab.on { background: var(--accent-dark); color: var(--white); box-shadow: 0 0 0 3px #000, inset 0 0 0 3px var(--accent); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}
.card {
  position: relative;
  text-align: left;
  font-family: var(--font-body);
  font-size: 18px;
  background: var(--panel-2);
  color: var(--white);
  padding: 10px;
  box-shadow: 0 0 0 3px #000, inset -3px -3px 0 var(--steel-dark), inset 3px 3px 0 var(--steel);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 150px;
}
.card:hover:not(.off) { outline: 3px solid var(--accent); }
.card.off { filter: grayscale(0.6) brightness(0.75); cursor: default; }
.card h3 { font-family: var(--font-pixel); font-weight: normal; font-size: 10px; margin: 0; line-height: 1.5; }
.card canvas { align-self: center; image-rendering: pixelated; }
.card .row { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.card .cnt { color: var(--steel-light); }
.card .why { font-size: 16px; }
.card .count-badge {
  position: absolute; top: 6px; right: 6px;
  font-family: var(--font-pixel); font-size: 10px;
  background: var(--accent); padding: 4px 6px; box-shadow: 0 0 0 2px #000;
}
.cost { display: inline-flex; align-items: center; gap: 6px; }
.cost.short { color: var(--danger); }

/* faction choice */
.factions { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.faction {
  font-family: var(--font-body);
  text-align: left;
  font-size: 19px;
  padding: 16px;
  background: var(--panel-2);
  box-shadow: 0 0 0 var(--px) #000;
  display: flex; flex-direction: column; gap: 10px;
}
.faction h3 { font-family: var(--font-pixel); font-weight: normal; font-size: 13px; margin: 0; }
.faction .tag { color: var(--white); }
.faction p { margin: 0; color: var(--steel-light); }
.faction.iron { box-shadow: 0 0 0 var(--px) #000, inset 0 0 0 var(--px) #4f7db3; }
.faction.ember { box-shadow: 0 0 0 var(--px) #000, inset 0 0 0 var(--px) #c4562c; }
.faction:hover { transform: translateY(-3px); }

/* mission list */
.missions { display: flex; flex-direction: column; gap: 10px; }
.mission {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  background: var(--panel-2);
  box-shadow: 0 0 0 3px #000;
}
.mission.locked { opacity: 0.5; }
.mission .num { font-family: var(--font-pixel); font-size: 14px; color: var(--accent-glow); text-align: center; }
.mission h3 { font-family: var(--font-pixel); font-weight: normal; font-size: 10px; margin: 0 0 4px; }
.mission .meta { font-size: 17px; color: var(--steel-light); display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.stars { display: inline-flex; gap: 3px; }
.star { width: 14px; height: 14px; background: #333; box-shadow: 0 0 0 2px #000; clip-path: polygon(50% 0, 62% 35%, 100% 38%, 70% 60%, 80% 100%, 50% 77%, 20% 100%, 30% 60%, 0 38%, 38% 35%); }
.star.on { background: var(--gold); }

.army-line { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 14px; font-size: 18px; }
.army-line span { background: var(--panel-2); padding: 2px 8px; box-shadow: 0 0 0 2px #000; }

/* goals */
.goal { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 3px solid var(--panel-2); }
.goal.claimed { opacity: 0.45; }
.goal .gtext { font-size: 20px; }

/* training */
.queue { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; min-height: 34px; }
.q-item {
  font-family: var(--font-body);
  font-size: 18px;
  background: var(--panel-2);
  padding: 4px 8px;
  box-shadow: 0 0 0 2px #000;
}
.q-item b { color: var(--danger); margin-left: 6px; }

/* lodge / pickers */
.pills { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.pill {
  font-family: var(--font-body); font-size: 18px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; background: var(--panel-2); box-shadow: 0 0 0 2px #000;
}
.pill.on { background: var(--accent-dark); box-shadow: 0 0 0 2px #000, inset 0 0 0 2px var(--accent-glow); }
.crew { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.crew-row { display: grid; grid-template-columns: 48px 1fr 34px 30px 34px; align-items: center; gap: 6px; font-size: 18px; }
.crew-row b { text-align: center; }
.trip { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 2px solid var(--panel-2); font-size: 18px; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 2px solid var(--panel-2); font-size: 19px; flex-wrap: wrap; }
.list-row .grow { flex: 1; min-width: 120px; }
.list-row small { color: var(--steel-light); }
.field { width: 100%; font-family: var(--font-body); font-size: 20px; color: var(--white); background: var(--bg); border: 3px solid var(--steel-dark); padding: 6px 8px; }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

/* ---------- battle ---------- */
#battle-top {
  top: 8px; left: 8px; right: 8px;
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
  pointer-events: none;
}
.b-box {
  background: rgba(11, 15, 28, 0.88);
  box-shadow: 0 0 0 3px #000;
  padding: 6px 12px;
  text-align: center;
  min-width: 92px;
}
.b-label { font-size: 16px; color: var(--steel-light); }
.b-big { font-family: var(--font-pixel); font-size: 14px; margin-top: 4px; }
.b-stars { display: flex; gap: 4px; justify-content: center; }
.b-stars .star { width: 18px; height: 18px; }
.b-box.loot { text-align: left; font-size: 20px; display: flex; flex-direction: column; gap: 2px; }
.b-box.loot div { display: flex; gap: 8px; align-items: center; }

#battle-bottom {
  left: 8px; right: 8px; bottom: 10px;
  display: flex; gap: 12px; align-items: flex-end; justify-content: space-between;
}
#troop-bar { display: flex; gap: 10px; overflow-x: auto; padding: 6px; }
.troop {
  position: relative;
  font-family: var(--font-body);
  font-size: 16px;
  width: 78px;
  padding: 6px 4px;
  background: var(--panel-2);
  box-shadow: 0 0 0 3px #000;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  flex-shrink: 0;
}
.troop.on { background: var(--accent-dark); box-shadow: 0 0 0 3px #000, inset 0 0 0 3px var(--accent-glow); }
.troop.empty { filter: grayscale(1) brightness(0.5); }
.troop .n { position: absolute; top: 2px; right: 4px; font-family: var(--font-pixel); font-size: 9px; }
#battle-hint {
  left: 50%; top: 84px; transform: translateX(-50%);
  background: rgba(11, 15, 28, 0.88); box-shadow: 0 0 0 3px #000;
  padding: 6px 12px; font-size: 19px; pointer-events: none; text-align: center;
}

.result-stars { display: flex; gap: 14px; justify-content: center; margin: 10px 0 18px; }
.result-stars .star { width: 52px; height: 52px; }
.result-line { display: flex; gap: 20px; justify-content: center; flex-wrap: wrap; font-size: 24px; margin-bottom: 18px; }
.result-line div { display: flex; gap: 8px; align-items: center; }

#visit-bar {
  top: 8px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: center;
  background: rgba(11, 15, 28, 0.9); box-shadow: 0 0 0 3px #000; padding: 8px 12px; font-size: 20px;
  max-width: calc(100% - 16px);
}

/* ---------- toast ---------- */
#toast {
  position: absolute;
  z-index: 60;
  left: 50%;
  top: 64px;
  transform: translateX(-50%);
  pointer-events: none;
  display: flex; flex-direction: column; gap: 6px; align-items: center;
}
#toast div {
  background: #000;
  color: var(--white);
  padding: 6px 14px;
  font-size: 20px;
  box-shadow: 0 0 0 3px var(--steel-dark);
  animation: toast 2.4s steps(6) forwards;
}
#toast div.bad { color: #ff9a8a; }
#toast div.good { color: var(--ok); }
@keyframes toast { 0% { opacity: 0; } 8% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }

.legal { font-size: 16px; color: var(--steel); margin-top: 16px; }
a { color: var(--accent-glow); }

@media (max-width: 560px) {
  html, body { font-size: 18px; }
  .res { min-width: 0; padding: 3px 8px 3px 5px; }
  .res .val { font-size: 19px; }
  .res .cap { display: none; }
  .big-btn { font-size: 9px; padding: 13px 11px; }
  .big-btn.attack { font-size: 11px; padding: 18px 16px; }
  .chip { bottom: 80px; }
  .weather-chip { bottom: 116px; }
  .tut { top: 96px; font-size: 16px; }
  .troop { width: 66px; }
}
