:root {
  color-scheme: dark;
  --bg: oklch(15% 0.025 245);
  --panel: oklch(20% 0.035 245);
  --panel-strong: oklch(25% 0.045 245);
  --ink: oklch(94% 0.015 240);
  --muted: oklch(76% 0.035 240);
  --soft: oklch(58% 0.045 240);
  --line: oklch(36% 0.04 245);
  --cyan: oklch(82% 0.16 210);
  --mint: oklch(82% 0.17 155);
  --gold: oklch(82% 0.17 82);
  --coral: oklch(72% 0.2 28);
  --danger: oklch(68% 0.22 20);
  --shadow: rgb(0 0 0 / 0.36);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family:
    "Segoe UI",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
  background:
    radial-gradient(circle at 20% 12%, oklch(35% 0.12 210 / 0.45), transparent 34rem),
    radial-gradient(circle at 88% 80%, oklch(36% 0.15 28 / 0.38), transparent 30rem),
    linear-gradient(135deg, oklch(12% 0.03 245), var(--bg));
  overflow-x: hidden;
  overscroll-behavior: none;
}

button {
  font: inherit;
}

button[hidden] {
  display: none !important;
}

.rotate-overlay {
  display: none;
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 32px 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  align-items: center;
}

.game-panel,
.side-panel {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, oklch(22% 0.04 245 / 0.92), oklch(17% 0.035 245 / 0.94));
  box-shadow: 0 18px 42px var(--shadow);
}

.game-panel {
  border-radius: 14px;
  padding: 18px;
}

.side-panel {
  border-radius: 12px;
  padding: 18px;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 22px;
}

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

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.language-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(42px, 1fr));
  gap: 3px;
  min-height: 42px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: oklch(14% 0.03 245 / 0.9);
}

.language-option {
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
  transition: color 160ms ease, background 160ms ease, transform 160ms ease;
}

.language-option:hover,
.language-option:focus-visible {
  color: var(--ink);
  outline: none;
}

.language-option.is-active {
  color: oklch(10% 0.03 245);
  background: var(--cyan);
}

.kicker,
.panel-label {
  margin: 0 0 5px;
  color: var(--cyan);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 4.4rem);
  line-height: 0.95;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.action-button {
  min-width: 128px;
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  color: oklch(10% 0.03 245);
  background: var(--mint);
  font-weight: 800;
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

.action-button:hover,
.action-button:focus-visible {
  transform: translateY(-1px);
  background: var(--cyan);
  box-shadow: 0 0 0 4px oklch(82% 0.16 210 / 0.18);
  outline: none;
}

.secondary-action {
  min-width: 96px;
  color: var(--ink);
  border: 1px solid var(--line);
  background: oklch(14% 0.03 245 / 0.88);
}

.secondary-action:hover,
.secondary-action:focus-visible {
  color: oklch(10% 0.03 245);
}

.stage-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 10px;
  background: oklch(10% 0.025 245);
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.fullscreen-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 4;
  display: none;
  gap: 8px;
  pointer-events: none;
}

.icon-action {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid oklch(90% 0.02 240 / 0.22);
  border-radius: 999px;
  color: var(--ink);
  background: oklch(7% 0.025 245 / 0.48);
  box-shadow: 0 8px 28px rgb(0 0 0 / 0.26);
  backdrop-filter: blur(10px);
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  transition: transform 160ms ease, background 160ms ease, opacity 160ms ease;
}

.icon-action:hover,
.icon-action:focus-visible {
  transform: translateY(-1px);
  background: oklch(15% 0.04 245 / 0.72);
  outline: none;
}

.icon-action:disabled {
  opacity: 0.38;
  cursor: default;
  transform: none;
}

.pause-icon span {
  width: 14px;
  height: 16px;
  display: block;
  border-left: 4px solid currentColor;
  border-right: 4px solid currentColor;
}

.exit-icon span {
  position: relative;
  width: 16px;
  height: 16px;
  display: block;
}

