:root {
  --ink: #eafcff;
  --ink-dim: #9fd3e3;
  --panel: rgba(4, 34, 58, 0.72);
  --panel-solid: rgba(3, 26, 46, 0.92);
  --stroke: rgba(140, 230, 255, 0.25);
  --accent: #35e0d0;
  --accent-2: #ffd166;
  --danger: #ff5a6e;
  --radius: 16px;
  --font: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #021a2b;
  color: var(--ink);
  font-family: var(--font);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.hidden { display: none !important; }

/* ---------------- Screens & panels ---------------- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 20;
  animation: fadeIn 0.25s ease;
  overflow-y: auto;
}
#pause, #gameover, #howto, #settings, #achievements { background: rgba(1, 16, 30, 0.45); backdrop-filter: blur(3px); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: translateY(14px) scale(0.97); } to { opacity: 1; transform: none; } }

.menu-card, .panel {
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(8px);
  padding: 28px 32px;
  text-align: center;
  animation: popIn 0.3s ease;
  max-width: 100%;
  margin: auto;
}
.menu-card { width: 440px; background: rgba(4, 34, 58, 0.55); }
.panel { width: 680px; }
.panel-narrow { width: 400px; }

h2 {
  margin: 0 0 18px;
  font-size: 30px;
  letter-spacing: 2px;
  color: var(--accent);
  text-shadow: 0 2px 12px rgba(53, 224, 208, 0.35);
}

.title {
  margin: 0 0 6px;
  line-height: 0.95;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.title-top {
  font-size: 30px;
  letter-spacing: 14px;
  color: var(--ink-dim);
  margin-right: -14px;
}
.title-bottom {
  font-size: 54px;
  font-weight: 900;
  letter-spacing: 3px;
  background: linear-gradient(180deg, #ffffff 0%, #7ff6ea 45%, #19b6d6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 14px rgba(25, 182, 214, 0.55));
}
.tagline { color: var(--ink-dim); margin: 10px 0 24px; font-size: 15px; }

.btn {
  display: block;
  width: 100%;
  margin: 10px 0;
  padding: 13px 18px;
  font: 700 16px var(--font);
  letter-spacing: 1.5px;
  color: var(--ink);
  background: rgba(120, 220, 255, 0.1);
  border: 1px solid var(--stroke);
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover { background: rgba(120, 220, 255, 0.2); transform: translateY(-1px); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn-primary {
  font-size: 24px;
  padding: 16px;
  color: #032a3a;
  background: linear-gradient(180deg, #7ff6ea, #22c6d8);
  border: none;
  box-shadow: 0 8px 24px rgba(34, 198, 216, 0.45), inset 0 -3px 0 rgba(0, 0, 0, 0.15);
}
.btn-primary:hover { background: linear-gradient(180deg, #a5fff5, #33d5e6); box-shadow: 0 10px 30px rgba(34, 198, 216, 0.6); }
.btn-small { font-size: 13px; padding: 9px 14px; }
.btn-danger { color: #ffb3bd; border-color: rgba(255, 90, 110, 0.35); background: rgba(255, 90, 110, 0.08); }
.btn-back { margin-top: 18px; }
.menu-row { display: flex; gap: 10px; }
.menu-row .btn { flex: 1; font-size: 14px; }

.menu-best { margin-top: 14px; color: var(--ink-dim); font-size: 13px; min-height: 16px; }
.menu-best b { color: var(--accent-2); }

/* How to play */
.howto-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; text-align: left; }
.howto-item {
  display: flex; gap: 12px; align-items: flex-start;
  background: rgba(120, 220, 255, 0.06);
  border: 1px solid rgba(140, 230, 255, 0.12);
  border-radius: 14px; padding: 12px; font-size: 14px; line-height: 1.4; color: #cdeef7;
}
.howto-item b { color: var(--ink); }
.howto-ico { font-size: 26px; line-height: 1; }
.red { color: var(--danger); font-weight: 700; }
.hint { color: var(--ink-dim); font-size: 13px; margin: 14px 0 0; }

