:root {
  --bg: #171717;
  --panel: #202020;
  --grid: #111111;
  --court: #101010;
  --text: #f7f7f7;
  --muted: #b8b8b8;
  --gold: #ffb700;
  --gold-soft: rgba(255, 183, 0, 0.14);
  --button: #ffb700;
  --button-text: #171717;
  --cyan: #41d6ff;
  --blue: #5a7dff;
  --orange: #ff9a3d;
  --yellow: #ffe45c;
  --green: #60e36e;
  --purple: #c77dff;
  --red: #ff5c5c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  width: 100%;
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 15% 12%, rgba(255, 183, 0, 0.08), transparent 28%),
    radial-gradient(circle at 86% 85%, rgba(65, 214, 255, 0.07), transparent 30%),
    var(--bg);
  color: var(--text);
}

.app {
  height: 100dvh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 0;
  overflow: hidden;
}

.panel {
  width: 100%;
  height: 100%;
  background: var(--panel);
  border: 1px solid rgba(255, 183, 0, 0.2);
  border-radius: 0;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.38);
  padding: 24px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel__header,
.header-actions,
.title-row {
  display: flex;
  align-items: center;
}

.panel__header {
  justify-content: space-between;
  gap: 16px;
}

.panel__header > div {
  min-width: 0;
  flex: 1;
}

