:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --background: #0f172a;
  --surface: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --gold: #fbbf24;
  --border: rgba(255,255,255,.12);
  --font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

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

body {
  font-family: var(--font-family);
  background:
    radial-gradient(circle at top, rgba(99,102,241,.26), transparent 38%),
    var(--background);
  color: var(--text-main);
  min-height: 100svh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

.app-container {
  width: 100%;
  max-width: 520px;
  min-height: 100svh;
  background: var(--surface);
  position: relative;
  box-shadow: 0 0 50px rgba(0,0,0,.55);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

@media (min-width: 540px) {
  body {
    padding: 24px 12px;
    align-items: center;
  }

  .app-container {
    min-height: min(92svh, 920px);
    border-radius: 26px;
    border: 1px solid var(--border);
  }
}

header {
  padding: max(16px, env(safe-area-inset-top)) 18px 12px;
  background: rgba(0,0,0,.22);
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.back-link {
  font-size: .82rem;
  color: var(--text-muted);
  background: rgba(255,255,255,.06);
  padding: 8px 11px;
  border-radius: 999px;
  text-decoration: none;
  white-space: nowrap;
}

.score-box {
  text-align: right;
}

.score-box span {
  display: block;
  font-size: .72rem;
  color: var(--text-muted);
  font-weight: 900;
  letter-spacing: .5px;
}

.score-box strong {
  color: var(--gold);
  font-size: 1.25rem;
}

.title-area {
  text-align: center;
  padding: 13px 18px 10px;
}

.logo {
  font-size: 2.8rem;
  filter: drop-shadow(0 0 18px rgba(99,102,241,.55));
}

h1 {
  font-size: clamp(1.65rem, 7vw, 2.25rem);
  letter-spacing: -1px;
  margin-top: 4px;
}

.subtitle {
  color: var(--text-muted);
  font-size: .9rem;
  margin-top: 6px;
  line-height: 1.35;
}

.next-card {
  margin: 0 18px 12px;
  background: rgba(255,255,255,.055);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 11px 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.next-card p {
  color: var(--text-muted);
  font-size: .78rem;
  font-weight: 900;
  letter-spacing: .6px;
}

.next-fruit {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.45rem;
  box-shadow: inset 0 -7px 0 rgba(0,0,0,.15), 0 8px 18px rgba(0,0,0,.25);
}

.game-wrap {
  flex: 1;
  padding: 0 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.board {
  position: relative;
  flex: 1;
  min-height: 440px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.025)),
    #172033;
  border: 3px solid rgba(255,255,255,.14);
  border-radius: 24px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.05), 0 16px 44px rgba(0,0,0,.38);
  touch-action: none;
}

.danger-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 72px;
  border-top: 2px dashed rgba(239,68,68,.58);
  z-index: 5;
}

.danger-line span {
  position: absolute;
  right: 10px;
  top: -22px;
  font-size: .68rem;
  color: #fecaca;
  font-weight: 900;
  background: rgba(239,68,68,.16);
  padding: 3px 7px;
  border-radius: 999px;
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.drop-guide {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(180deg, rgba(251,191,36,.85), transparent);
  z-index: 4;
  opacity: .75;
  pointer-events: none;
}

.preview-fruit {
  position: absolute;
  top: 18px;
  z-index: 6;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  transform: translateX(-50%);
  box-shadow: inset 0 -7px 0 rgba(0,0,0,.15), 0 8px 18px rgba(0,0,0,.25);
}

.controls-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: .82rem;
  line-height: 1.35;
}

.btn {
  border: 0;
  outline: 0;
  cursor: pointer;
  font-family: inherit;
  font-weight: 900;
  text-align: center;
  text-decoration: none;
  display: block;
  width: 100%;
  border-radius: 16px;
  padding: 15px;
  transition: transform .1s, opacity .2s;
}

.btn:active {
  transform: scale(.98);
}

.btn:disabled {
  opacity: .55;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 10px 24px rgba(99,102,241,.33);
}

.btn-secondary {
  background: rgba(255,255,255,.1);
  color: white;
  border: 1px solid var(--border);
  margin-top: 10px;
}

.result-screen {
  position: absolute;
  inset: 0;
  z-index: 80;
  background: rgba(15,23,42,.94);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

.result-screen.show {
  display: flex;
}

.result-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 24px 20px;
  box-shadow: 0 20px 70px rgba(0,0,0,.58);
}

.result-card .icon {
  font-size: 4rem;
  margin-bottom: 10px;
}

.result-card h2 {
  color: var(--gold);
  font-size: 2rem;
  margin-bottom: 8px;
}

.result-score {
  background: rgba(255,255,255,.08);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  margin: 16px 0;
}

.result-score span {
  color: var(--text-muted);
  font-size: .76rem;
  font-weight: 900;
  letter-spacing: .7px;
}

.result-score strong {
  display: block;
  color: white;
  font-size: 3.3rem;
  line-height: 1;
  margin-top: 8px;
}

.save-hint {
  color: var(--text-muted);
  font-size: .9rem;
  line-height: 1.4;
  margin-bottom: 12px;
}

.modal {
  position: absolute;
  inset: 0;
  z-index: 100;
  background: rgba(15,23,42,.86);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.show {
  display: flex;
}

.modal-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.55);
}

.modal-card h2 {
  margin-bottom: 8px;
}

.modal-card p {
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.35;
}

.modal-card label,
.avatar-label {
  display: block;
  font-size: .8rem;
  font-weight: 900;
  color: var(--text-muted);
  margin: 12px 0 7px;
}

.modal-card input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 13px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.08);
  color: white;
  outline: none;
  font: inherit;
  font-weight: 700;
}

.avatar-options {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 7px;
  margin-bottom: 10px;
}

.avatar-btn {
  min-height: 38px;
  border-radius: 10px;
  background: rgba(255,255,255,.08);
  border: 2px solid transparent;
  font-size: 1.25rem;
  cursor: pointer;
}

.avatar-btn.selected {
  border-color: var(--primary);
  background: rgba(99,102,241,.22);
}

.ranking-status {
  min-height: 20px;
  font-size: .85rem;
  color: var(--gold) !important;
}

.load-error {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
  z-index: 120;
  background: rgba(239,68,68,.14);
  border: 1px solid rgba(239,68,68,.35);
  color: #fecaca;
  border-radius: 14px;
  padding: 12px;
  font-size: .88rem;
}

@media (max-height: 760px) {
  .title-area {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .logo {
    font-size: 2.15rem;
  }

  h1 {
    font-size: 1.5rem;
  }

  .subtitle {
    font-size: .78rem;
  }

  .board {
    min-height: 360px;
  }

  .next-card {
    padding: 8px 11px;
  }

  .next-fruit {
    width: 36px;
    height: 36px;
  }
}

@media (max-width: 380px) {
  .avatar-options {
    grid-template-columns: repeat(4, 1fr);
  }

  .board {
    min-height: 390px;
  }
}
