:root {
  color-scheme: only light;
  --bg: #080b12;
  --panel: rgba(12, 18, 28, 0.7);
  --panel-strong: rgba(255, 255, 255, 0.15);
  --text: #fbfdff;
  --muted: rgba(251, 253, 255, 0.74);
  --line: rgba(255, 255, 255, 0.18);
  --cyan: #28d8ff;
  --lime: #b7ff45;
  --amber: #ffd84d;
  --red: #ff334f;
}

*,
*::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: linear-gradient(150deg, #070a12 0%, #10232d 48%, #11151d 100%);
}

button {
  font: inherit;
}

.app {
  width: 100vw;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  overflow: hidden;
}

.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;
  pointer-events: none;
  overflow-y: auto;
  transform: translateY(18px) scale(0.98);
  overscroll-behavior: contain;
  transition: opacity 0.22s ease, transform 0.26s ease;
}

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

#game-screen {
  position: fixed;
  inset: 0;
  padding: 0;
  overflow: hidden;
  background: #05070d;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hero,
.result-card,
.modal-card {
  width: min(860px, 100%);
  padding: clamp(18px, 4vw, 36px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.14), rgba(12, 18, 28, 0.64));
  box-shadow: 0 28px 64px rgba(0, 0, 0, 0.36);
  text-align: center;
  backdrop-filter: blur(16px);
}

.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;
}

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

h1 {
  font-size: clamp(42px, 9vw, 88px);
}

h2 {
  font-size: clamp(34px, 7vw, 62px);
}

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

.language-switch {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--line);
  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: #061018;
  background: var(--cyan);
}

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

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

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

.segmented {
  display: grid;
  gap: 6px;
}

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

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

.segmented--two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.segmented__btn,
.btn,
.icon-btn,
.touch-pad 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 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.11);
  font-weight: 800;
}

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

.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 {
  color: #061018;
  background: linear-gradient(135deg, var(--cyan), var(--lime));
  box-shadow: 0 16px 30px rgba(40, 216, 255, 0.24);
}

.btn--ghost,
.icon-btn,
.touch-pad button {
  background: rgba(255, 255, 255, 0.14);
}

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

.rules {
  width: min(860px, 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: 210px;
  opacity: 1;
  padding: 14px 18px;
}

.hud {
  position: absolute;
  top: 14px;
  top: calc(14px + env(safe-area-inset-top));
  left: 10px;
  left: calc(10px + env(safe-area-inset-left));
  right: 10px;
  right: calc(10px + env(safe-area-inset-right));
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) 52px;
  gap: 8px;
  pointer-events: none;
}

.hud > div,
.icon-btn {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(5, 8, 14, 0.66);
  display: grid;
  place-items: center;
  backdrop-filter: blur(12px);
  box-shadow: 0 0 22px rgba(40, 216, 255, 0.1), inset 0 0 14px rgba(255, 255, 255, 0.06);
}

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

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

.status-pill {
  position: absolute;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  z-index: 2;
  min-width: 168px;
  max-width: min(560px, calc(100vw - 24px));
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(5, 8, 14, 0.66);
  color: var(--text);
  text-align: center;
  transform: translateX(-50%);
  backdrop-filter: blur(12px);
  pointer-events: none;
}

.touch-pad {
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 2;
  width: min(430px, calc(100vw - 24px));
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  transform: translateX(-50%);
}

.touch-pad button {
  min-height: 58px;
  border-radius: 8px;
  font-size: 28px;
  font-weight: 900;
  backdrop-filter: blur(12px);
  box-shadow: 0 0 22px rgba(40, 216, 255, 0.11);
}

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

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

.modal-card {
  max-width: 500px;
  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;
  }

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

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

  #game-screen {
    padding: 0;
  }

  #game-screen > :first-child,
  #game-screen > :last-child {
    margin: 0;
  }

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

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

  h1 {
    font-size: clamp(36px, 11vw, 48px);
  }

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

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

  .setup-group {
    gap: 5px;
  }

  .segmented__btn {
    min-height: 39px;
    padding: 7px 5px;
    font-size: clamp(12px, 3.6vw, 15px);
  }

  .actions {
    margin-top: 14px;
  }

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

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

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

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

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

  .hud > div:nth-child(3) {
    display: none;
  }

  .icon-btn {
    width: 46px;
  }
}

@media (max-width: 520px) {
  .segmented--four,
  .segmented--three {
    grid-template-columns: repeat(2, 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;
  }

  h1 {
    font-size: clamp(32px, 10vw, 40px);
  }

  .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;
  }

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

  .touch-pad button {
    min-height: 50px;
  }

  .status-pill {
    bottom: calc(82px + env(safe-area-inset-bottom));
    font-size: 13px;
  }
}

@media (max-width: 340px) {
  .hero,
  .result-card,
  .modal-card {
    padding: 12px;
  }

  h1 {
    font-size: 30px;
  }

  .subtitle {
    font-size: 13px;
  }

  .segmented--four {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .segmented--two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .segmented__btn {
    min-height: 32px;
    font-size: 12px;
  }

  .actions {
    margin-top: 10px;
  }

  .btn {
    padding: 10px 14px;
  }
}
