* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  background: #1a1a2e;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  font-family: "Press Start 2P", monospace;
}

.game-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  width: 100%;
  min-height: 0;
  border: none;
  box-shadow: none;
}

#game {
  display: block;
  flex: 1;
  width: 100%;
  min-height: 240px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  vertical-align: top;
}

.game-dock-tooltip {
  position: absolute;
  z-index: 12;
  max-width: min(420px, 92vw);
  padding: 10px 14px;
  font-family: "Press Start 2P", monospace;
  font-size: 10px;
  line-height: 1.65;
  color: #ecf0f1;
  background: linear-gradient(180deg, #243447 0%, #1b2636 100%);
  border: 2px solid #5dade2;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.6),
    3px 3px 0 rgba(0, 0, 0, 0.45);
  pointer-events: none;
  white-space: normal;
  word-break: break-word;
}

.game-dock-tooltip.hidden {
  display: none !important;
}

/* Village progression — parchment/gold UI inspired by Towers */
.village-open-btn {
  position: absolute;
  right: 18px;
  top: 18px;
  z-index: 15;
  padding: 11px 15px;
  color: #f5e6c8;
  font: 9px/1.4 "Press Start 2P", monospace;
  background: linear-gradient(180deg, #594027, #2d1d12);
  border: 2px solid #c9a66b;
  border-radius: 8px;
  box-shadow: 0 4px 0 #130c07;
  cursor: pointer;
}

.village-open-btn:hover {
  color: #fff4c7;
  border-color: #f0cf7c;
  transform: translateY(-1px);
}

.village-open-btn.hidden,
.village-spell-bar.hidden,
.village-panel.hidden,
.battle-controls.hidden {
  display: none !important;
}

/* Battle HUD controls — Towers-style mini buttons */
.battle-controls {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 22;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  max-width: min(420px, 92vw);
  pointer-events: auto;
}

.battle-controls .btn-mini {
  appearance: none;
  padding: 7px 10px;
  color: #f5e6c8;
  font: 700 10px/1.3 "Press Start 2P", monospace;
  background: rgba(60, 40, 20, 0.9);
  border: 1px solid #c9a66b;
  border-radius: 8px;
  box-shadow: 0 2px 0 #1a1208;
  cursor: pointer;
}

.battle-controls .btn-mini:hover {
  filter: brightness(1.15);
  border-color: #f0cf7c;
}

.battle-controls .btn-mini.on {
  color: #1a1208;
  background: linear-gradient(#f0cf7c, #b98835);
  border-color: #ffe5a0;
}

.village-panel {
  position: absolute;
  inset: 0;
  z-index: 50;
  overflow: auto;
  padding: 18px;
  color: #f5e6c8;
  background:
    radial-gradient(circle at 50% 10%, rgba(127, 89, 45, 0.26), transparent 45%),
    rgba(15, 12, 10, 0.96);
  font: 10px/1.65 "Press Start 2P", monospace;
}

.village-panel-frame {
  position: relative;
  width: min(1160px, 100%);
  min-height: calc(100% - 4px);
  margin: 0 auto;
  padding: 18px 20px 58px;
  background: linear-gradient(145deg, #3d2a18, #1c120a 70%);
  border: 3px solid #c9a66b;
  border-radius: 12px;
  box-shadow: 0 0 0 2px #211307, 0 18px 40px rgba(0, 0, 0, 0.62);
}

.village-close {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 2;
  width: 36px;
  height: 36px;
  color: #f5e6c8;
  font: 22px/30px Georgia, serif;
  background: #4a2918;
  border: 2px solid #c9a66b;
  border-radius: 6px;
  cursor: pointer;
}

.village-head {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  padding: 4px 50px 14px 2px;
  border-bottom: 1px solid rgba(201, 166, 107, 0.45);
}

.village-kicker {
  color: #d4af37;
  font-size: 7px;
  letter-spacing: 0.18em;
}

.village-head h2 {
  margin: 7px 0 0;
  color: #fff0c2;
  font-size: clamp(14px, 2.4vw, 24px);
  line-height: 1.35;
}

.village-currencies {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.village-currencies span,
.loadout-summary span {
  padding: 8px 10px;
  color: #d8c9ac;
  background: rgba(10, 7, 4, 0.52);
  border: 1px solid #80663d;
  border-radius: 7px;
  white-space: nowrap;
}

.village-currencies b,
.loadout-summary b {
  color: #facc15;
}

.village-nav {
  display: flex;
  gap: 6px;
  padding: 13px 0;
  overflow-x: auto;
}

.village-nav button,
.village-action,
.squad-card button,
.spell-card button,
.defense-actions button,
.quest-row button {
  padding: 10px 12px;
  color: #ead8b4;
  font: 8px/1.45 "Press Start 2P", monospace;
  background: linear-gradient(#4d3521, #2a1b10);
  border: 1px solid #9b7845;
  border-radius: 6px;
  cursor: pointer;
}

.village-nav button.active,
.village-action.primary,
.defense-actions .primary,
.quest-row.claimable button {
  color: #1a1208;
  background: linear-gradient(#f0cf7c, #b98835);
  border-color: #ffe5a0;
}

.village-nav button:hover,
.village-action:hover,
.squad-card button:hover:not(:disabled),
.spell-card button:hover:not(:disabled),
.defense-actions button:hover,
.quest-row button:hover:not(:disabled) {
  filter: brightness(1.18);
}

.village-body {
  min-height: 440px;
}

.village-city-layout {
  display: grid;
  grid-template-columns: minmax(460px, 1.6fr) minmax(270px, 0.8fr);
  gap: 16px;
}

.village-map {
  position: relative;
  min-height: 500px;
  overflow: hidden;
  background:
    linear-gradient(90deg, transparent 49%, rgba(209, 184, 132, 0.18) 50%, transparent 51%),
    radial-gradient(ellipse at 50% 65%, #766342 0 10%, transparent 10.5%),
    linear-gradient(145deg, #405930, #243b28 58%, #173124);
  border: 2px solid #9f814e;
  border-radius: 10px;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.55);
}

.village-map::before {
  content: "";
  position: absolute;
  inset: 8%;
  border: 10px solid rgba(166, 145, 97, 0.38);
  border-radius: 46% 48% 42% 44%;
  transform: rotate(-2deg);
}

.village-map-building {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 128px;
  min-height: 76px;
  padding: 7px 5px;
  transform: translate(-50%, -50%);
  color: #f6e8c8;
  text-align: center;
  font: 7px/1.45 "Press Start 2P", monospace;
  background: linear-gradient(#765234, #3d2818);
  border: 2px solid #a98a59;
  border-radius: 8px 8px 3px 3px;
  box-shadow: 0 6px 0 #21150e, 0 8px 12px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}

.village-map-building .building-icon {
  display: block;
  margin-bottom: 4px;
  font: 25px/1 "Segoe UI Symbol", sans-serif;
}

.village-map-building strong,
.village-map-building small {
  display: block;
}

.village-map-building small {
  margin-top: 4px;
  color: #d0bd9a;
  font-size: 6px;
}

.village-map-building.locked {
  opacity: 0.42;
  filter: grayscale(0.8);
}

.village-map-building.ready {
  border-color: #f0cf7c;
  animation: village-ready 1.8s ease-in-out infinite;
}

.village-map-building.selected {
  outline: 3px solid #facc15;
  outline-offset: 3px;
}

@keyframes village-ready {
  50% { box-shadow: 0 6px 0 #21150e, 0 0 18px rgba(250, 204, 21, 0.5); }
}

.village-detail,
.squad-card,
.spell-card,
.defense-scene,
.quest-group,
.quests-layout > aside {
  padding: 16px;
  background: linear-gradient(145deg, rgba(85, 58, 34, 0.88), rgba(32, 20, 12, 0.94));
  border: 1px solid #9d7c49;
  border-radius: 9px;
}

.detail-title,
.squad-card header,
.spell-card header,
.defense-scene > header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.detail-title > span,
.squad-card header > span,
.spell-card header > span {
  font: 28px/1 "Segoe UI Symbol", sans-serif;
}

.village-detail h3,
.squad-card h3,
.spell-card h4,
.defense-scene h3,
.quest-group h3,
.quests-layout aside h3 {
  margin: 0;
  color: #f0d9a0;
  font-size: 11px;
  line-height: 1.5;
}

.village-detail p,
.squad-card p,
.spell-card p,
.village-empty p {
  color: #d0c0a3;
}

.requirement,
.locked-note {
  color: #e6a268 !important;
}

.village-actions,
.squad-actions,
.defense-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 15px;
}

.village-max {
  color: #8fdb90;
}

.loadout-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 12px;
}

.squad-grid,
.spell-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.squad-card.disabled,
.spell-card.locked {
  opacity: 0.52;
}

.squad-card header {
  align-items: flex-start;
}

.squad-card header > div {
  flex: 1;
}

.squad-focus {
  padding: 7px !important;
  font-size: 6px !important;
}

.squad-focus.active {
  color: #201509;
  background: #facc15;
}

.gear-list {
  margin-top: 13px;
  border-top: 1px solid rgba(201, 166, 107, 0.35);
}

.gear-list h4 {
  color: #dec28a;
  font-size: 7px;
}

.gear-option {
  display: flex;
  width: 100%;
  justify-content: space-between;
  gap: 8px;
  margin-top: 5px;
  padding: 8px !important;
  text-align: left;
}

.gear-option small {
  font-size: 5px;
}

.gear-option.equipped {
  border-color: #facc15;
  color: #facc15;
}

.magic-head {
  margin-bottom: 12px;
}

.spell-card {
  min-height: 220px;
}

.spell-card > small {
  display: block;
  margin: 10px 0;
  color: #af9c7d;
}

.spell-card.known {
  border-color: #d4af37;
}

.village-empty {
  padding: 80px 30px;
  text-align: center;
  border: 1px dashed #9d7c49;
}

.defense-scene {
  max-width: 820px;
  margin: 0 auto;
}

.defense-scene > header {
  justify-content: space-between;
}

.wave-badge {
  padding: 9px;
  color: #1b1209;
  background: #d4af37;
  border-radius: 5px;
}

.defense-field {
  position: relative;
  height: 160px;
  margin: 15px 0;
  overflow: hidden;
  background: linear-gradient(#334c2e 64%, #6c5433 64%);
  border: 2px solid #80663d;
  border-radius: 8px;
}

.defense-gate,
.defense-squads,
.defense-enemies {
  position: absolute;
  bottom: 27px;
}

.defense-gate {
  left: 4%;
  padding: 36px 12px 10px;
  color: #cfb781;
  background: #54493f;
  border: 4px solid #2d2722;
}

.defense-squads {
  left: 28%;
  font-size: 28px;
}

.defense-enemies {
  right: 7%;
  font-size: 30px;
}

.meter {
  height: 12px;
  margin: 5px 0 11px;
  overflow: hidden;
  background: #17100b;
  border: 1px solid #82663e;
  border-radius: 6px;
}

.meter i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #487b38, #8ed15e);
}

.meter.enemy i {
  background: linear-gradient(90deg, #7e2e26, #d85c3f);
}

.defense-log {
  margin-top: 12px;
  padding: 8px 12px;
  color: #bfae91;
  background: rgba(0, 0, 0, 0.25);
}

.defense-log p {
  margin: 5px 0;
}

.quests-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(270px, 0.65fr);
  gap: 12px;
}

.quest-group {
  margin-bottom: 10px;
}

.quest-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  margin-top: 8px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(157, 124, 73, 0.5);
}

.quest-row h4 {
  margin: 0 0 5px;
  color: #ead8b4;
  font-size: 8px;
}

.quest-row.claimed {
  opacity: 0.5;
}

.quest-reward {
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: flex-end;
  color: #d4af37;
  font-size: 6px;
}

.achievement-grid {
  display: grid;
  gap: 7px;
}

.title-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 9px 0 18px;
}

.title-chip {
  padding: 7px 9px;
  color: #bba98b;
  font: 6px/1.4 "Press Start 2P", monospace;
  background: #291b10;
  border: 1px solid #735b39;
  border-radius: 5px;
}

.title-chip.active {
  color: #211508;
  background: #d4af37;
  border-color: #f0cf7c;
}

.achievement {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 5px 8px;
  padding: 9px;
  opacity: 0.32;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid #6d5737;
}

.achievement.on {
  opacity: 1;
  border-color: #d4af37;
}

.achievement > span {
  grid-row: 1 / 3;
  font-size: 23px;
}

.achievement small {
  color: #ac9c83;
  font-size: 5px;
}

.village-status {
  position: absolute;
  left: 20px;
  right: 65px;
  bottom: 10px;
  min-height: 20px;
  margin: 0;
  color: #8fdb90;
}

.village-status.is-bad {
  color: #ff8875;
}

.village-spell-bar {
  position: absolute;
  z-index: 18;
  left: 50%;
  bottom: 18px;
  display: flex;
  gap: 5px;
  align-items: center;
  max-width: 90%;
  padding: 7px;
  transform: translateX(-50%);
  background: rgba(25, 16, 35, 0.93);
  border: 2px solid #a574c1;
  border-radius: 8px;
}

.village-spell-bar > span {
  color: #d9b3ef;
  font: 7px/1.3 "Press Start 2P", monospace;
  white-space: nowrap;
}

.village-spell-bar button {
  padding: 8px;
  color: #efe0ff;
  font: 7px/1.3 "Press Start 2P", monospace;
  background: #473055;
  border: 1px solid #b98bd2;
  border-radius: 5px;
  cursor: pointer;
}

@media (max-width: 780px) {
  .village-panel {
    padding: 5px;
  }
  .village-panel-frame {
    padding: 12px 10px 55px;
  }
  .village-head,
  .village-city-layout,
  .quests-layout {
    display: block;
  }
  .village-currencies {
    justify-content: flex-start;
    margin-top: 10px;
  }
  .village-map {
    min-height: 430px;
  }
  .village-detail {
    margin-top: 10px;
  }
  .squad-grid,
  .spell-grid {
    grid-template-columns: 1fr;
  }
  .village-map-building {
    width: 100px;
    font-size: 6px;
  }
}

.menu-panel {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 20;
  overflow-y: auto;
  background: rgba(18, 22, 42, 0.94);
  color: #dce0f0;
  font-size: 10px;
  line-height: 1.65;
}

.menu-panel.hidden {
  display: none !important;
}

.menu-panel-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 24px 28px;
}

.menu-title {
  margin: 0 0 14px;
  font-size: 14px;
  color: #85c1e9;
  letter-spacing: 0.02em;
}

.menu-subtitle {
  margin: 18px 0 10px;
  font-size: 10px;
  color: #aab6d6;
}

.menu-msg {
  min-height: 1.4em;
  margin: 0 0 12px;
  color: #f5b041;
  font-size: 9px;
}

.menu-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.menu-btn {
  font-family: inherit;
  font-size: 9px;
  padding: 10px 14px;
  min-height: 36px;
  cursor: pointer;
  border: 2px solid #4a5f8a;
  background: #2c3558;
  color: #e8ecff;
  line-height: 1.4;
}

.menu-btn:hover {
  background: #3d4a78;
  border-color: #6d8cc4;
}

.menu-btn-primary {
  background: #1e4d6b;
  border-color: #5dade2;
}

.menu-save-block {
  margin-bottom: 12px;
}

.menu-label {
  display: block;
  margin-bottom: 8px;
  color: #aab6d6;
  font-size: 9px;
}

.menu-save-input-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.menu-save-input-row input {
  flex: 1;
  min-width: 140px;
  font-family: inherit;
  font-size: 9px;
  padding: 8px 10px;
  min-height: 34px;
  border: 2px solid #4a5f8a;
  background: #16213e;
  color: #e8ecff;
}

.menu-note {
  margin: 0 0 10px;
  font-size: 8px;
  line-height: 1.55;
  color: #8892b0;
}

.menu-saves-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.menu-saves-list > li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 10px 0;
  border-bottom: 1px solid #2a3555;
}

.menu-saves-list .menu-save-meta {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  font-size: 9px;
  line-height: 1.5;
  word-break: break-word;
}

.menu-saves-list .menu-save-actions {
  display: flex;
  flex-shrink: 0;
  gap: 6px;
  flex-wrap: wrap;
}

.menu-saves-list .menu-btn-small {
  padding: 8px 10px;
  font-size: 8px;
  min-height: 32px;
}

.menu-empty {
  color: #8892b0;
  padding: 10px 0;
  font-size: 9px;
  border: none;
}

.char-create-panel {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 25;
  overflow-y: auto;
  background: rgba(14, 18, 32, 0.96);
  color: #dce0f0;
  font-size: 10px;
  line-height: 1.65;
}

.char-create-panel.hidden {
  display: none !important;
}

.char-create-inner {
  max-width: 520px;
  margin: 0 auto;
  padding: 18px 22px 24px;
}

.char-create-title {
  margin: 0 0 8px;
  font-size: 14px;
  color: #85c1e9;
  letter-spacing: 0.02em;
}

.char-create-sub {
  margin: 0 0 12px;
  font-size: 8px;
  color: #8892b0;
  line-height: 1.55;
}

.char-preview-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
}

#char-preview {
  display: block;
  width: 80px;
  height: 80px;
  border: 2px solid #4a5f8a;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #1b2636;
}

.char-section {
  margin-bottom: 12px;
}

.char-label {
  display: block;
  margin-bottom: 6px;
  color: #aab6d6;
  font-size: 9px;
}

.char-swatches,
.char-expr-row,
.char-hats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.char-swatch {
  width: 44px;
  height: 44px;
  border: 2px solid #4a5f8a;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.char-swatch:hover,
.char-swatch.selected {
  border-color: #85c1e9;
  box-shadow: 0 0 0 1px rgba(133, 193, 233, 0.45);
}

.char-chip {
  font-family: inherit;
  font-size: 8px;
  padding: 8px 10px;
  min-height: 32px;
  line-height: 1.35;
  cursor: pointer;
  border: 2px solid #4a5f8a;
  background: #2c3558;
  color: #e8ecff;
}

.char-chip:hover,
.char-chip.selected {
  border-color: #5dade2;
  background: #34495e;
}

.char-hat-btn {
  min-width: 0;
  max-width: 100%;
  font-family: inherit;
  font-size: 8px;
  padding: 8px 10px;
  min-height: 32px;
  line-height: 1.35;
  cursor: pointer;
  border: 2px solid #4a5f8a;
  background: #243044;
  color: #dce0f0;
  text-align: center;
}

.char-hat-btn:hover,
.char-hat-btn.selected {
  border-color: #f1c40f;
  background: #2c3e50;
}

.char-create-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
  padding-top: 4px;
}

.char-create-actions .menu-btn {
  flex: 1 1 auto;
  min-width: 120px;
}

#game:focus {
  outline: none;
}

#game:focus-visible {
  outline: 2px solid #5dade2;
  outline-offset: 4px;
}
