:root {
  --bg-1: #18232a;
  --bg-2: #2d3d4c;
  --panel: #f5efda;
  --ink: #132028;
  --accent: #cf5f4c;
  --accent-2: #4f7f79;
  --card-bg: #fdf7ea;
  --shadow: 4px 4px 0 #132028;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "VT323", monospace;
  background: radial-gradient(circle at 10% 10%, #627f8d 0%, var(--bg-2) 45%, var(--bg-1) 100%);
}

.atmosphere {
  position: fixed;
  inset: 0;
  background-image: linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 22px 22px;
  pointer-events: none;
}

.shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
  position: relative;
  z-index: 1;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.panel {
  background: var(--panel);
  border: 3px solid var(--ink);
  box-shadow: var(--shadow);
  padding: 0.75rem;
}

h1,
h2,
h3 {
  margin: 0 0 0.5rem;
  font-family: "Press Start 2P", cursive;
  line-height: 1.4;
}

h1 {
  font-size: clamp(1rem, 2.2vw, 1.4rem);
}

h2,
h3 {
  font-size: clamp(0.78rem, 1.5vw, 1rem);
}

p {
  margin: 0.3rem 0;
  font-size: 1.35rem;
}

.menu-box {
  max-width: 640px;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(680px, calc(100vw - 2rem));
  z-index: 20;
  margin: 10vh auto;
  display: grid;
  gap: 0.8rem;
}

.subtitle {
  font-size: 1.5rem;
}
#textbox-text {
  font-size: 1.7rem;
}

.textbox {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  width: min(920px, calc(100vw - 2rem));
  z-index: 20;
  margin: 0;
  text-align: center;
  background: rgba(255, 247, 226, 0.96);
  backdrop-filter: blur(6px);
  border-radius: 8px;
  box-shadow: 0 0 0 3px rgba(19, 32, 40, 0.8), 8px 8px 0 rgba(19, 32, 40, 0.25);
}

.tiny {
  font-size: 1.1rem;
  opacity: 0.9;
}

.credits {
  margin-top: 0.6rem;
  display: grid;
  gap: 0.35rem;
}

.credits p {
  font-size: 1.2rem;
}

.menu-actions,
.hud-actions,
.battle-actions,
.settings-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn {
  border: 3px solid var(--ink);
  background: var(--accent);
  color: #fff9ea;
  box-shadow: 2px 2px 0 #132028;
  font-family: "Press Start 2P", cursive;
  font-size: 0.6rem;
  padding: 0.55rem 0.8rem;
  cursor: pointer;
}

.btn-secondary {
  background: var(--accent-2);
}

.btn:hover {
  filter: brightness(1.1);
}

.btn-link {
  display: inline-block;
  text-decoration: none;
  line-height: 1.2;
}

.hud {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.5rem;
  align-items: center;
}

.world-grid {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1rem;
}

.textbox {
  margin-top: 1rem;
  background: #fff7e2;
}

.textbox-speaker {
  font-family: "Press Start 2P", cursive;
  font-size: 0.65rem;
  margin-bottom: 0.25rem;
}

.canvas-wrap canvas {
  width: 100%;
  height: auto;
  border: 3px solid var(--ink);
  image-rendering: pixelated;
  background: #111;
}

.side-panel {
  display: grid;
  gap: 0.5rem;
  align-content: start;
}

.scroll-box {
  min-height: 140px;
  max-height: 230px;
  overflow: auto;
  border: 2px solid var(--ink);
  background: #fff;
  padding: 0.35rem;
}

.battle-top {
  margin-bottom: 1rem;
}

.battle-intro {
  margin-bottom: 1rem;
  border-color: #8b3f36;
  background: #fff1dd;
  animation: intro-pop 180ms ease-out;
}

.battle-intro-name {
  font-family: "Press Start 2P", cursive;
  font-size: 0.64rem;
  color: #8b3f36;
}

@keyframes intro-pop {
  from {
    transform: translateY(-4px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.battle-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.battler {
  min-height: 210px;
}

.pixel {
  width: 96px;
  height: 96px;
  image-rendering: pixelated;
  border: 3px solid var(--ink);
  background: #ece4d0;
}

.cards {
  margin-top: 0.75rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
}

.card {
  border: 3px solid var(--ink);
  background: var(--card-bg);
  box-shadow: 2px 2px 0 #2a3832;
  padding: 0.5rem;
  cursor: pointer;
}

.card.unplayable {
  opacity: 0.45;
  cursor: not-allowed;
}

.card h4 {
  margin: 0 0 0.4rem;
  font-family: "Press Start 2P", cursive;
  font-size: 0.62rem;
  line-height: 1.4;
}

.card p {
  margin: 0.2rem 0;
  font-size: 1.15rem;
}

.hidden {
  display: none;
}

#settings-dialog {
  width: min(460px, 95vw);
  border: 0;
  background: transparent;
}

.settings-grid {
  display: grid;
  gap: 0.6rem;
}

label {
  display: grid;
  gap: 0.2rem;
  font-size: 1.2rem;
}

menu {
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.deck-editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.deck-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #ccc;
  padding: 0.2rem 0;
}

.mini-btn {
  border: 2px solid var(--ink);
  background: var(--accent-2);
  color: #fff;
  font-family: "VT323", monospace;
  font-size: 1rem;
  padding: 0.15rem 0.4rem;
  cursor: pointer;
}

.shop-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid #c3baa1;
  padding: 0.35rem 0;
}

.shop-row p {
  margin: 0;
  font-size: 1.15rem;
}

#shop-dialog {
  width: min(520px, 96vw);
  border: 0;
  background: transparent;
}

@media (max-width: 920px) {
  .hud {
    grid-template-columns: 1fr;
  }

  .world-grid,
  .battle-grid {
    grid-template-columns: 1fr;
  }

  .deck-editor-grid {
    grid-template-columns: 1fr;
  }
}
