:root {
  color-scheme: dark;
  --bg: #06080b;
  --panel: rgba(12, 16, 22, 0.9);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f6f7fb;
  --muted: #9aa5b5;
  --mint: #65e6c9;
  --gold: #ffd66b;
  --berry: #ff6f91;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 10%, rgba(101, 230, 201, 0.14), transparent 28%),
    radial-gradient(circle at 82% 18%, rgba(255, 111, 145, 0.12), transparent 26%),
    linear-gradient(135deg, #080b10, #111620 54%, #08090d);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  border-color: rgba(101, 230, 201, 0.7);
  outline: none;
}

.game-shell {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  gap: 0;
  width: 100%;
  height: 100%;
  padding: 14px;
}

body.embed .game-shell {
  padding: 0;
}

.hud {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--mint);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 { font-size: clamp(1.1rem, 3vw, 2rem); }
h2 { font-size: clamp(1.4rem, 5vw, 2.8rem); }

.hud-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.hud-stats strong {
  min-width: 110px;
  font-size: clamp(1.6rem, 5vw, 3rem);
  text-align: right;
}

#timeText {
  min-width: 58px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  color: var(--muted);
  text-align: center;
  font-weight: 900;
}

.player-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  min-height: 32px;
  margin: 10px auto 0;
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.32);
  color: rgba(255, 248, 223, 0.82);
  font-size: 13px;
  font-weight: 900;
}

.player-badge.is-user { color: var(--mint); }

.stage-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
}

body.embed .stage-wrap {
  border: 0;
  border-radius: 0;
  background: transparent;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.fruit-game-hud {
  position: absolute;
  top: 18px;
  left: 18px;
  right: 18px;
  z-index: 3;
  display: flex;
  align-items: stretch;
  gap: 10px;
  pointer-events: none;
}

.fruit-game-stat {
  min-width: 112px;
  padding: 9px 12px;
  border: 1px solid rgba(121, 224, 255, 0.24);
  border-radius: 8px;
  background: rgba(5, 8, 24, 0.62);
  color: #fff;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.24), inset 0 0 20px rgba(80, 120, 255, 0.08);
  backdrop-filter: blur(8px);
}

.fruit-game-stat span {
  display: block;
  margin-bottom: 3px;
  color: #89dfff;
  font-size: 10px;
  font-weight: 950;
  letter-spacing: 0;
}

.fruit-game-stat strong {
  display: block;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  font-weight: 950;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.44);
}

.overlay.hidden { display: none; }

.hidden {
  display: none;
}

.menu-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: transparent;
  backdrop-filter: none;
  pointer-events: none;
}

.menu-overlay > * {
  pointer-events: auto;
}

.menu-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(22px, 4vh, 36px);
  width: min(380px, 92vw);
}

.menu-title-block {
  margin: 0;
  text-align: center;
  color: #f4f8ff;
  text-shadow: 0 3px 18px rgba(5, 14, 34, 0.7);
}

.menu-title-block h2 {
  font-size: clamp(2rem, 7vw, 4rem);
}

.menu-actions {
  display: grid;
  gap: 12px;
  width: 100%;
}

.menu-button {
  width: 100%;
  padding: 15px 20px;
  border: 2px solid rgba(154, 190, 255, 0.42);
  border-radius: 14px;
  background: rgba(10, 25, 52, 0.58);
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 28px rgba(4, 12, 30, 0.34);
  font-size: clamp(16px, 2.8vw, 20px);
  font-weight: 900;
  color: #f4f8ff;
  text-shadow: 0 2px 10px rgba(5, 14, 34, 0.58);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.menu-button:hover {
  background: rgba(19, 45, 88, 0.78);
  border-color: rgba(181, 210, 255, 0.72);
}

.menu-button:active {
  transform: scale(0.98);
}

.menu-button-primary {
  border-color: rgba(119, 179, 255, 0.78);
  background: rgba(20, 64, 124, 0.78);
}

.menu-button-primary:hover {
  background: rgba(33, 86, 158, 0.9);
  border-color: rgba(184, 216, 255, 0.92);
}

.menu-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  width: min(420px, 92vw);
  margin: 0;
  padding: 18px 20px;
  border: 2px solid rgba(126, 166, 235, 0.28);
  border-radius: 16px;
  background: rgba(8, 20, 44, 0.9);
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 60px rgba(2, 8, 24, 0.56);
  color: #f4f8ff;
  text-align: center;
  transform: translate(-50%, -50%);
}