.exit-icon span::before,
.exit-icon span::after {
  content: "";
  position: absolute;
  left: 7px;
  top: 0;
  width: 2px;
  height: 16px;
  border-radius: 999px;
  background: currentColor;
}

.exit-icon span::before {
  transform: rotate(45deg);
}

.exit-icon span::after {
  transform: rotate(-45deg);
}

.state-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: radial-gradient(circle, rgb(0 0 0 / 0.14), rgb(0 0 0 / 0.44));
  opacity: 1;
  transition: opacity 180ms ease;
}

.state-overlay.is-hidden {
  opacity: 0;
}

.state-overlay.is-paused {
  display: block;
  background: rgb(0 0 0 / 0.08);
}

.state-copy {
  width: min(560px, calc(100% - 40px));
  text-align: center;
  padding: 18px 20px;
  text-shadow: 0 2px 16px rgb(0 0 0 / 0.8);
}

.state-overlay.is-paused .state-copy {
  position: absolute;
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 10px;
  row-gap: 1px;
  align-items: center;
  width: min(275px, calc(100% - 28px));
  padding: 9px 11px;
  border: 1px solid oklch(72% 0.16 155 / 0.32);
  border-radius: 8px;
  background: oklch(11% 0.03 245 / 0.82);
  text-align: left;
  text-shadow: none;
}

.state-overlay.is-paused.pause-top-left .state-copy {
  top: 14px;
  left: 14px;
}

.state-overlay.is-paused.pause-top-right .state-copy {
  top: 14px;
  right: 14px;
}

.state-overlay.is-paused.pause-bottom-left .state-copy {
  bottom: 14px;
  left: 14px;
}

.state-overlay.is-paused.pause-bottom-right .state-copy {
  right: 14px;
  bottom: 14px;
}

