:root {
  color-scheme: only light;
  --bg-a: #101726;
  --bg-b: #123344;
  --panel: rgba(255, 255, 255, 0.09);
  --panel-strong: rgba(255, 255, 255, 0.15);
  --text: #f7fbff;
  --muted: rgba(247, 251, 255, 0.72);
  --cyan: #39e6ff;
  --green: #96ff6a;
  --pink: #ff4fca;
  --orange: #ffb34f;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 16% 12%, rgba(57, 230, 255, 0.28), transparent 32%),
    radial-gradient(circle at 86% 16%, rgba(150, 255, 106, 0.18), transparent 30%),
    linear-gradient(155deg, var(--bg-a), var(--bg-b));
}

button {
  font: inherit;
}

.app {
  width: 100vw;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  display: grid;
  place-items: center;
}

.screen {
  position: absolute;
  inset: 0;
  min-height: 100vh;
  min-height: 100dvh;
  padding: clamp(12px, 2.6vw, 30px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  opacity: 0;
  overflow-y: auto;
  transform: translateY(18px) scale(0.98);
  pointer-events: none;
  overscroll-behavior: contain;
  transition: opacity 0.22s ease, transform 0.26s ease;
}

.screen--active {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.hero,
.result-card,
.modal-card {
  width: min(760px, 100%);
  padding: clamp(20px, 4vw, 36px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.06));
  box-shadow: 0 28px 62px rgba(0, 0, 0, 0.28);
  text-align: center;
}

.hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0;
  color: var(--cyan);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.language-switch {
  display: inline-flex;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

.language-switch__btn {
  min-width: 40px;
  height: 30px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0;
}

.language-switch__btn--active {
  color: #06111b;
  background: var(--cyan);
}

h1,
h2 {
  margin: 0;
  line-height: 0.96;
}

h1 {
  font-size: clamp(44px, 10vw, 86px);
}

h2 {
  font-size: clamp(38px, 8vw, 70px);
}

.subtitle {
  max-width: 620px;
  margin: 16px auto 0;
  color: var(--muted);
  font-size: clamp(16px, 2.2vw, 21px);
  line-height: 1.45;
}

.setup-grid {
  margin-top: 22px;
  display: grid;
  gap: 12px;
}

.setup-group {
  display: grid;
  gap: 8px;
}

.setup-group > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.segmented[data-group="pieces"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.segmented__btn,
.btn,
.icon-btn,
.touch-controls button {
  border: 0;
  cursor: pointer;
  color: var(--text);
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.segmented__btn {
  min-height: 42px;
  padding: 9px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.11);
  font-weight: 800;
}

.segmented__btn--active {
  color: #06111b;
  background: linear-gradient(135deg, var(--cyan), var(--green));
}

.actions {
  margin-top: 22px;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.btn {
  min-width: 140px;
  padding: 13px 22px;
  border-radius: 999px;
  font-weight: 800;
}

.btn--primary {
  background: linear-gradient(135deg, var(--cyan), #3d7dff);
  box-shadow: 0 14px 28px rgba(57, 230, 255, 0.25);
}

.btn--ghost {
  background: rgba(255, 255, 255, 0.14);
}

.btn:active,
.icon-btn:active,
.touch-controls button:active,
.segmented__btn:active {
  transform: translateY(2px) scale(0.98);
}

.rules {
  width: min(760px, 100%);
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  display: grid;
  gap: 8px;
  padding: 0 18px;
  color: var(--muted);
  text-align: center;
  transition: max-height 0.24s ease, opacity 0.24s ease, padding 0.24s ease;
}

.rules--open {
  max-height: 180px;
  opacity: 1;
  padding: 14px 18px;
}

.hud {
  width: min(760px, 100%);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) 52px;
  gap: 8px;
  align-items: center;
}

.hud > div,
.icon-btn,
.side-panel section {
  min-height: 54px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: var(--panel);
  display: grid;
  place-items: center;
}

.hud span,
.side-panel span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.hud strong {
  font-size: 21px;
}

.icon-btn {
  width: 52px;
  font-weight: 900;
}

.game-layout {
  width: min(760px, 100%);
  height: min(680px, calc(100vh - 184px));
  min-height: 0;
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
}

.side-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(0, 1.25fr);
  gap: 12px;
}

.side-panel section {
  padding: 10px;
  align-content: center;
  gap: 8px;
}

.side-panel canvas {
  width: 100%;
  max-width: 120px;
  height: auto;
}

.board-wrap {
  min-height: 0;
  display: grid;
  place-items: center;
}

#game-canvas {
  width: auto;
  height: 100%;
  max-height: 100%;
  max-width: 100%;
  aspect-ratio: 1 / 2;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: #07121f;
  box-shadow:
    0 0 0 1px rgba(57, 230, 255, 0.12),
    0 24px 64px rgba(0, 0, 0, 0.34);
  touch-action: none;
}

.touch-controls {
  width: min(760px, 100%);
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.touch-controls button {
  min-height: 48px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.13);
  font-size: 22px;
  font-weight: 900;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(5, 10, 18, 0.64);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal--visible {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  max-width: 460px;
  transform: translateY(14px) scale(0.96);
  transition: transform 0.22s ease;
}

.modal--visible .modal-card {
  transform: translateY(0) scale(1);
}

@media (max-width: 720px) {
  .screen {
    padding: 10px;
    justify-content: flex-start;
    gap: 8px;
  }

  #game-screen {
    justify-content: center;
  }

  .screen > :first-child {
    margin-top: auto;
  }

  .screen > :last-child {
    margin-bottom: auto;
  }

  .hero,
  .result-card,
  .modal-card {
    padding: 16px;
  }

  .hero-top {
    align-items: flex-start;
    margin-bottom: 8px;
  }

  h1 {
    font-size: clamp(38px, 12vw, 50px);
  }

  h2 {
    font-size: clamp(34px, 10vw, 48px);
  }

  .subtitle {
    margin-top: 10px;
    font-size: 16px;
    line-height: 1.35;
  }

  .setup-grid {
    margin-top: 14px;
    gap: 8px;
  }

  .setup-group {
    gap: 5px;
  }

  .segmented__btn {
    min-height: 40px;
    padding: 7px 5px;
    font-size: clamp(13px, 3.8vw, 16px);
  }

  .actions {
    margin-top: 14px;
  }

  .btn {
    min-width: 0;
    padding: 12px 18px;
  }

  .hud {
    grid-template-columns: repeat(4, minmax(0, 1fr)) 46px;
    gap: 6px;
  }

  .hud > div,
  .icon-btn {
    min-height: 44px;
  }

  .hud span,
  .side-panel span {
    font-size: 10px;
  }

  .hud strong {
    font-size: 16px;
  }

  .icon-btn {
    width: 46px;
  }

  .game-layout {
    height: auto;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    gap: 6px;
  }

  .side-panel {
    order: 2;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: none;
    gap: 8px;
  }

  .side-panel section {
    min-height: 72px;
    padding: 7px;
    gap: 5px;
  }

  .side-panel canvas {
    max-height: 50px;
  }

  .board-wrap {
    order: 1;
    height: min(50vh, 430px);
    height: min(50dvh, 430px);
    min-height: 0;
  }

  #game-canvas {
    width: min(100%, 25vh, 215px);
    width: min(100%, 25dvh, 215px);
    height: min(50vh, 430px);
    height: min(50dvh, 430px);
  }

  .touch-controls {
    gap: 6px;
  }

  .touch-controls button {
    min-height: 44px;
    font-size: 20px;
  }
}

@media (max-width: 460px) {
  .segmented[data-group="pieces"] {
    grid-template-columns: 1fr 1fr;
  }

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

@media (max-width: 380px), (max-height: 700px) {
  .screen {
    padding: 8px;
  }

  .hero,
  .result-card,
  .modal-card {
    padding: 14px;
  }

  .hero-top {
    margin-bottom: 6px;
  }

  .eyebrow {
    font-size: 12px;
  }

  .language-switch {
    padding: 3px;
  }

  .language-switch__btn {
    min-width: 36px;
    height: 28px;
  }

  h1 {
    font-size: clamp(34px, 11vw, 42px);
  }

  .subtitle {
    margin-top: 8px;
    font-size: 14px;
  }

  .setup-grid {
    margin-top: 10px;
    gap: 7px;
  }

  .setup-group > span {
    font-size: 10px;
  }

  .segmented {
    gap: 5px;
  }

  .segmented__btn {
    min-height: 36px;
    padding: 6px 4px;
    font-size: 14px;
  }

  .actions {
    margin-top: 12px;
    gap: 8px;
  }

  .btn {
    padding: 11px 15px;
  }

  .hud > div,
  .icon-btn {
    min-height: 40px;
  }

  .icon-btn {
    width: 42px;
  }

  .board-wrap {
    height: min(47vh, 360px);
    height: min(47dvh, 360px);
  }

  #game-canvas {
    width: min(100%, 23.5vh, 190px);
    width: min(100%, 23.5dvh, 190px);
    height: min(47vh, 360px);
    height: min(47dvh, 360px);
  }

  .side-panel section {
    min-height: 64px;
  }

  .side-panel canvas {
    max-height: 42px;
  }

  .touch-controls button {
    min-height: 40px;
  }
}

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

  .segmented[data-group="pieces"] {
    grid-template-columns: 1fr 1fr;
  }
}