/* Settings */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 4px; border-bottom: 1px solid rgba(140, 230, 255, 0.1);
  cursor: pointer; font-size: 16px; gap: 12px; text-align: left;
}
.toggle-row input { display: none; }
.switch {
  width: 46px; height: 26px; border-radius: 13px; background: rgba(255, 255, 255, 0.15);
  position: relative; transition: background 0.2s; flex-shrink: 0;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; transition: transform 0.2s;
}
.toggle-row input:checked + .switch { background: var(--accent); }
.toggle-row input:checked + .switch::after { transform: translateX(20px); }
.seg { display: flex; border: 1px solid var(--stroke); border-radius: 10px; overflow: hidden; }
.seg button {
  font: 600 14px var(--font); color: var(--ink); background: transparent; border: none;
  padding: 7px 14px; cursor: pointer;
}
.seg button.active { background: var(--accent); color: #032a3a; }
#btn-reset-progress { margin-top: 18px; }

/* Achievements */
.ach-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: left; }
.ach {
  display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 14px;
  background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.08); opacity: 0.55;
}
.ach.unlocked { opacity: 1; background: rgba(255, 209, 102, 0.1); border-color: rgba(255, 209, 102, 0.4); }
.ach-ico { font-size: 26px; filter: grayscale(1); }
.ach.unlocked .ach-ico { filter: none; }
.ach-name { font-weight: 700; font-size: 15px; }
.ach-desc { font-size: 12.5px; color: var(--ink-dim); }

/* Game over */
.go-title { color: var(--danger); text-shadow: 0 2px 14px rgba(255, 90, 110, 0.45); margin-bottom: 4px; }
.go-killer { color: var(--ink-dim); margin: 0 0 12px; }
.newbest {
  color: var(--accent-2); font-weight: 800; letter-spacing: 2px; margin-bottom: 10px;
  animation: pulse 1s ease-in-out infinite alternate;
}
@keyframes pulse { from { opacity: 0.6; transform: scale(0.97); } to { opacity: 1; transform: scale(1.03); } }
.go-table { width: 100%; border-collapse: collapse; margin: 6px 0 14px; font-size: 15px; }
.go-table th { font-size: 12px; letter-spacing: 1px; color: var(--ink-dim); font-weight: 600; padding: 4px; text-align: right; }
.go-table td { padding: 6px 4px; border-top: 1px solid rgba(140, 230, 255, 0.1); text-align: right; }
.go-table td:first-child { text-align: left; color: var(--ink-dim); }
.go-table td:nth-child(2) { font-weight: 700; }
.go-table tr.total td { font-size: 18px; color: var(--accent-2); }