.state-copy p {
  margin-bottom: 10px;
  color: var(--mint);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.state-copy p.is-new-best {
  color: var(--gold);
  text-shadow: 0 0 18px oklch(82% 0.17 82 / 0.6);
}

.state-overlay.is-paused .state-copy p {
  grid-row: 1 / span 2;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  margin: 0;
  border-radius: 999px;
  color: oklch(10% 0.03 245);
  background: var(--mint);
  font-size: 0.74rem;
  letter-spacing: 0;
  text-transform: none;
}

.state-copy h2 {
  margin-bottom: 10px;
  font-size: clamp(1.45rem, 3vw, 2.7rem);
  line-height: 1.12;
  letter-spacing: 0;
  text-wrap: balance;
}

.state-overlay.is-paused .state-copy h2 {
  margin: 0;
  font-size: clamp(1rem, 1.8vw, 1.18rem);
  line-height: 1.1;
}

.state-copy span {
  display: block;
  color: var(--muted);
  line-height: 1.5;
  text-wrap: pretty;
}

.result-stats {
  width: min(390px, 100%);
  margin: 16px auto 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  text-shadow: none;
}

.result-stats.is-hidden {
  display: none;
}

.result-stats div {
  min-width: 0;
  padding: 10px;
  border-radius: 8px;
  background: oklch(15% 0.035 245 / 0.78);
}

.result-stats div.is-new-best {
  outline: 1px solid oklch(82% 0.17 82 / 0.72);
  background:
    linear-gradient(135deg, oklch(82% 0.17 82 / 0.18), transparent 58%),
    oklch(15% 0.035 245 / 0.86);
  box-shadow: 0 0 22px oklch(82% 0.17 82 / 0.2);
  animation: new-best-pop 560ms ease-out both;
}

.result-stats span {
  display: block;
  margin-bottom: 5px;
  color: var(--soft);
  font-size: 0.72rem;
  line-height: 1;
}

.result-stats strong {
  display: block;
  color: var(--ink);
  font-size: clamp(1rem, 2vw, 1.25rem);
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-stats div.is-new-best strong {
  color: var(--gold);
}

.state-overlay.is-paused .state-copy span {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.2;
}

@keyframes new-best-pop {
  0% {
    transform: scale(0.96);
  }

  55% {
    transform: scale(1.04);
  }

  100% {
    transform: scale(1);
  }
}

.hud {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.metric {
  min-width: 0;
  border-radius: 10px;
  padding: 12px;
  background: var(--panel-strong);
}

.metric span {
  display: block;
  margin-bottom: 5px;
  color: var(--soft);
  font-size: 0.74rem;
}

.metric strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: clamp(1.1rem, 2.5vw, 1.7rem);
  line-height: 1;
}

#powerValue {
  white-space: nowrap;
  overflow-wrap: normal;
  font-size: clamp(1rem, 1.9vw, 1.45rem);
}

.status-block {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.status-dot {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  margin-top: 4px;
  border-radius: 999px;
  background: var(--mint);
  box-shadow: 0 0 20px oklch(82% 0.17 155 / 0.65);
}

.status-block strong {
  display: block;
  line-height: 1.2;
  text-wrap: balance;
}

.rules {
  color: var(--muted);
  line-height: 1.55;
}

.rules p {
  margin-bottom: 12px;
}

.rules p:last-child {
  margin-bottom: 0;
}

.power-guide {
  display: grid;
  gap: 9px;
}

.power-guide .panel-label {
  margin-bottom: 0;
}

.power-guide div {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 10px;
  align-items: center;
}

.power-guide span {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: oklch(10% 0.03 245);
  background: oklch(84% 0.16 92);
  font-size: 0.82rem;
  font-weight: 900;
}

.power-guide div:nth-of-type(2) span {
  background: var(--mint);
}

.power-guide div:nth-of-type(3) span {
  background: oklch(76% 0.16 275);
}

.power-guide strong {
  color: var(--ink);
  font-size: 0.92rem;
  line-height: 1.25;
}

.control-list {
  margin: 0;
  display: grid;
  gap: 10px;
}

.control-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.control-list dt {
  color: var(--soft);
}

.control-list dd {
  margin: 0;
  color: var(--ink);
  font-weight: 700;
  text-align: right;
}

body.is-fullscreen {
  overflow: hidden;
  background: oklch(8% 0.025 245);
}

body.is-fullscreen .shell {
  width: 100vw;
  height: 100dvh;
  min-height: 0;
  padding: 0;
  display: block;
}

.shell:fullscreen {
  background: oklch(8% 0.025 245);
}

body.is-fullscreen .game-panel {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: 0;
  overflow: hidden;
  background: transparent;
  box-shadow: none;
}

body.is-fullscreen .topbar,
body.is-fullscreen .side-panel,
body.is-fullscreen .hud {
  display: none;
}

body.is-fullscreen .stage-wrap {
  position: absolute;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  min-height: 0;
  aspect-ratio: auto;
  border-radius: 0;
}

body.is-fullscreen .fullscreen-controls {
  display: flex;
}

@media (max-width: 940px) and (orientation: portrait), (any-pointer: coarse) and (orientation: portrait) {
  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  .shell {
    display: none;
  }

  .rotate-overlay {
    width: 100vw;
    height: 100dvh;
    padding: clamp(12px, 4vw, 24px);
    display: grid;
    place-items: center;
  }

  .rotate-content {
    width: min(420px, 100%);
    height: 100%;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: clamp(10px, 2.2vh, 16px);
  }

  .rotate-message {
    text-align: center;
  }

  .rotate-message span {
    width: 58px;
    height: 34px;
    margin: 0 auto 12px;
    display: block;
    border: 3px solid var(--mint);
    border-radius: 8px;
    box-shadow: 0 0 24px oklch(82% 0.17 155 / 0.28);
  }

  .rotate-message h2 {
    margin: 0 0 8px;
    font-size: clamp(1.65rem, 8.4vw, 2.6rem);
    line-height: 1;
  }

  .rotate-message p {
    margin: 0;
    color: var(--muted);
    font-size: clamp(0.86rem, 3.7vw, 1rem);
    line-height: 1.35;
  }

  .portrait-guide {
    min-height: 0;
    padding: clamp(12px, 3.5vw, 18px);
    display: grid;
    grid-template-rows: auto auto auto auto;
    gap: clamp(9px, 1.8vh, 16px);
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: linear-gradient(180deg, oklch(22% 0.04 245 / 0.92), oklch(17% 0.035 245 / 0.94));
    box-shadow: 0 18px 42px var(--shadow);
  }

  .portrait-guide .status-block {
    gap: 10px;
  }

  .portrait-guide .panel-label {
    margin-bottom: 4px;
    font-size: clamp(0.66rem, 2.8vw, 0.76rem);
  }

  .portrait-guide .status-block strong,
  .portrait-guide .power-guide strong,
  .portrait-guide .control-list {
    font-size: clamp(0.78rem, 3.6vw, 0.95rem);
  }

  .portrait-guide .rules {
    font-size: clamp(0.76rem, 3.35vw, 0.92rem);
    line-height: 1.42;
  }

  .portrait-guide .rules p {
    margin-bottom: 8px;
  }

  .portrait-guide .power-guide {
    gap: 7px;
  }

  .portrait-guide .power-guide div {
    grid-template-columns: 28px 1fr;
    gap: 9px;
  }

  .portrait-guide .power-guide span {
    width: 28px;
    height: 28px;
  }

  .portrait-guide .control-list {
    gap: 6px;
  }

  .portrait-guide .control-list div {
    gap: 8px;
    padding-top: 7px;
  }
}

@media (max-width: 940px) and (orientation: landscape), (any-pointer: coarse) and (orientation: landscape) {
  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  .shell {
    width: 100vw;
    height: 100dvh;
    min-height: 0;
    padding: 0;
    display: block;
  }

  .game-panel {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 0;
    padding: 0;
    display: block;
    border: 0;
    border-radius: 0;
    overflow: hidden;
  }

  .side-panel {
    display: none;
  }

  .topbar {
    display: none;
    position: absolute;
    top: 8px;
    left: 10px;
    right: 10px;
    z-index: 3;
    margin-bottom: 0;
    align-items: center;
    pointer-events: none;
  }

  .topbar-actions {
    gap: 7px;
    pointer-events: auto;
  }

  .kicker {
    display: none;
  }

  h1 {
    font-size: clamp(1.2rem, 4.6vw, 1.65rem);
    letter-spacing: 0;
    text-shadow: 0 3px 16px oklch(7% 0.03 245 / 0.8);
  }

  .language-switch {
    min-height: 34px;
    grid-template-columns: repeat(2, 38px);
    background: oklch(8% 0.03 245 / 0.84);
    backdrop-filter: blur(10px);
  }

  .language-option {
    font-size: 0.72rem;
  }

  .action-button {
    min-width: 96px;
    min-height: 36px;
  }

  .stage-wrap {
    position: absolute;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    min-height: 0;
    margin: auto;
    aspect-ratio: auto;
    border-radius: 0;
  }

  .hud {
    display: none;
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 8px;
    z-index: 3;
    margin-top: 0;
    gap: 5px;
    pointer-events: none;
  }

  .metric {
    min-height: 42px;
    padding: 6px 8px;
    background: oklch(18% 0.05 235 / 0.72);
    backdrop-filter: blur(10px);
  }

  .metric span {
    margin-bottom: 2px;
    font-size: 0.62rem;
  }

  .metric strong {
    font-size: clamp(0.86rem, 2.6vw, 1.12rem);
  }

  #powerValue {
    font-size: clamp(0.76rem, 2.2vw, 1rem);
  }

  .panel-label,
  .kicker {
    font-size: 0.68rem;
  }

  .fullscreen-controls {
    top: 10px;
    right: 10px;
    display: flex;
  }

  .exit-icon {
    display: none !important;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100vw - 18px, 1180px);
  }

  .game-panel,
  .side-panel {
    padding: 12px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .action-button {
    width: 100%;
  }

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

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

  .control-list div {
    align-items: baseline;
  }
}

@media (max-width: 560px) and (orientation: landscape) {
  .shell {
    width: 100vw;
  }

  .game-panel {
    padding: 0;
  }

  .topbar,
  .hud,
  .side-panel {
    display: none;
  }
}

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