:root {
  --bg-top: #120f24;
  --bg-bottom: #26173b;
  --panel: rgba(11, 10, 27, 0.78);
  --panel-border: #6ce7d8;
  --ink: #f6f3ff;
  --muted: #b6aed6;
  --accent: #f95794;
  --accent-2: #f9c74f;
  --shadow: #090611;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: "Trebuchet MS", "Verdana", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top, rgba(108, 231, 216, 0.16), transparent 30%),
    radial-gradient(circle at 20% 20%, rgba(249, 87, 148, 0.2), transparent 25%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 22px 22px;
  opacity: 0.35;
}

.layout {
  width: min(1760px, calc(100vw - 28px));
  min-height: calc(100vh - 28px);
  margin: 14px auto;
}

.panel {
  position: relative;
  background: var(--panel);
  border: 3px solid rgba(108, 231, 216, 0.55);
  border-radius: 18px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.panel::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 3px solid rgba(249, 199, 79, 0.18);
  border-radius: 18px;
  pointer-events: none;
}

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

h1 {
  margin: 0;
  font-size: clamp(2rem, 3vw, 2.8rem);
  line-height: 0.95;
}

.intro-copy {
  color: var(--muted);
  line-height: 1.5;
}

.art-card {
  display: grid;
  gap: 12px;
  margin: 22px 0;
  padding: 16px;
  background: linear-gradient(180deg, rgba(249, 87, 148, 0.16), rgba(108, 231, 216, 0.1));
  border: 2px solid rgba(249, 199, 79, 0.4);
  border-radius: 16px;
}

.art-card img {
  width: 96px;
  height: 96px;
  image-rendering: pixelated;
  background: rgba(4, 4, 11, 0.5);
  padding: 8px;
  border-radius: 12px;
  border: 2px solid rgba(108, 231, 216, 0.5);
}

.art-card p {
  margin: 0;
  color: var(--muted);
}

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

.legend div {
  display: grid;
  gap: 3px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
}

.legend strong {
  color: var(--accent-2);
}

.legend span {
  color: var(--muted);
  line-height: 1.4;
}

.game-panel {
  padding: 16px;
  min-height: calc(100vh - 28px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
}

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

.stats-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.controls-row {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 12px;
}

.stat {
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 14px;
}

.label {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat strong {
  display: block;
  font-size: 1.45rem;
  line-height: 1;
  letter-spacing: 0.02em;
}

.restart-btn,
.language-btn,
.difficulty-btn,
.fullscreen-btn,
.sound-btn,
.cat-color-btn,
.shop-btn,
.rules-btn,
.overlay-card button {
  border: 0;
  border-radius: 14px;
  background: linear-gradient(180deg, var(--accent-2), #ff9e3d);
  color: #23181e;
  font-weight: 700;
  padding: 0 18px;
  min-height: 54px;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
}

.sound-btn {
  background: linear-gradient(180deg, #7cefe1, #39b5d3);
  color: #10212a;
}

.fullscreen-btn {
  background: linear-gradient(180deg, #f58bd5, #ef5f9f);
  color: #2b1021;
}

.difficulty-btn {
  background: linear-gradient(180deg, #b7a8ff, #7c69de);
  color: #140f2f;
}

.language-btn {
  background: linear-gradient(180deg, #ffd98a, #ffb347);
  color: #2c1802;
}

.difficulty-btn:disabled {
  cursor: not-allowed;
  filter: saturate(0.7) brightness(0.85);
}

.restart-btn:hover,
.language-btn:hover,
.difficulty-btn:hover,
.fullscreen-btn:hover,
.sound-btn:hover,
.cat-color-btn:hover,
.shop-btn:hover,
.rules-btn:hover,
.overlay-card button:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(180deg, #090611, #1b1231);
  border: 3px solid rgba(108, 231, 216, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas {
  display: block;
  width: min(100%, calc((100vh - 250px) * 1.7778));
  max-height: calc(100vh - 250px);
  height: auto;
  aspect-ratio: 16 / 9;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

body.fullscreen-active {
  overflow: hidden;
}

body.fullscreen-active .layout {
  width: 100vw;
  min-height: 100vh;
  margin: 0;
  padding: 12px;
  gap: 0;
  grid-template-columns: 1fr;
}

body.fullscreen-active .intro-panel {
  display: none;
}

body.fullscreen-active .game-panel {
  min-height: calc(100vh - 24px);
  padding: 12px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

body.fullscreen-active .hud {
  margin-bottom: 0;
}

body.fullscreen-active .canvas-wrap {
  height: 100%;
  min-height: 0;
  display: flex;
  align-items: stretch;
}

body.fullscreen-active canvas {
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 2, 10, 0.58);
  backdrop-filter: blur(6px);
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(360px, 100%);
  padding: 20px;
  text-align: center;
  background: rgba(23, 17, 37, 0.96);
  border: 3px solid rgba(249, 199, 79, 0.48);
  border-radius: 18px;
}

.overlay-card h2 {
  margin: 0 0 8px;
}

.overlay-card p {
  color: var(--muted);
  line-height: 1.45;
  margin: 0 0 16px;
}

@media (max-width: 920px) {
  .layout {
    width: min(100vw - 20px, 1100px);
    min-height: auto;
    margin: 10px auto;
  }

  .game-panel {
    min-height: auto;
  }

  .stats-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .controls-row {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .canvas-wrap {
    min-height: 0;
  }
}

@media (max-width: 640px) {
  body {
    padding-bottom: 18px;
  }

  .layout {
    width: min(100vw - 18px, 720px);
    gap: 18px;
    margin: 12px auto;
  }

  .game-panel {
    padding: 14px;
  }

  .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .controls-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .difficulty-btn,
  .language-btn,
  .fullscreen-btn,
  .sound-btn,
  .restart-btn,
  .shop-btn,
  .cat-color-btn,
  .rules-btn {
    grid-column: 1 / -1;
  }

  .canvas-wrap {
    min-height: 0;
  }
}

.shop-btn {
  background: linear-gradient(180deg, #ffe57a, #ffab00);
  color: #2a1f00;
}

.rules-btn {
  background: linear-gradient(180deg, #9de7ff, #56bde4);
  color: #0f2330;
}

.rules-overlay {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: rgba(9, 6, 17, 0.82);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.rules-overlay.hidden {
  display: none;
}

.rules-panel {
  width: min(980px, calc(100vw - 30px));
  max-height: 90vh;
  overflow-y: auto;
  padding: 22px;
}

.rules-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 16px;
}

.rules-header h2 {
  margin: 0;
  font-size: clamp(1.8rem, 3vw, 2.6rem);
  line-height: 0.95;
}

.rules-close-btn {
  border: 2px solid var(--accent);
  border-radius: 10px;
  background: transparent;
  color: var(--accent);
  font-weight: 700;
  padding: 8px 16px;
  cursor: pointer;
}

.rules-close-btn:hover {
  filter: brightness(1.15);
}

@media (max-width: 640px) {
  .rules-header {
    flex-direction: column;
  }
}

.shop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 6, 17, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
}

.shop-overlay.hidden {
  display: none;
}

.shop-panel {
  background: var(--panel);
  border: 3px solid rgba(249, 199, 79, 0.6);
  border-radius: 18px;
  padding: 20px;
  width: min(500px, calc(100vw - 32px));
  max-height: 90vh;
  overflow-y: auto;
}

.shop-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.shop-header h2 {
  margin: 0;
  flex: 1;
  color: var(--accent-2);
  font-size: 1.3rem;
}

.shop-budget {
  color: var(--accent-2);
  font-weight: 700;
  font-size: 1rem;
}

.shop-close-btn {
  background: none;
  border: 2px solid var(--accent);
  color: var(--accent);
  border-radius: 8px;
  cursor: pointer;
  padding: 4px 12px;
  font-size: 1rem;
  line-height: 1;
  min-height: auto;
  transition: filter 120ms ease;
}

.shop-close-btn:hover {
  filter: brightness(1.2);
}

.shop-items-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

@media (max-width: 480px) {
  .shop-items-grid {
    grid-template-columns: 1fr;
  }
}

.shop-item {
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(108, 231, 216, 0.25);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.shop-item-header {
  display: flex;
  align-items: center;
  gap: 6px;
}

.shop-item-icon {
  font-size: 1.4rem;
  line-height: 1;
  min-width: 1.4rem;
  text-align: center;
}

.shop-item-name {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--ink);
  flex: 1;
}

.shop-item-count {
  font-size: 0.73rem;
  color: var(--muted);
}

.shop-item-desc {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.4;
  margin: 0;
}

.shop-item-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.shop-item-cost {
  color: var(--accent-2);
  font-weight: 700;
  font-size: 0.85rem;
  flex: 1;
}

.shop-item-buy-btn {
  border: 0;
  border-radius: 10px;
  background: linear-gradient(180deg, var(--accent-2), #ff9e3d);
  color: #23181e;
  font-weight: 700;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 0.78rem;
  transition: filter 120ms ease;
  min-height: auto;
}

.shop-item-buy-btn:hover:not(:disabled) {
  filter: brightness(1.1);
}

.shop-item-buy-btn:disabled {
  cursor: not-allowed;
  filter: saturate(0.45) brightness(0.65);
}
