:root {
  color-scheme: dark;
  --bg: #0b1016;
  --panel: rgba(14, 20, 28, 0.86);
  --panel-strong: #111a24;
  --text: #e7eef7;
  --muted: #9eb0c2;
  --accent: #79d1ff;
  --accent-2: #ffcf6f;
  --line: rgba(255, 255, 255, 0.12);
  --shadow: 0 30px 70px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(121, 209, 255, 0.18), transparent 35%),
    radial-gradient(circle at right top, rgba(255, 207, 111, 0.12), transparent 28%),
    linear-gradient(180deg, #0b1016 0%, #0d1320 100%);
  color: var(--text);
  font-family: "Segoe UI", "Noto Sans JP", sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.5), transparent);
}

.shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 32px 0 40px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 8px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--accent);
  font-size: 12px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(32px, 4vw, 58px);
  line-height: 0.95;
  margin-bottom: 12px;
}

.lede {
  max-width: 68ch;
  color: var(--muted);
  line-height: 1.7;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.zoomControl {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  box-shadow: var(--shadow);
}

.zoomControl span {
  font-size: 12px;
  color: var(--muted);
  min-width: 42px;
  text-align: right;
}

.zoomControl input[type="range"] {
  width: 140px;
}

button {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  padding: 12px 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  box-shadow: var(--shadow);
}

button.primary {
  background: linear-gradient(135deg, #71cdf6, #3f87c9);
  color: #ffffff;
}

button.secondary {
  background: rgba(255, 255, 255, 0.06);
}

.board {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: start;
}

.canvasWrap,
.panel {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.canvasWrap {
  min-height: 720px;
  position: relative;
}

.gameControls {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: min(52vw, 420px);
}

.gameControls button {
  padding: 9px 12px;
  font-size: 12px;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.28);
}

canvas {
  width: 100%;
  height: auto;
  display: block;
  cursor: pointer;
  touch-action: none;
}

.panel {
  padding: 20px;
  background: linear-gradient(180deg, rgba(17, 26, 36, 0.96), rgba(9, 14, 20, 0.92));
}

.bootStatus {
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(121, 209, 255, 0.35);
  border-radius: 14px;
  background: rgba(121, 209, 255, 0.08);
  color: #bfe9ff;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.unitCard {
  margin-top: 4px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
}

.unitInfo {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.unitInfoTitle {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.unitInfoBody {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.unitHpWrap {
  display: grid;
  gap: 4px;
}

.unitHpBar {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.unitHpFill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #83ffb7, #ffcc66);
}

.unitHpLabel {
  color: var(--text);
  font-size: 11px;
  letter-spacing: 0.02em;
}

.unitActions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.unitCardOverlay,
.enemyCardOverlay {
  position: absolute;
  bottom: 16px;
  z-index: 2;
  width: min(132px, calc(100% - 32px));
  margin-top: 0;
  background: rgba(10, 16, 22, 0.82);
  backdrop-filter: blur(12px);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.35);
}

.unitCardOverlay {
  left: 16px;
}

.enemyCardOverlay {
  position: absolute;
  right: 16px;
}

.abilityCardOverlay {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 2;
  width: min(240px, calc(100% - 32px));
  margin-top: 0;
  background: rgba(10, 16, 22, 0.82);
  backdrop-filter: blur(12px);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.35);
}

.abilityCardOverlay h3 {
  margin-bottom: 6px;
  font-size: 12px;
}

.abilityCardOverlay .abilityList {
  gap: 8px;
}

.abilityCardOverlay .abilityButton {
  padding: 10px 12px;
}

.unitCardOverlay h3,
.enemyCardOverlay h3 {
  margin-bottom: 6px;
  font-size: 12px;
}

.attackFxOverlay {
  position: absolute;
  left: 50%;
  bottom: 78px;
  transform: translateX(-50%) rotate(-11deg);
  z-index: 2;
  width: min(320px, 42vw);
  height: 22px;
  pointer-events: none;
  display: grid;
  place-items: center;
  overflow: visible;
}

.attackFxSlash {
  position: absolute;
  inset: 50% 0 auto;
  height: 4px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    rgba(255, 120, 120, 0) 0%,
    rgba(255, 120, 120, 0.95) 18%,
    rgba(255, 208, 120, 0.98) 50%,
    rgba(255, 120, 120, 0.95) 82%,
    rgba(255, 120, 120, 0) 100%
  );
  box-shadow:
    0 0 18px rgba(255, 122, 122, 0.7),
    0 0 30px rgba(255, 198, 102, 0.35);
  animation: attackSlashPulse 220ms ease-out;
}

.attackFxLabel {
  position: relative;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(9, 14, 20, 0.92);
  color: #ffe9c0;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  border: 1px solid rgba(255, 208, 120, 0.35);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
}

@keyframes attackSlashPulse {
  0% {
    transform: translateY(-50%) scaleX(0.3);
    opacity: 0.15;
  }
  60% {
    transform: translateY(-50%) scaleX(1.08);
    opacity: 1;
  }
  100% {
    transform: translateY(-50%) scaleX(1);
    opacity: 0.9;
  }
}

.unitCardHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin: 0 0 6px;
  gap: 8px;
}

.unitCardHeader span {
  min-width: 0;
  color: #ffffff;
}

.unitPanelClose {
  width: auto;
  min-width: 0;
  height: auto;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: 14px;
  line-height: 1;
  box-shadow: none;
  display: inline-block;
  flex: 0 0 auto;
  color: var(--muted);
}

.unitCardHeader .unitPanelClose {
  flex: 0 0 auto;
  margin-left: auto;
  padding: 0;
}

.unitPanelClose:hover {
  background: transparent;
  color: var(--text);
}

.unitCardOverlay .unitInfoTitle,
.enemyCardOverlay .unitInfoTitle {
  font-size: 12px;
  color: #ffffff;
}

.unitCardOverlay .unitInfoBody,
.unitCardOverlay .statusLine,
.enemyCardOverlay .unitInfoBody,
.enemyCardOverlay .statusLine {
  font-size: 10px;
  line-height: 1.35;
  color: #ffffff;
}

.unitCardOverlay .unitActions,
.enemyCardOverlay .unitActions {
  gap: 6px;
  margin-top: 8px;
}

.unitCardOverlay button,
.enemyCardOverlay button {
  padding: 7px 10px;
  font-size: 11px;
  flex: 1 1 72px;
}

.abilityButton strong,
.abilityButton small {
  color: #ffffff;
}

.unitCardOverlay .unitHpLabel,
.enemyCardOverlay .unitHpLabel {
  color: #ffffff;
}

.stats {
  display: grid;
  gap: 12px;
}

.stats > div {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
}

dt {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

dd {
  margin: 0;
  font-size: 16px;
}

.legend ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.statusLine {
  margin: 18px 0 0;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.help {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.help ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.7;
}

.abilities {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.abilityList {
  display: grid;
  gap: 10px;
}

.abilityButton {
  width: 100%;
  border-radius: 16px;
  text-align: left;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.abilityButton strong {
  display: block;
  margin-bottom: 4px;
  color: #ffffff;
}

.abilityButton small {
  color: #ffffff;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.swatch.plain {
  background: #3b5d3f;
}

.swatch.castle {
  background: #7d8794;
}

.swatch.town {
  background: #7a5542;
}

.swatch.rice {
  background: #4c8fd1;
}

.swatch.terrace {
  background: #82744d;
}

.swatch.road {
  background: #a18f69;
}

@media (max-width: 1024px) {
  .hero,
  .board {
    grid-template-columns: 1fr;
    display: grid;
  }

  .canvasWrap {
    min-height: 0;
  }
}

@media (max-width: 768px) {
  .shell {
    width: min(100vw, calc(100vw - 16px));
    padding: 12px 0 20px;
  }

  .hero {
    gap: 12px;
    margin-bottom: 14px;
  }

  .gameControls {
    top: 12px;
    left: 12px;
    gap: 6px;
    max-width: calc(100% - 24px);
  }

  .gameControls button {
    padding: 7px 10px;
    font-size: 10px;
  }

  h1 {
    font-size: clamp(24px, 8vw, 36px);
  }

  .toolbar {
    gap: 8px;
  }

  .toolbar button,
  .zoomControl {
    padding: 9px 12px;
    font-size: 12px;
  }

  .zoomControl {
    width: 100%;
    justify-content: space-between;
  }

  .zoomControl input[type="range"] {
    width: min(180px, 100%);
  }

  .canvasWrap {
    border-radius: 18px;
  }

  .unitCardOverlay,
  .enemyCardOverlay {
    bottom: 10px;
    width: min(144px, calc(100% - 20px));
    max-width: 144px;
    max-height: 24vh;
    overflow: auto;
    padding: 8px 9px;
  }

  .unitCardOverlay {
    left: 10px;
    right: auto;
  }

  .enemyCardOverlay {
    right: 10px;
    left: auto;
  }

  .abilityCardOverlay {
    top: 10px;
    right: 10px;
    width: min(200px, calc(100% - 20px));
    max-width: 200px;
    max-height: 24vh;
    overflow: auto;
    padding: 8px 9px;
  }

  .abilityCardOverlay h3 {
    font-size: 10px;
    margin-bottom: 4px;
  }

  .abilityCardOverlay .abilityButton {
    padding: 6px 8px;
    font-size: 9px;
  }

  canvas {
    width: 100%;
    height: min(82vh, 108vw);
  }

  .unitCardOverlay h3,
  .enemyCardOverlay h3 {
    font-size: 10px;
    margin-bottom: 4px;
  }

  .attackFxOverlay {
    bottom: 96px;
    width: min(260px, 54vw);
    height: 18px;
  }

  .attackFxLabel {
    font-size: 9px;
    padding: 2px 6px;
  }

  .unitCardOverlay .unitInfoTitle,
  .enemyCardOverlay .unitInfoTitle {
    font-size: 10px;
  }

  .unitCardOverlay .unitInfoBody,
  .unitCardOverlay .statusLine,
  .enemyCardOverlay .unitInfoBody,
  .enemyCardOverlay .statusLine {
    font-size: 8px;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .unitCardOverlay button,
  .enemyCardOverlay button {
    padding: 5px 7px;
    font-size: 9px;
  }
}
