:root {
  --text: #4a2d5c;
  --muted: #9a7fae;
  --accent: #ff5fa8;
  --accent-2: #ff9a3d;
  --good: #2bc48a;
  --card: rgba(255, 255, 255, 0.62);
  --card-strong: rgba(255, 255, 255, 0.8);
  --card-brd: rgba(160, 90, 170, 0.18);
  --shadow: 0 18px 50px rgba(160, 80, 160, 0.22);
}

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

.loading-screen {
  position: fixed; inset: 0; z-index: 999;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: linear-gradient(160deg, #ffd1e6 0%, #ff9ecb 45%, #b39dff 100%);
  transition: opacity 0.35s ease, visibility 0.35s ease;
}
.loading-screen.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-emoji { font-size: 64px; line-height: 1; animation: loading-bob 1.1s ease-in-out infinite; filter: drop-shadow(0 10px 18px rgba(0,0,0,0.25)); }
.loading-spinner { width: 34px; height: 34px; border-radius: 50%; border: 4px solid rgba(255,255,255,0.45); border-top-color: #fff; animation: loading-spin 0.8s linear infinite; }
.loading-text { font-weight: 800; font-size: 15px; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,0.2); }
@keyframes loading-spin { to { transform: rotate(360deg); } }
@keyframes loading-bob { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-10px) rotate(4deg); } }

html, body { margin: 0; height: 100%; }
body {
  min-height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1000px 700px at 12% -10%, rgba(255, 150, 200, 0.55), transparent 60%),
    radial-gradient(900px 600px at 108% 6%, rgba(150, 160, 255, 0.5), transparent 55%),
    radial-gradient(900px 720px at 50% 122%, rgba(140, 235, 190, 0.45), transparent 60%),
    linear-gradient(160deg, #fff1e9, #ffe1ec 45%, #e7e3ff);
  background-attachment: fixed;
  display: flex; align-items: center; justify-content: center;
  padding: 16px; overflow: hidden; position: relative;
}

