/* Paju — UI styles. Theme colours live in the two blocks at the top. */
:root,
:root[data-theme="light"] {
  --text: #0f172a;
  --muted: #51607a;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-border: rgba(15, 23, 42, 0.08);
  --card: rgba(255, 255, 255, 0.92);
  --card-hover: #ffffff;
  --chip: rgba(15, 23, 42, 0.06);
  --chip-on: #0f172a;
  --chip-on-text: #ffffff;
  --hud-bg: rgba(255, 255, 255, 0.78);
  --hud-text: #0f172a;
  --shadow: 0 18px 50px rgba(15, 35, 80, 0.22);
  --scrim: linear-gradient(180deg, rgba(255, 255, 255, 0) 30%, rgba(214, 236, 251, 0.55));
  --accent: #ff5a1f;
  --accent-2: #ffb703;
  --legend-bg: linear-gradient(180deg, #d4ecfb, #8b9099 60%, #5a5e69);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --text: #eef2ff;
  --muted: #9aa6c7;
  --panel: rgba(12, 16, 36, 0.84);
  --panel-border: rgba(255, 255, 255, 0.08);
  --card: rgba(255, 255, 255, 0.05);
  --card-hover: rgba(255, 255, 255, 0.1);
  --chip: rgba(255, 255, 255, 0.08);
  --chip-on: #ffd166;
  --chip-on-text: #111827;
  --hud-bg: rgba(8, 11, 26, 0.66);
  --hud-text: #eef2ff;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
  --scrim: linear-gradient(180deg, rgba(3, 5, 13, 0) 25%, rgba(3, 5, 13, 0.6));
  --accent: #ff7a2f;
  --accent-2: #ffd166;
  --legend-bg: linear-gradient(180deg, #1d2350, #2f323b 60%, #24272f);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0b1020;
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }

#game {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
}

/* ---------- screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow-y: auto;
  z-index: 10;
  background: rgba(0, 0, 0, 0.25);
  animation: fade-in 0.25s ease;
}
.screen.active { display: flex; }
.screen-menu { background: var(--scrim); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.panel {
  width: min(480px, 100%);
  margin: auto;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 18px;
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  backdrop-filter: blur(16px) saturate(1.3);
  animation: rise 0.3s cubic-bezier(.2, .9, .3, 1.2);
}
.panel.narrow { width: min(380px, 100%); }
@keyframes rise { from { transform: translateY(14px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }
.panel-title {
  margin: 2px 4px 12px;
  font-size: 0.82rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 800;
}
.panel-title.center { text-align: center; font-size: 1.4rem; letter-spacing: 0.02em; text-transform: none; color: var(--text); margin: 6px 0 16px; }
.panel-sub { margin: 16px 4px 8px; font-size: 0.8rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }

/* ---------- menu ---------- */
.menu-layout {
  width: min(480px, 100%);
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.brand { text-align: center; padding-top: 4px; }
.logo {
  margin: 0;
  font-family: "Arial Black", "Segoe UI Black", "Helvetica Neue", system-ui, sans-serif;
  font-weight: 900;
  font-style: italic;
  font-size: clamp(3.6rem, 17vw, 6.4rem);
  line-height: 0.95;
  letter-spacing: 0.02em;
  position: relative;
  display: inline-block;
  transform: skewX(-8deg);
}
.logo span {
  background: linear-gradient(180deg, #ffe08a 0%, #ff9a3c 45%, #ff3d3d 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 2px rgba(60, 10, 0, 0.35);
  filter: drop-shadow(0 4px 0 rgba(90, 20, 0, 0.45)) drop-shadow(0 10px 24px rgba(0, 0, 0, 0.25));
}
.logo::before, .logo::after {
  content: "";
  position: absolute;
  left: -38%;
  height: 5px;
  border-radius: 4px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.85));
  animation: streak 1.8s linear infinite;
}
.logo::before { top: 34%; width: 32%; }
.logo::after { top: 62%; width: 22%; left: -28%; animation-delay: 0.5s; }
@keyframes streak { 0% { transform: translateX(-40px); opacity: 0; } 30% { opacity: 1; } 100% { transform: translateX(30px); opacity: 0; } }
.tagline {
  margin: 6px 0 0;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}

.modes { display: flex; flex-direction: column; gap: 8px; }
.mode {
  --c: #22c55e;
  display: grid;
  grid-template-columns: 44px 1fr auto 18px;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 10px 12px 10px 10px;
  border-radius: 16px;
  border: 1px solid var(--panel-border);
  background: var(--card);
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.mode::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 5px;
  background: var(--c);
}
.mode:hover { transform: translateY(-2px); background: var(--card-hover); box-shadow: 0 8px 22px rgba(0, 0, 0, 0.12); }
.mode:active { transform: scale(0.985); }
.mode-easy { --c: #22c55e; }
.mode-medium { --c: #3b82f6; }
.mode-hard { --c: #f97316; }
.mode-evil { --c: #ef4444; }
.mode-endless { --c: #a855f7; }
.mode-evil { background: linear-gradient(90deg, rgba(239, 68, 68, 0.14), transparent 70%), var(--card); }
.mode-endless { background: linear-gradient(90deg, rgba(168, 85, 247, 0.16), rgba(59, 130, 246, 0.08) 70%), var(--card); }
.lanes {
  height: 36px;
  border-radius: 8px;
  background: #4b4f5a;
  display: flex;
  justify-content: space-evenly;
  align-items: stretch;
  padding: 4px 3px;
  transform: perspective(60px) rotateX(28deg);
  border-left: 3px solid #f4f4f4;
  border-right: 3px solid #f4f4f4;
}
.lanes i {
  width: 2px;
  background: repeating-linear-gradient(180deg, #fff 0 5px, transparent 5px 9px);
}
.lanes i:first-child { display: none; }
.mode-text { display: flex; flex-direction: column; min-width: 0; }
.mode-name { font-weight: 900; font-size: 1.08rem; color: var(--text); }
.mode-meta { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.mode-best { text-align: right; font-weight: 900; font-size: 0.95rem; color: var(--c); line-height: 1.05; }
.mode-best small { display: block; font-size: 0.65rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.mode-go { color: var(--muted); display: flex; }
.mode-go svg { width: 18px; height: 18px; }

.settings-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  justify-content: center;
}
.chip, .seg button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: var(--chip);
  font-weight: 800;
  font-size: 0.88rem;
  min-height: 38px;
}
.chip svg { width: 18px; height: 18px; fill: currentColor; }
.chip:hover, .seg button:hover { filter: brightness(1.08); }
.seg { display: inline-flex; border-radius: 999px; background: var(--chip); padding: 3px; border: 1px solid var(--panel-border); }
.seg button { border: 0; background: transparent; padding: 5px 12px; min-height: 30px; }
.seg button.on { background: var(--chip-on); color: var(--chip-on-text); }

/* ---------- help ---------- */
.help-text { margin: 0 4px 10px; line-height: 1.5; color: var(--text); font-weight: 600; }
.legend { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.legend figure { margin: 0; text-align: center; }
.legend canvas {
  width: 100%;
  aspect-ratio: 168 / 124;
  border-radius: 12px;
  background: var(--legend-bg);
  display: block;
}
.legend figcaption { font-size: 0.74rem; font-weight: 800; margin-top: 4px; color: var(--muted); }
@media (max-width: 420px) { .legend { grid-template-columns: repeat(3, 1fr); } }

/* ---------- buttons ---------- */
.btn-row, .btn-col { display: flex; gap: 10px; margin-top: 16px; }
.btn-col { flex-direction: column; }
.btn {
  flex: 1;
  padding: 13px 18px;
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  background: var(--chip);
  font-weight: 900;
  font-size: 1rem;
  transition: transform 0.12s ease, filter 0.12s ease;
}
.btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.btn:active { transform: scale(0.98); }
.btn.primary {
  background: linear-gradient(180deg, #ff8a3d, var(--accent));
  color: #fff;
  border: 0;
  box-shadow: 0 6px 0 #c73d0c, 0 12px 24px rgba(255, 90, 31, 0.35);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}
.btn.primary:active { box-shadow: 0 2px 0 #c73d0c; transform: translateY(4px); }

/* ---------- game over ---------- */
.result-badge {
  width: 64px; height: 64px;
  margin: 4px auto 6px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(180deg, #ff6b6b, #d62828);
  box-shadow: 0 8px 24px rgba(214, 40, 40, 0.4);
}
.panel.win .result-badge { background: linear-gradient(180deg, #ffd166, #f59e0b); box-shadow: 0 8px 24px rgba(245, 158, 11, 0.45); }
.result-badge svg { width: 34px; height: 34px; fill: currentColor; }
.result-mode {
  display: table;
  margin: 0 auto;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #fff;
  background: var(--c, #64748b);
}
.result-title { margin: 6px 0 2px; text-align: center; font-size: 1.6rem; font-weight: 900; }
.result-sub { margin: 0 0 12px; text-align: center; color: var(--muted); font-weight: 700; min-height: 1em; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat {
  background: var(--chip);
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
}
.stat span { font-size: 0.64rem; line-height: 1.2; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 800; }
.stat b { font-size: 1.15rem; font-weight: 900; margin-top: 2px; }
.stat.big { grid-column: 1 / -1; align-items: center; }
.stat.big b { font-size: 2.2rem; color: var(--accent); }
.best-line { grid-column: 1 / -1; text-align: center; font-weight: 700; color: var(--muted); margin-top: 2px; }
.new-best {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  color: #3b2300;
  background: linear-gradient(90deg, #ffd166, #ffb703);
  font-weight: 900;
  animation: pulse 1s ease-in-out infinite alternate;
}
@keyframes pulse { to { transform: scale(1.06); } }

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
  pointer-events: none;
  z-index: 5;
}
.hud[hidden] { display: none; }
.hud-left { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.hud-center { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.hud-right { display: flex; justify-content: flex-end; }
.pill {
  background: var(--hud-bg);
  color: var(--hud-text);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 800;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  white-space: nowrap;
}
.pill.small { font-size: 0.8rem; padding: 4px 10px; }
.pill.small span { color: var(--muted); font-weight: 700; }
.timer { font-size: 1.6rem; font-variant-numeric: tabular-nums; padding: 4px 18px; letter-spacing: 0.02em; }
.timer.warn { color: #fff; background: #e5383b; animation: pulse 0.5s ease-in-out infinite alternate; }
.hearts { display: flex; gap: 3px; padding: 6px 10px; }
.heart { width: 20px; height: 20px; fill: rgba(127, 127, 127, 0.35); }
.heart.full { fill: #ff3b5c; filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.2)); }
.hearts.hurt { animation: shake 0.4s ease; }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
.icon-btn {
  pointer-events: auto;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--hud-bg);
  color: var(--hud-text);
  display: grid;
  place-items: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }

.countdown {
  position: fixed;
  left: 0; right: 0; top: 38%;
  text-align: center;
  font-family: "Arial Black", "Segoe UI Black", system-ui, sans-serif;
  font-style: italic;
  font-weight: 900;
  font-size: clamp(4rem, 22vw, 9rem);
  color: #fff;
  -webkit-text-stroke: 3px rgba(0, 0, 0, 0.35);
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.25), 0 12px 30px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  z-index: 6;
  transform: translateY(-50%);
}
.countdown.pop { animation: pop 0.9s cubic-bezier(.2, .9, .3, 1.3) both; }
.countdown.go { color: #ffd166; }
@keyframes pop {
  0% { transform: translateY(-50%) scale(1.8); opacity: 0; }
  20% { transform: translateY(-50%) scale(1); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translateY(-50%) scale(0.9); opacity: 0; }
}

.hint {
  position: fixed;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--hud-bg);
  color: var(--hud-text);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 6;
  white-space: nowrap;
}
.hint.show { opacity: 1; transform: translate(-50%, 0); }

/* Landscape / desktop: logo beside the menu */
@media (min-width: 860px) and (min-aspect-ratio: 5/4) {
  .menu-layout { width: min(980px, 100%); flex-direction: row; align-items: center; gap: 40px; }
  .brand { flex: 1; text-align: left; }
  .menu-layout .panel { flex: 0 0 440px; }
}
@media (max-height: 560px) and (orientation: landscape) {
  .logo { font-size: 3rem; }
  .menu-layout { width: min(900px, 100%); flex-direction: row; align-items: center; gap: 20px; }
  .brand { flex: 0 0 34%; }
  .mode { padding: 6px 10px 6px 8px; }
  .lanes { height: 28px; }
  .timer { font-size: 1.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
