:root {
  color-scheme: dark;
  --ink: #f8f4ff;
  --muted: #c9c1e8;
  --panel: rgba(20, 16, 39, 0.78);
  --panel-strong: rgba(29, 21, 53, 0.94);
  --line: rgba(255, 255, 255, 0.18);
  --cyan: #42e7ff;
  --mint: #67ffb0;
  --gold: #ffc857;
  --rose: #ff5f9e;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #141126;
  color: var(--ink);
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.shell {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.arcade-wrap {
  position: relative;
  width: min(100vw, 177.78vh);
  height: min(100vh, 56.25vw);
  min-width: 320px;
  min-height: 180px;
  overflow: hidden;
  background: #141126;
  touch-action: none;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.top-hud,
.ticker,
.control-bar,
.result-panel,
.lobby {
  position: absolute;
  z-index: 2;
}

.top-hud {
  top: 14px;
  left: 18px;
  right: 18px;
  display: grid;
  grid-template-columns: 42px auto 1fr 42px;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}

.brand {
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  white-space: nowrap;
}

.wind {
  justify-self: center;
  width: min(560px, 58vw);
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(90deg, rgba(72, 230, 255, 0.16), rgba(255, 200, 87, 0.1));
  color: var(--muted);
  text-align: center;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  pointer-events: auto;
  font-size: 24px;
  font-weight: 900;
}

.back-btn {
  opacity: 0;
  pointer-events: none;
}

.is-playing .back-btn {
  opacity: 1;
  pointer-events: auto;
}

.ticker {
  top: 62px;
  left: 50%;
  max-width: min(760px, calc(100% - 32px));
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(22, 17, 38, 0.48);
  color: #f4eaff;
  font-size: 13px;
  text-align: center;
  transform: translateX(-50%);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lobby {
  inset: 88px 24px 22px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 16px;
  pointer-events: auto;
}

.lobby-head {
  display: grid;
  grid-template-columns: minmax(180px, 260px) 1fr;
  align-items: center;
  gap: 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(12px);
}

.lobby-head span,
.stat span,
.bet-panel span {
  color: var(--muted);
  font-size: 12px;
}

.lobby-head strong {
  display: block;
  color: var(--gold);
  font-size: clamp(26px, 4vw, 42px);
  line-height: 1;
}

.lobby-head p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  min-height: 0;
}

.game-card {
  display: grid;
  align-content: end;
  min-height: 112px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background:
    radial-gradient(circle at 20% 20%, rgba(255,255,255,0.13), transparent 34%),
    linear-gradient(145deg, rgba(66, 231, 255, 0.14), rgba(255, 95, 158, 0.07)),
    rgba(12, 10, 25, 0.68);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04), 0 14px 36px rgba(0,0,0,0.24);
  text-align: left;
  overflow: hidden;
}

.game-card strong {
  display: block;
  margin-bottom: 6px;
  font-size: clamp(15px, 1.65vw, 21px);
  line-height: 1.05;
}

.game-card span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.game-card em {
  display: inline-block;
  width: max-content;
  margin-bottom: 18px;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(255, 200, 87, 0.14);
  color: var(--gold);
  font-size: 11px;
  font-style: normal;
  font-weight: 900;
}

.family-reactor { background-color: rgba(80, 23, 52, 0.7); }
.family-mine { background-color: rgba(18, 45, 63, 0.72); }
.family-wheel,
.family-nova { background-color: rgba(49, 24, 84, 0.74); }
.family-lane,
.family-tunnel,
.family-pulse { background-color: rgba(23, 42, 70, 0.72); }
.family-cards,
.family-tiles,
.family-crystal { background-color: rgba(61, 38, 78, 0.72); }

.control-bar {
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: minmax(104px, 142px) minmax(184px, 242px) minmax(178px, 240px) minmax(104px, 142px) minmax(150px, 190px);
  align-items: center;
  gap: clamp(6px, 0.8vw, 10px);
  width: min(1120px, calc(100% - 28px));
  padding: clamp(8px, 1vw, 12px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.3);
  transform: translateX(-50%);
  backdrop-filter: blur(12px);
}

.stat,
.bet-panel,
.mode-toggle {
  min-height: 58px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  background: rgba(8, 7, 20, 0.35);
}

.stat {
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 0 14px;
}

.stat strong,
.bet-panel strong {
  color: var(--gold);
  font-size: 20px;
  line-height: 1;
}

.bet-panel {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
  padding: 7px;
  text-align: center;
}

.round-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffd66b, #ff9f3e);
  color: #241229;
  font-size: 28px;
  font-weight: 900;
  box-shadow: 0 0 20px rgba(255, 200, 87, 0.3);
}

.mode-toggle {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 7px;
}

.mode {
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-weight: 850;
  font-size: 13px;
}

.mode.active {
  background: linear-gradient(180deg, rgba(66, 231, 255, 0.28), rgba(103, 255, 176, 0.16));
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(103, 255, 176, 0.26);
}

.play-btn,
.result-panel button {
  min-height: 58px;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffe177, #ff9c38);
  color: #26112b;
  font-weight: 950;
  box-shadow: 0 0 32px rgba(255, 200, 87, 0.38);
}

.play-btn {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  touch-action: none;
}

.play-btn::before {
  position: absolute;
  inset: 0 auto 0 0;
  z-index: -1;
  width: var(--charge);
  content: "";
  background: linear-gradient(90deg, rgba(66, 231, 255, 0.72), rgba(103, 255, 176, 0.7));
  box-shadow: 0 0 26px rgba(66, 231, 255, 0.5);
  transition: width 60ms linear;
}

.play-btn:disabled {
  opacity: 0.58;
  cursor: wait;
}

.play-btn.is-charging {
  transform: translateY(1px);
  box-shadow: 0 0 42px rgba(66, 231, 255, 0.38), 0 0 32px rgba(255, 200, 87, 0.28);
}

.result-panel {
  left: 50%;
  bottom: 104px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
  width: min(560px, calc(100% - 40px));
  padding: 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
  transform: translateX(-50%);
}

.result-panel p,
.result-panel strong,
.result-panel span {
  display: block;
  margin: 0;
}

.result-panel p {
  color: var(--gold);
  font-size: 15px;
  font-weight: 900;
}

.result-panel strong {
  font-size: 30px;
}

.result-panel span {
  color: var(--muted);
  font-size: 13px;
}

.result-panel button {
  min-width: 136px;
  padding: 0 16px;
}

.rotate-warning {
  display: none;
}

@media (max-width: 900px) {
  .top-hud {
    top: 8px;
    left: 10px;
    right: 10px;
    grid-template-columns: 34px auto 1fr 34px;
    gap: 8px;
  }

  .brand { font-size: 12px; }
  .wind {
    width: auto;
    padding: 6px 9px;
    font-size: 11px;
  }

  .icon-btn {
    width: 34px;
    height: 34px;
  }

  .ticker {
    top: 48px;
    font-size: 11px;
  }

  .lobby {
    inset: 72px 10px 10px;
    gap: 8px;
  }

  .lobby-head {
    grid-template-columns: 160px 1fr;
    padding: 9px 11px;
  }

  .lobby-head p {
    font-size: 12px;
  }

  .game-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
  }

  .game-card {
    min-height: 76px;
    padding: 8px;
  }

  .game-card em {
    margin-bottom: 8px;
  }

  .game-card span {
    display: none;
  }

  .game-card strong {
    font-size: 13px;
  }

  .game-card em {
    font-size: 9px;
  }

  .control-bar {
    bottom: 8px;
    grid-template-columns: minmax(74px, 0.9fr) minmax(150px, 1.5fr) minmax(128px, 1fr) minmax(112px, 1fr);
    width: calc(100% - 16px);
    padding: 8px;
    gap: 7px;
  }

  .cost-stat {
    display: none;
  }

  .stat,
  .bet-panel,
  .mode-toggle,
  .play-btn {
    min-height: 48px;
  }

  .stat { padding: 0 8px; }
  .stat strong,
  .bet-panel strong { font-size: 15px; }

  .round-btn {
    width: 34px;
    height: 34px;
    font-size: 22px;
  }

  .bet-panel {
    grid-template-columns: 34px 1fr 34px;
    gap: 4px;
    padding: 6px;
  }

  .mode-toggle {
    padding: 5px;
    gap: 4px;
  }

  .mode,
  .play-btn { font-size: 12px; }
  .result-panel { bottom: 72px; }
}

@media (max-width: 700px) and (orientation: landscape) {
  .control-bar {
    grid-template-columns: 0.95fr 1.45fr 1fr;
  }

  .mode-toggle {
    display: none;
  }

  .play-btn {
    min-width: 104px;
  }
}

@media (orientation: portrait) and (max-width: 760px) {
  .arcade-wrap {
    filter: blur(8px) brightness(0.55);
  }

  .rotate-warning {
    position: fixed;
    inset: 0;
    z-index: 8;
    display: grid;
    place-content: center;
    gap: 10px;
    padding: 28px;
    text-align: center;
    background: rgba(13, 10, 26, 0.72);
  }

  .rotate-warning strong {
    font-size: 28px;
  }

  .rotate-warning span {
    color: var(--muted);
  }
}