/* ---------------- HUD ---------------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.hud-panel {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.hud-left { top: 12px; left: 12px; padding: 10px 14px; width: 230px; }
.stage-row { display: flex; gap: 10px; align-items: center; }
.stage-icon { font-size: 26px; }
.stage-row > div { flex: 1; }
.stage-name { font-weight: 800; font-size: 16px; letter-spacing: 0.5px; }
.progress, .stamina {
  height: 7px; border-radius: 4px; background: rgba(255, 255, 255, 0.12); overflow: hidden; margin-top: 5px;
}
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, #7ff6ea, #ffd166); transition: width 0.3s; }
.hud-stats { display: flex; justify-content: space-between; margin-top: 9px; font-size: 14px; font-weight: 700; }
.stat { display: flex; align-items: center; gap: 5px; }
.ico { font-size: 13px; opacity: 0.85; }
.stamina-row { display: flex; align-items: center; gap: 8px; margin-top: 7px; }
.stamina { flex: 1; margin-top: 0; height: 8px; }
.stamina-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #ffd166, #ff9f43); }
.stamina-fill.low { background: #ff5a6e; }

.hud-score { top: 12px; left: 50%; transform: translateX(-50%); padding: 6px 22px 8px; text-align: center; min-width: 150px; }
.score-label { font-size: 10px; letter-spacing: 3px; color: var(--ink-dim); }
.score-value { font-size: 26px; font-weight: 900; line-height: 1.05; color: var(--accent-2); }
.zone-label { font-size: 11px; letter-spacing: 1px; color: var(--ink-dim); }

.icon-btn {
  position: absolute; top: 12px; right: 12px; width: 44px; height: 44px;
  border-radius: 12px; border: 1px solid var(--stroke); background: var(--panel);
  color: var(--ink); font-size: 15px; cursor: pointer; pointer-events: auto; backdrop-filter: blur(6px);
}
#minimap {
  position: absolute; right: 12px; bottom: 12px; width: 180px; height: 90px;
  border-radius: 12px; border: 1px solid var(--stroke); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}
.boost-btn {
  display: none;
  position: absolute; left: 20px; bottom: 24px; width: 86px; height: 86px; border-radius: 50%;
  border: 2px solid rgba(255, 209, 102, 0.7);
  background: radial-gradient(circle at 40% 35%, rgba(255, 209, 102, 0.55), rgba(255, 159, 67, 0.25));
  color: #fff; font: 800 14px var(--font); letter-spacing: 1px; pointer-events: auto;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}
.boost-btn.active { transform: scale(0.93); background: radial-gradient(circle, rgba(255, 209, 102, 0.9), rgba(255, 159, 67, 0.5)); }
body.touch .boost-btn { display: block; }

/* Banner & toasts */
.banner {
  position: fixed; top: 22%; left: 50%; transform: translate(-50%, -50%);
  z-index: 15; pointer-events: none; text-align: center; opacity: 0;
  font-weight: 900; font-size: 34px; letter-spacing: 2px; color: #fff;
  text-shadow: 0 3px 18px rgba(0, 0, 0, 0.6), 0 0 30px rgba(127, 246, 234, 0.6);
  transition: opacity 0.35s ease, transform 0.35s ease; white-space: nowrap;
}
.banner small { display: block; font-size: 15px; letter-spacing: 3px; color: var(--accent-2); font-weight: 700; }
.banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1.04); }

#toasts {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 30; pointer-events: none;
}
.toast {
  background: var(--panel-solid); border: 1px solid rgba(255, 209, 102, 0.5); border-radius: 14px;
  padding: 9px 16px; font-size: 14px; display: flex; gap: 10px; align-items: center;
  animation: toastIn 0.35s ease, toastOut 0.4s ease 3.2s forwards; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.toast b { color: var(--accent-2); }
.toast.info { border-color: rgba(127, 246, 234, 0.5); }
.toast.info b { color: var(--accent); }
@keyframes toastIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

/* ---------------- Responsive ---------------- */
@media (max-width: 720px) {
  .howto-grid, .ach-list { grid-template-columns: 1fr; }
  .panel { padding: 22px 18px; }
  .title-bottom { font-size: 42px; }
  .title-top { font-size: 24px; letter-spacing: 11px; margin-right: -11px; }
  .hud-left { width: 180px; padding: 8px 10px; }
  .stage-name { font-size: 13px; }
  .stage-icon { font-size: 20px; }
  .hud-stats { font-size: 12px; }
  .hud-score { top: auto; bottom: 12px; padding: 4px 14px 6px; min-width: 110px; }
  body.touch .hud-score { left: auto; right: 12px; transform: none; bottom: 84px; }
  .score-value { font-size: 20px; }
  #minimap { width: 120px; height: 60px; }
  .banner { font-size: 24px; }
  .banner small { font-size: 12px; }
}
@media (max-height: 520px) {
  .menu-card { padding: 16px 24px; }
  .title-bottom { font-size: 38px; }
  .tagline { margin: 6px 0 10px; }
  .btn { margin: 6px 0; padding: 9px; }
  .btn-primary { font-size: 20px; padding: 11px; }
}
