:root {
  color-scheme: dark;
  --bg: #02060b;
  --bg-2: #05080d;
  --surface: #0b1118;
  --surface-soft: rgba(11, 17, 24, 0.78);
  --cyan: #00e5ff;
  --orange: #ff8a30;
  --success: #42ff9e;
  --error: #ff3d68;
  --white: #f4f8fa;
  --muted: #687582;
  --node: #46535d;
  --line: rgba(244, 248, 250, 0.12);
  --shadow: 0 26px 70px rgba(0, 0, 0, 0.55);
  font-family: "Space Grotesk", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #000;
  color: var(--white);
}

body {
  min-height: 100dvh;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.app-shell {
  width: 100vw;
  height: 100dvh;
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background:
    radial-gradient(circle at 20% 16%, rgba(0, 229, 255, 0.12), transparent 28rem),
    radial-gradient(circle at 82% 72%, rgba(255, 138, 48, 0.08), transparent 26rem),
    #000;
}

.phone {
  position: relative;
  width: min(100vw, 460px);
  height: min(100dvh, 920px);
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 16%, rgba(0, 229, 255, 0.08), transparent 28%),
    radial-gradient(circle at 82% 50%, rgba(255, 138, 48, 0.06), transparent 25%),
    linear-gradient(180deg, #05080d, #010305 70%);
}

@media (min-width: 760px) {
  .phone {
    width: min(430px, calc(100vw - 48px));
    height: min(900px, calc(100dvh - 36px));
    border: 1px solid rgba(244, 248, 250, 0.16);
    border-radius: 36px;
    box-shadow: var(--shadow), inset 0 0 0 8px rgba(255, 255, 255, 0.03);
  }
}

.ambient-lines {
  position: absolute;
  inset: 0;
  opacity: 0.3;
  pointer-events: none;
  background:
    linear-gradient(24deg, transparent 42%, rgba(0, 229, 255, 0.18) 42.2%, transparent 42.8%),
    linear-gradient(154deg, transparent 55%, rgba(255, 138, 48, 0.14) 55.2%, transparent 55.8%);
}

.game-page,
.game-board,
.board-svg,
.anchor-layer {
  position: absolute;
  inset: 0;
}

.game-page {
  overflow: hidden;
}

.game-page[data-screen="home"] .game-hud,
.game-page[data-screen="home"] .pause-button,
.game-page[data-screen="practice"] .game-hud,
.game-page[data-screen="ranking"] .game-hud,
.game-page[data-screen="modes"] .game-hud,
.game-page[data-screen="account"] .game-hud,
.game-page[data-screen="compete"] .game-hud,
.game-page[data-screen="practice"] .pause-button,
.game-page[data-screen="ranking"] .pause-button,
.game-page[data-screen="modes"] .pause-button,
.game-page[data-screen="account"] .pause-button,
.game-page[data-screen="compete"] .pause-button {
  opacity: 0;
  pointer-events: none;
}

.game-board {
  z-index: 1;
}

.board-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.pattern-line,
.history-line,
.drag-line,
.pattern-comet {
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.pattern-line {
  stroke: var(--cyan);
  stroke-width: 4;
  filter: url(#cyanGlow);
}

.pattern-comet {
  fill: var(--white);
  filter: url(#cyanGlow);
  opacity: 0.95;
}

.history-line {
  stroke: rgba(66, 255, 158, 0.88);
  stroke-width: 3;
  opacity: 0.9;
  transition: opacity 180ms ease;
}

.history-line.is-fading {
  opacity: 0;
}

.drag-line {
  stroke: var(--cyan);
  stroke-width: 4;
  filter: url(#cyanGlow);
}

.drag-line.error {
  stroke: var(--error);
}

.anchor {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 999px;
  background: var(--node);
  box-shadow: 0 0 18px rgba(0, 229, 255, 0.08);
  transform: scale(1);
  transition: background 150ms ease, box-shadow 150ms ease, transform 150ms ease, opacity 180ms ease;
}

.anchor::before {
  content: "";
  position: absolute;
  inset: -24px;
  border-radius: 999px;
}

.anchor.is-accent-left {
  background: rgba(0, 229, 255, 0.75);
}

.anchor.is-accent-right {
  background: rgba(255, 138, 48, 0.74);
}

.anchor.is-pulse,
.anchor.is-snap {
  background: var(--cyan);
  transform: scale(1.35);
  box-shadow: 0 0 32px rgba(0, 229, 255, 0.46);
}

.anchor.is-success {
  background: var(--success);
  transform: scale(1.45);
  box-shadow: 0 0 34px rgba(66, 255, 158, 0.5);
}

.anchor.is-error {
  background: var(--error);
  transform: scale(1.45);
  box-shadow: 0 0 34px rgba(255, 61, 104, 0.5);
}

.game-hud {
  position: absolute;
  z-index: 5;
  top: calc(28px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  text-align: center;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.hud-label,
.game-hud small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.game-hud strong {
  font-size: 36px;
  line-height: 0.95;
  letter-spacing: 0;
}

.game-hud.is-error strong {
  color: var(--error);
}

.game-hud.is-success strong {
  color: var(--success);
}

.pause-button {
  position: absolute;
  z-index: 8;
  top: calc(28px + env(safe-area-inset-top));
  right: calc(22px + env(safe-area-inset-right));
  width: 42px;
  height: 42px;
  border: 1px solid rgba(244, 248, 250, 0.3);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.34);
}

.pause-button span {
  display: inline-block;
  width: 4px;
  height: 17px;
  margin: 0 3px;
  border-radius: 999px;
  background: var(--white);
}

.screen {
  position: absolute;
  z-index: 10;
  inset: 0;
  padding: calc(28px + env(safe-area-inset-top)) 26px calc(24px + env(safe-area-inset-bottom));
  transition: opacity 170ms ease, transform 170ms ease;
}

.screen.hidden,
.status-overlay.hidden {
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
}

.home-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.brand-mark {
  position: relative;
  width: 168px;
  height: 112px;
  margin-bottom: 12px;
}

.brand-mark i {
  position: absolute;
  display: block;
  border-radius: 999px;
}

.brand-mark i:nth-child(1),
.brand-mark i:nth-child(2) {
  width: 6px;
  height: 94px;
  bottom: 0;
  box-shadow: 0 0 24px currentColor;
}

.brand-mark i:nth-child(1) {
  left: 22px;
  color: var(--cyan);
  background: var(--cyan);
}

.brand-mark i:nth-child(2) {
  right: 22px;
  color: var(--orange);
  background: var(--orange);
}

.brand-mark i:nth-child(3) {
  left: 31px;
  top: 11px;
  width: 106px;
  height: 64px;
  border-left: 6px solid var(--cyan);
  border-right: 6px solid var(--orange);
  border-bottom: 6px solid transparent;
  border-top: 6px solid transparent;
  transform: skewY(-2deg);
  filter: drop-shadow(0 0 14px rgba(0, 229, 255, 0.35));
}

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

h1 {
  margin: 0;
  font-size: clamp(40px, 13vw, 58px);
  line-height: 0.94;
  letter-spacing: 0.08em;
}

h1 span,
h1 strong {
  display: block;
  font-weight: 800;
}

h1 strong {
  color: var(--cyan);
}

h1 strong span {
  display: inline;
  color: var(--orange);
}

.claim {
  margin: 14px 0 28px;
  color: var(--white);
  font-size: 13px;
  font-weight: 800;
}

.record-pill {
  display: grid;
  gap: 2px;
  margin-bottom: 28px;
  color: var(--cyan);
  text-transform: uppercase;
}

.record-pill span {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.record-pill strong {
  font-size: 34px;
  line-height: 1;
}

.main-actions {
  display: grid;
  width: min(100%, 260px);
  gap: 10px;
}

.primary-button,
.secondary-button {
  min-height: 54px;
  border-radius: 8px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: transform 120ms ease, filter 120ms ease;
}

.primary-button {
  color: #041016;
  background: linear-gradient(105deg, var(--cyan), var(--orange));
  box-shadow: 0 0 34px rgba(0, 229, 255, 0.2);
}

.secondary-button {
  background: rgba(11, 17, 24, 0.88);
  border: 1px solid rgba(244, 248, 250, 0.08);
}

.primary-button:active,
.secondary-button:active,
.bottom-links button:active,
.mode-list button:active,
.option-list button:active {
  transform: scale(0.98);
}

.bottom-links {
  position: absolute;
  left: 26px;
  right: 26px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.bottom-links button {
  min-height: 44px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.bottom-links button:hover {
  color: var(--cyan);
}

.sheet-screen {
  background: linear-gradient(180deg, rgba(2, 6, 11, 0.88), rgba(2, 6, 11, 0.98));
}

.back-button {
  width: 42px;
  height: 42px;
  margin-bottom: 28px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--white);
  font-size: 30px;
  line-height: 1;
}

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

h2 {
  margin: 0 0 22px;
  font-size: 27px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.option-list,
.mode-list {
  display: grid;
  gap: 12px;
}

.option-list button,
.mode-list button {
  min-height: 74px;
  padding: 15px;
  border-radius: 8px;
  border: 1px solid rgba(244, 248, 250, 0.08);
  background: rgba(11, 17, 24, 0.84);
  text-align: left;
}

.auth-form,
.friend-tools {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.auth-form input,
.friend-tools input,
#joinRoomInput {
  width: 100%;
  min-height: 48px;
  border: 1px solid rgba(244, 248, 250, 0.1);
  border-radius: 8px;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--white);
  font: inherit;
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.sheet-status {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.friend-tools h3 {
  margin: 8px 0 0;
  font-size: 15px;
  text-transform: uppercase;
}

.friend-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.friend-list p {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 13px;
}

.friend-list strong {
  color: var(--white);
}

.friend-list button {
  min-width: 42px;
  min-height: 30px;
  border-radius: 8px;
  background: rgba(0, 229, 255, 0.12);
  color: var(--cyan);
  font-weight: 900;
}

.room-code {
  display: grid;
  place-items: center;
  min-height: 82px;
  margin: 18px 0;
  border: 1px solid rgba(0, 229, 255, 0.22);
  border-radius: 8px;
  background: rgba(0, 229, 255, 0.07);
  color: var(--cyan);
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.option-list strong,
.mode-list strong {
  display: block;
  color: var(--white);
  font-size: 15px;
  text-transform: uppercase;
}

.option-list span,
.mode-list span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.mode-list button {
  display: grid;
  grid-template-columns: 44px 1fr;
  column-gap: 12px;
  align-items: center;
}

.mode-list i {
  grid-row: span 2;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--cyan);
  background: rgba(0, 229, 255, 0.1);
  font-style: normal;
  font-size: 22px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.tabs button {
  min-height: 38px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.tabs .active {
  color: var(--cyan);
  background: rgba(0, 229, 255, 0.14);
}

.ranking-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 2px;
}

.ranking-list li {
  display: grid;
  grid-template-columns: 34px 1fr 42px;
  align-items: center;
  min-height: 44px;
  border-bottom: 1px solid rgba(244, 248, 250, 0.06);
  color: var(--muted);
}

.ranking-list strong {
  color: var(--white);
}

.ranking-list em {
  color: var(--white);
  font-style: normal;
  text-align: right;
}

.ranking-list .you {
  margin-top: 22px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: rgba(0, 229, 255, 0.16);
}

.ranking-list .you strong,
.ranking-list .you em {
  color: var(--cyan);
}

.status-overlay {
  position: absolute;
  z-index: 7;
  left: 24px;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  gap: 8px;
  text-align: center;
  pointer-events: none;
  transition: opacity 170ms ease, transform 170ms ease;
}

.status-overlay strong {
  color: var(--cyan);
  font-size: 22px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.status-overlay span {
  color: var(--muted);
  font-size: 14px;
}

.status-overlay.success strong {
  color: var(--success);
}

.status-overlay.error strong {
  color: var(--error);
}

.level-up-screen,
.game-over-screen {
  display: grid;
  place-items: center;
  text-align: center;
  background: rgba(2, 6, 11, 0.9);
}

.level-up-screen p {
  margin: 0;
  color: var(--success);
  font-size: 22px;
  font-weight: 900;
  text-transform: uppercase;
}

.level-up-screen span,
.level-up-screen em {
  color: var(--muted);
  font-style: normal;
  text-transform: uppercase;
}

.level-up-screen strong {
  color: var(--cyan);
  font-size: 24px;
  text-transform: uppercase;
}

.level-up-screen .primary-button,
.game-over-screen .main-actions {
  align-self: end;
  width: min(100%, 280px);
}

.game-over-screen h2 {
  color: var(--error);
  font-size: 31px;
}

.record-badge {
  margin: 0;
  padding: 6px 12px;
  border: 1px solid var(--success);
  border-radius: 999px;
  color: var(--success);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.score-grid {
  width: min(100%, 300px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.score-grid span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.score-grid strong {
  display: block;
  margin-top: 8px;
  color: var(--white);
  font-size: 30px;
}

.trace-preview {
  width: min(100%, 300px);
  height: 150px;
  opacity: 0.85;
}

.shake {
  animation: shake 180ms ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  35% { transform: translateX(-4px); }
  70% { transform: translateX(4px); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-height: 680px) {
  .brand-mark {
    width: 132px;
    height: 86px;
  }

  h1 {
    font-size: 38px;
  }

  .claim {
    margin-bottom: 18px;
  }
}