.bokeh { position: fixed; border-radius: 50%; filter: blur(64px); opacity: 0.5; pointer-events: none; z-index: 0; animation: drift 18s ease-in-out infinite; }
.b1 { width: 320px; height: 320px; background: #ffb3d1; top: -80px; left: -60px; }
.b2 { width: 260px; height: 260px; background: #ffd29a; bottom: -60px; right: -40px; animation-delay: -4s; }
.b3 { width: 220px; height: 220px; background: #b7c4ff; bottom: 20%; left: -90px; animation-delay: -9s; }
.b4 { width: 200px; height: 200px; background: #b8f0d0; top: 8%; right: -70px; animation-delay: -13s; }
@keyframes drift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -28px) scale(1.08); }
  66% { transform: translate(-24px, 22px) scale(0.94); }
}

.app { position: relative; z-index: 1; width: min(420px, 100%); display: flex; flex-direction: column; gap: 14px; }

.hud { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.title {
  display: inline-flex; align-items: center; padding: 7px 16px;
  background: var(--card); border: 1px solid var(--card-brd); border-radius: 14px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 6px 18px rgba(160, 80, 160, 0.12);
}
.title span {
  font-weight: 800; font-size: clamp(18px, 5vw, 24px); letter-spacing: 0.5px;
  background: linear-gradient(92deg, #ff7ab8, #ff9a3d 46%, #a05bff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.chips { display: flex; align-items: center; gap: 8px; }
.chip {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 58px; padding: 6px 12px; background: var(--card); border: 1px solid var(--card-brd);
  border-radius: 14px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 6px 18px rgba(160, 80, 160, 0.12); line-height: 1.1;
}
.chip-label { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.chip-val { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--text); transition: transform 0.12s ease; }
.chip-val.pulse { transform: scale(1.28); color: var(--accent-2); }
.icon-btn { min-width: 44px; font-size: 20px; cursor: pointer; flex-direction: row; padding: 0; height: 44px; user-select: none; }
.icon-btn:hover { border-color: rgba(160, 80, 160, 0.32); }
.icon-btn:active { transform: scale(0.92); }

.pill-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.best-pill, .next-pill {
  display: flex; align-items: center; gap: 6px; padding: 4px 11px 4px 9px;
  background: var(--card); border: 1px solid var(--card-brd); border-radius: 999px;
  box-shadow: 0 4px 14px rgba(160, 80, 160, 0.16); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  flex: 1; justify-content: center;
}
.pill-label { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); }
.pill-emoji { font-size: 17px; font-weight: 800; color: var(--text); }
.pill-dot { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.15); box-shadow: inset 0 -2px 3px rgba(0,0,0,0.15), inset 0 2px 2px rgba(255,255,255,0.4); }

.stage {
  position: relative; border-radius: 22px; padding: 10px;
  background: rgba(255, 255, 255, 0.4); border: 1px solid rgba(160, 90, 170, 0.2);
  box-shadow: var(--shadow); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
#game { display: block; width: 100%; aspect-ratio: 8 / 16.4; touch-action: none; border-radius: 14px; }

.toast {
  position: absolute; top: 30%; left: 50%; transform: translate(-50%, -50%) scale(0.8);
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 28px;
  background: rgba(255, 255, 255, 0.88); border: 1px solid var(--card-brd); border-radius: 18px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); box-shadow: 0 16px 44px rgba(160, 80, 160, 0.3);
  text-align: center; opacity: 0; pointer-events: none; z-index: 6;
  transition: opacity 0.25s ease, transform 0.3s cubic-bezier(0.18, 1.4, 0.4, 1);
}
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.toast-emoji { font-size: 40px; line-height: 1; }
.toast-text { font-size: 15px; font-weight: 800; color: var(--text); }
.toast.big .toast-emoji { font-size: 58px; }
.toast.big .toast-text { font-size: 20px; color: var(--accent-2); }

.overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(255, 240, 246, 0.6); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-radius: 22px; z-index: 5; transition: opacity 0.25s ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.overlay-card { text-align: center; max-width: 300px; animation: pop-in 0.35s cubic-bezier(0.18, 1.2, 0.4, 1); }
.big-emoji { font-size: 60px; line-height: 1; filter: drop-shadow(0 8px 18px rgba(160, 80, 160, 0.3)); animation: bob 3s ease-in-out infinite; }
.record-badge { display: inline-block; margin: 12px 0 2px; padding: 6px 16px; border-radius: 999px; font-size: 14px; font-weight: 900; color: #6a3a00; background: linear-gradient(135deg, #ffe08a, #ffb347); box-shadow: 0 8px 22px rgba(255, 179, 71, 0.4); }
.record-badge.hidden { display: none; }
.overlay-card h1 { margin: 12px 0 8px; font-size: 26px; font-weight: 800; color: var(--text); }
.overlay-card p { margin: 0 0 18px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.overlay-card p.result { font-size: 16px; color: var(--text); margin-bottom: 4px; }
.overlay-card p.result-fruit { font-size: 14px; color: var(--text); margin-bottom: 18px; }
.overlay-card b { color: var(--accent-2); }
.play-btn {
  font: inherit; font-weight: 800; font-size: 17px; color: #4a1030; padding: 13px 36px; border: none;
  border-radius: 16px; cursor: pointer; background: linear-gradient(135deg, var(--accent-2), var(--accent));
  box-shadow: 0 10px 26px rgba(255, 95, 168, 0.35); transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.play-btn:hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(255, 95, 168, 0.45); }
.play-btn:active { transform: translateY(1px) scale(0.97); }
.link-btn { display: inline-block; margin-top: 10px; font: inherit; font-weight: 700; font-size: 13px; color: var(--text); background: none; border: none; cursor: pointer; text-decoration: underline; opacity: 0.85; }
.link-btn:hover { opacity: 1; }

@keyframes pop-in { from { opacity: 0; transform: scale(0.85) translateY(12px); } to { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }

.set-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 14px; margin-bottom: 10px;
  border: 1px solid var(--card-brd); border-radius: 14px; background: rgba(255, 255, 255, 0.5);
  font-size: 15px; font-weight: 700; color: var(--text);
}
.toggle { position: relative; width: 50px; height: 28px; flex: none; border: none; border-radius: 999px; cursor: pointer; background: rgba(160, 90, 170, 0.25); transition: background 0.18s ease; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,0.25); transition: transform 0.18s ease; }
.toggle.on { background: linear-gradient(135deg, var(--accent-2), var(--good)); }
.toggle.on::after { transform: translateX(22px); }

.lb-section { margin: 2px 0 16px; }
.lb-submit { display: flex; gap: 8px; margin-bottom: 10px; }
.lb-input { flex: 1; min-width: 0; font: inherit; font-size: 14px; padding: 9px 12px; border-radius: 12px; border: 1px solid var(--card-brd); background: rgba(255,255,255,0.7); color: var(--text); }
.lb-input::placeholder { color: var(--muted); }
.lb-input:focus { outline: none; border-color: var(--accent); }
.lb-btn { font: inherit; font-weight: 800; font-size: 13px; white-space: nowrap; padding: 0 14px; border: none; border-radius: 12px; cursor: pointer; color: #4a1030; background: linear-gradient(135deg, var(--accent-2), var(--accent)); }
.lb-rank-msg { margin: 0; min-height: 16px; font-size: 13px; font-weight: 800; color: var(--accent); }
.lb-list { list-style: none; margin: 8px 0 0; padding: 0; max-height: 180px; overflow-y: auto; text-align: left; border: 1px solid var(--card-brd); border-radius: 14px; background: rgba(255,255,255,0.5); }
.lb-row { display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-bottom: 1px solid rgba(160,80,160,0.1); font-size: 13px; }
.lb-row:last-child { border-bottom: none; }
.lb-row.me { background: rgba(255, 154, 61, 0.24); }
.lb-pos { width: 20px; font-weight: 800; color: var(--muted); text-align: center; }
.lb-nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-weight: 700; }
.lb-sc { font-weight: 900; color: var(--text); font-variant-numeric: tabular-nums; }
.lb-empty { padding: 14px; text-align: center; color: var(--muted); font-size: 13px; }

.touch-controls { display: flex; align-items: center; justify-content: center; gap: 10px; }
.ctl-btn {
  flex: 1; max-width: 78px; min-height: 52px; display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 800; color: var(--text); cursor: pointer;
  background: var(--card); border: 1px solid var(--card-brd); border-radius: 16px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); box-shadow: 0 6px 18px rgba(160,80,160,0.14);
  transition: transform 0.1s ease, background 0.15s ease; user-select: none;
}
.ctl-btn:active { transform: scale(0.9); background: rgba(255,255,255,0.85); }
.ctl-rotate { max-width: 64px; font-size: 24px; color: var(--accent); }
.ctl-down { color: var(--accent-2); }

.hint { margin: 0; text-align: center; font-size: 12px; color: var(--muted); }

@media (max-height: 760px) { .hint { display: none; } .big-emoji { font-size: 50px; } .overlay-card h1 { font-size: 22px; } }