.menu-panel-wide {
  width: min(640px, 92vw);
}

.menu-panel h2 {
  margin-bottom: 10px;
  font-size: clamp(24px, 5vw, 34px);
}

.menu-panel p {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  font-weight: 700;
  color: rgba(226, 237, 255, 0.9);
}

.howto-scroll {
  display: grid;
  gap: 12px;
  max-height: min(48vh, 360px);
  overflow-y: auto;
  text-align: left;
}

.howto-section {
  padding: 12px;
  border-radius: 12px;
  background: rgba(32, 64, 118, 0.34);
}

.howto-section h3 {
  margin: 0 0 6px;
  color: #9fc8ff;
  font-size: 16px;
}

.mini-button {
  min-height: 40px;
  margin-top: 14px;
  padding: 0 18px;
  border-radius: 12px;
}

.leaderboard-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  max-height: min(42vh, 280px);
  overflow-y: auto;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  font-weight: 800;
}

.leaderboard-list li + li {
  margin-top: 8px;
}

.leaderboard-rank {
  color: #ffd34f;
}

.leaderboard-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: rgba(255, 248, 223, 0.92);
  font-size: 14px;
}

.leaderboard-score {
  text-align: right;
  font-size: 18px;
  color: #ffffff;
}

.leaderboard-empty {
  display: block;
  padding: 16px 8px;
  color: rgba(255, 248, 223, 0.75);
  font-weight: 700;
}

.panel {
  width: min(520px, 94vw);
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

.panel p {
  color: var(--muted);
  line-height: 1.5;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.actions button,
.leaderboard-panel button {
  min-height: 44px;
  padding: 0 18px;
}

.actions button:first-child {
  background: linear-gradient(135deg, rgba(101, 230, 201, 0.28), rgba(255, 214, 107, 0.18));
  color: #fff;
}

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

.controls button {
  min-height: 46px;
}

.controls button.is-down {
  border-color: rgba(255, 214, 107, 0.75);
  background: rgba(255, 214, 107, 0.14);
}

.sprite-editor {
  display: none;
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 30;
  width: min(280px, calc(100vw - 28px));
  pointer-events: none;
}

.sprite-editor button,
.sprite-editor input,
.sprite-editor select {
  pointer-events: auto;
}

.editor-toggle {
  float: right;
  min-height: 36px;
  padding: 0 12px;
  background: rgba(0, 0, 0, 0.48);
}

.editor-panel {
  clear: both;
  display: grid;
  gap: 10px;
  margin-top: 44px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(8, 12, 18, 0.92);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.38);
  pointer-events: auto;
}

.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.editor-head button {
  min-height: 30px;
  padding: 0 10px;
}

.editor-panel label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.editor-panel select,
.editor-panel input {
  width: 100%;
}

.editor-panel select {
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: #111820;
  color: var(--text);
  padding: 0 8px;
}

.editor-panel output {
  color: var(--mint);
  font-variant-numeric: tabular-nums;
}

.editor-panel p {
  margin: 0;
  color: #7f8b9a;
  font-size: 0.74rem;
}

.editor-copy {
  min-height: 36px;
}

.editor-config-output {
  width: 100%;
  min-height: 96px;
  resize: vertical;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  padding: 8px;
  font: 11px ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.leaderboard-panel ol {
  display: grid;
  gap: 8px;
  min-height: 120px;
  margin: 14px 0;
  padding: 0;
  list-style: none;
}

.leaderboard-panel li {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

.leaderboard-hint {
  min-height: 20px;
}

.leaderboard-hint a {
  color: var(--mint);
}

@media (max-width: 620px) {
  .game-shell { padding: 10px; }
  .hud { align-items: flex-start; }
  .hud-stats { flex-direction: column; align-items: flex-end; gap: 6px; }
  .hud-stats strong { min-width: 0; }
  .controls { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .fruit-game-hud {
    top: 10px;
    left: 10px;
    right: 10px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }
  .fruit-game-stat {
    min-width: 0;
    padding: 7px 8px;
  }
  .fruit-game-stat strong {
    font-size: 17px;
  }
}