.header-actions {
  flex: 0 0 auto;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.eyebrow,
.help,
.stat__label,
.mini-stats span {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.title-row {
  gap: 16px;
  justify-content: space-between;
}

.title-row h1 {
  margin: 0;
  font-size: 20px;
}

.stat {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  padding: 5px 10px;
  border: 1px solid rgba(255, 183, 0, 0.18);
  border-radius: 999px;
  background: rgba(255, 183, 0, 0.08);
}

.stat__label {
  display: inline;
  font-size: 0.8rem;
  margin-bottom: 0;
}

.stat strong,
.mini-stats strong,
.target-score {
  color: var(--gold);
}

button {
  border: 0;
  border-radius: 999px;
  background: var(--button);
  color: var(--button-text);
  padding: 10px 16px;
  font: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

button:focus-visible {
  outline: 3px solid rgba(255, 183, 0, 0.35);
  outline-offset: 2px;
}

.secondary-button {
  border: 1px solid rgba(255, 183, 0, 0.22);
  background: rgba(255, 183, 0, 0.08);
  color: var(--text);
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 0.86rem;
  line-height: 1;
  font-weight: 800;
}

.game-shell {
  width: 100%;
  min-height: 0;
  margin-top: 18px;
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(116px, 170px);
  justify-content: center;
  align-items: start;
  gap: 14px;
}

.court-wrap {
  position: relative;
  width: min(100%, calc(100vw - 230px));
  height: min(calc(100dvh - 190px), 78dvh);
  aspect-ratio: 16 / 9;
  align-self: center;
  touch-action: none;
  user-select: none;
}

.court {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 16px;
  background: var(--court);
  box-shadow:
    inset 0 0 0 1px rgba(255, 183, 0, 0.16),
    0 20px 45px rgba(0, 0, 0, 0.35);
}

.serve-hint {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  padding: 8px 12px;
  border: 1px solid rgba(255, 183, 0, 0.18);
  border-radius: 999px;
  background: rgba(17, 17, 17, 0.72);
  color: var(--text);
  font-size: 0.86rem;
  text-align: center;
  pointer-events: none;
  white-space: nowrap;
}

.serve-hint.hidden {
  display: none;
}

.rotate-hint {
  display: none;
}

.court-serve-button {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  transform: translate(-50%, -50%);
  min-width: 86px;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid rgba(255, 183, 0, 0.28);
  border-radius: 8px;
  background: var(--button);
  color: var(--button-text);
  font-weight: 800;
  letter-spacing: 0.06em;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.24);
}

.side-card {
  min-width: 0;
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(255, 183, 0, 0.18);
  border-radius: 16px;
  background: rgba(17, 17, 17, 0.45);
}

.target-score {
  display: block;
  font-size: 2.1rem;
  line-height: 1;
}

.mini-stats {
  display: grid;
  gap: 8px;
}

.mini-stats div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.help {
  margin: 16px 0 0;
  line-height: 1.5;
}

.control-button--serve {
  letter-spacing: 0.06em;
  box-shadow: 0 0 0 1px rgba(255, 183, 0, 0.24), 0 10px 22px rgba(0, 0, 0, 0.22);
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(23, 23, 23, 0.74);
  z-index: 10;
}

.overlay.hidden,
.hidden {
  display: none;
}

.modal {
  width: min(100%, 720px);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 20px;
  border: 1px solid rgba(255, 183, 0, 0.24);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  text-align: left;
}

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

.modal h2 {
  margin: 2px 0 0;
}

.final-score {
  margin: 0 0 16px;
  color: var(--muted);
}

.final-score strong {
  color: var(--text);
}

.overlay-options {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
}

.language-menu {
  position: relative;
}

.flag-icon {
  width: 24px;
  height: 16px;
  display: block;
}

.language-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 174px;
  max-height: min(360px, calc(100dvh - 120px));
  overflow: auto;
  padding: 6px;
  border: 1px solid rgba(255, 183, 0, 0.18);
  border-radius: 12px;
  background: #202020;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.42);
  z-index: 20;
}

.language-option {
  width: 100%;
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  box-shadow: none;
}

.language-option:hover,
.language-option.active {
  background: rgba(255, 183, 0, 0.1);
}

.sound-toggle {
  border: 1px solid rgba(255, 183, 0, 0.22);
  background: rgba(255, 183, 0, 0.08);
  color: var(--text);
  box-shadow: none;
}

.sound-toggle[aria-pressed="true"] {
  background: var(--button);
  color: var(--button-text);
}

.mode-heading {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mode-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.mode-button {
  width: 100%;
  border-radius: 12px;
  padding: 8px;
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  background: #272727;
  border: 1px solid rgba(255, 183, 0, 0.16);
  color: var(--text);
  text-align: left;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.mode-button:hover,
.mode-button:active {
  background: #303030;
  border-color: rgba(255, 183, 0, 0.46);
  transform: translateY(-1px);
}

.mode-copy,
.mode-copy span,
.mode-button small {
  display: block;
}

.mode-copy span {
  font-weight: 700;
}

.mode-button small {
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.35;
}

.mode-preview {
  position: relative;
  width: 72px;
  aspect-ratio: 1;
  border-radius: 8px;
  background:
    repeating-linear-gradient(90deg, transparent 0 33px, rgba(255, 183, 0, 0.18) 33px 36px),
    #111111;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 183, 0, 0.14);
}

.mode-preview::before,
.mode-preview::after {
  content: "";
  position: absolute;
  border-radius: 3px;
}

.mode-preview--classic::before {
  width: 8px;
  height: 32px;
  left: 10px;
  top: 20px;
  background: var(--cyan);
  box-shadow: 44px 0 0 var(--gold);
}

.mode-preview--classic::after {
  width: 12px;
  height: 12px;
  left: 30px;
  top: 30px;
  background: var(--yellow);
  border-radius: 50%;
}

.mode-preview--duel::before {
  width: 8px;
  height: 40px;
  left: 10px;
  top: 16px;
  background: var(--green);
  box-shadow: 44px 0 0 var(--red);
}

.mode-preview--duel::after {
  width: 10px;
  height: 10px;
  left: 32px;
  top: 18px;
  background: var(--gold);
  border-radius: 50%;
  box-shadow: -8px 16px 0 rgba(255, 183, 0, 0.38), 8px 32px 0 rgba(255, 183, 0, 0.16);
}

.mode-preview--wall::before {
  width: 8px;
  height: 38px;
  left: 10px;
  top: 17px;
  background: var(--cyan);
}

.mode-preview--wall::after {
  width: 7px;
  height: 52px;
  right: 9px;
  top: 10px;
  background: #626262;
  box-shadow: -30px 24px 0 -20px var(--yellow);
}

.mode-preview--speed::before {
  width: 8px;
  height: 30px;
  left: 10px;
  top: 21px;
  background: var(--orange);
  box-shadow: 44px -7px 0 var(--purple);
}

.mode-preview--speed::after {
  width: 12px;
  height: 12px;
  left: 38px;
  top: 28px;
  background: var(--gold);
  border-radius: 50%;
  box-shadow: -10px 0 0 rgba(255, 183, 0, 0.28), -20px 0 0 rgba(255, 183, 0, 0.12);
}

.mode-preview--zen::before {
  width: 8px;
  height: 46px;
  left: 10px;
  top: 13px;
  background: var(--green);
  box-shadow: 44px 0 0 var(--green);
}

.mode-preview--zen::after {
  width: 54px;
  height: 54px;
  left: 9px;
  top: 9px;
  border: 1px solid rgba(255, 183, 0, 0.38);
  background: transparent;
}

.mode-preview--tiny::before {
  width: 8px;
  height: 20px;
  left: 10px;
  top: 26px;
  background: var(--red);
  box-shadow: 44px 0 0 var(--red);
}

.mode-preview--tiny::after {
  width: 11px;
  height: 11px;
  left: 31px;
  top: 31px;
  background: var(--cyan);
  border-radius: 50%;
}

@media (max-width: 760px) {
  .panel {
    padding: 16px;
  }

  .panel__header {
    align-items: flex-start;
  }

  .stat--level,
  .side-card {
    display: none;
  }

  .game-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    justify-content: center;
    justify-items: center;
    margin-top: 12px;
    gap: 8px;
  }

  .court-wrap {
    width: min(calc(100vw - 32px), calc((100dvh - 210px) * 16 / 9));
    height: auto;
    max-height: calc(100dvh - 210px);
  }

  .rotate-hint {
    display: none;
    width: calc(100vw - 32px);
    max-width: 520px;
    justify-self: center;
    padding: 7px 10px;
    border: 1px solid rgba(255, 183, 0, 0.18);
    border-radius: 8px;
    background: rgba(17, 17, 17, 0.76);
    color: var(--text);
    font-size: 0.78rem;
    line-height: 1.2;
    text-align: center;
  }

  .help {
    display: none;
  }

  .control-button--serve {
    min-width: 0;
    min-height: 42px;
    font-size: 0.82rem;
  }

  .court-serve-button {
    min-width: 70px;
    min-height: 34px;
    padding: 0 10px;
  }

  .modal {
    padding: 16px;
  }

  .modal-header {
    flex-direction: column;
    gap: 12px;
    margin-bottom: 12px;
  }

  .overlay-options {
    justify-content: flex-start;
  }

  .language-dropdown {
    left: 0;
    right: auto;
  }

  .mode-options {
    grid-template-columns: 1fr;
  }

  .mode-button {
    grid-template-columns: 54px minmax(0, 1fr);
    padding: 8px;
    gap: 9px;
  }

  .mode-preview {
    width: 54px;
  }

  .mode-button small {
    line-height: 1.2;
  }
}

@media (max-width: 760px) and (orientation: portrait) {
  .game-shell {
    align-content: start;
  }

  .court-wrap {
    width: min(calc(100vw - 32px), calc((100dvh - 240px) * 16 / 9));
    max-height: calc(100dvh - 240px);
  }

  .rotate-hint {
    display: block;
  }
}

@media (min-width: 900px) and (orientation: landscape) {
  .panel {
    display: grid;
    grid-template-columns: minmax(0, calc(100dvh * 1.55)) clamp(245px, 26vw, 340px);
    grid-template-rows: auto auto auto minmax(0, 1fr);
    grid-template-areas:
      "court header"
      "court side"
      "court help"
      "court .";
    align-items: start;
    justify-content: center;
    gap: 18px 24px;
  }

  .panel__header {
    grid-area: header;
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .game-shell {
    grid-area: court;
    margin-top: 0;
    display: contents;
  }

  .court-wrap {
    grid-area: court;
    width: 100%;
    height: min(calc(100dvh - 52px), calc((100vw - 410px) * 0.5625));
    max-width: 100%;
  }

  .side-card {
    grid-area: side;
    width: 100%;
    align-self: start;
  }

  .help {
    grid-area: help;
    margin: 0;
  }

}

@media (max-width: 430px) {
  .control-button--serve {
    min-width: 0;
    min-height: 38px;
    font-size: 0.72rem;
  }

  .court-serve-button {
    min-width: 64px;
    min-height: 32px;
    font-size: 0.72rem;
  }

  .serve-hint {
    bottom: 10px;
    font-size: 0.78rem;
  }
}
