:root {
  --sky-top: #0b1330;
  --sky-mid: #1e2a5e;
  --sky-bottom: #3a2f6e;
  --sun: #ffb347;
  --sun-bright: #ffe28a;
  --ink: #f4f1ea;
  --ink-dim: #c7c3d9;
  --panel: rgba(10, 14, 34, 0.72);
  --panel-border: rgba(255, 255, 255, 0.14);
  --accent: #ff8a5c;
  --accent-2: #6ce0d6;
  --good: #7be08a;
  --bad: #ff6b6b;
  --radius: 18px;
  --gap: 16px;
  --nav-h: 68px;
  --topbar-h: 52px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  background: var(--sky-mid);
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button, input {
  font-family: inherit;
}

#horizon-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  display: block;
}

.app {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- Entry screen ---------- */

#screen-entry {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.entry-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 28px 22px;
  backdrop-filter: blur(10px);
  text-align: center;
}

.kost-mark {
  display: block;
  filter: drop-shadow(0 4px 14px rgba(255, 179, 71, 0.35));
}

.kost-mark-hero {
  width: 88px;
  height: 88px;
  margin: 0 auto 10px;
}

.kost-mark-small {
  width: 26px;
  height: 26px;
  flex: none;
}

.kost-eyebrow {
  margin: 0 0 4px;
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-2);
}

.wordmark {
  font-size: 1.7rem;
  margin: 0 0 8px;
  letter-spacing: 0.02em;
  background: linear-gradient(90deg, var(--sun-bright), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  color: var(--ink-dim);
  font-size: 0.92rem;
  line-height: 1.5;
  margin: 0 0 24px;
}

.entry-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.entry-hint {
  text-align: left;
  font-size: 0.76rem;
  color: var(--ink-dim);
  margin: -2px 0 8px;
}

.entry-label {
  text-align: left;
  font-size: 0.85rem;
  color: var(--ink-dim);
}

#passphrase-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--ink);
  font-size: 1rem;
}

.entry-error {
  color: var(--bad);
  font-size: 0.88rem;
  margin: 0;
}

/* ---------- Buttons ---------- */

.btn {
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  padding: 12px 18px;
  transition: transform 0.12s ease, filter 0.12s ease;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--sun), var(--accent));
  color: #241200;
}

.btn-large {
  width: 100%;
  padding: 16px;
  font-size: 1.05rem;
  min-height: 52px;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--panel-border);
}

/* ---------- Main app shell ---------- */

.topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  background: rgba(6, 9, 24, 0.55);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--panel-border);
}

.topbar-wordmark {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

.topbar-player {
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  background: linear-gradient(135deg, var(--sun), var(--accent));
  color: #241200;
}

.view {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px calc(var(--nav-h) + 24px);
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--nav-h);
  display: flex;
  background: rgba(6, 9, 24, 0.82);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--panel-border);
  z-index: 5;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--ink-dim);
  font-size: 0.72rem;
  cursor: pointer;
  min-height: 52px;
}

.nav-btn.active {
  color: var(--sun-bright);
}

.nav-icon {
  font-size: 1.2rem;
}

/* ---------- Chamber shared UI ---------- */

.chamber-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

/* ---------- Chamber hero icon ---------- */

.chamber-icon {
  position: relative;
  width: 84px;
  height: 84px;
  margin: 0 auto 12px;
}

.chamber-icon::before {
  content: "";
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 179, 71, 0.45), transparent 70%);
  filter: blur(6px);
  animation: icon-glow-breathe 3.2s ease-in-out infinite;
  z-index: 0;
}

.chamber-icon svg {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 3px 10px rgba(255, 138, 92, 0.35));
}

.chamber-icon svg g,
.chamber-icon svg rect,
.chamber-icon svg circle,
.chamber-icon svg path {
  transform-box: view-box;
  transform-origin: 50px 50px;
}

@keyframes icon-glow-breathe {
  0%, 100% { opacity: 0.55; transform: scale(0.94); }
  50% { opacity: 1; transform: scale(1.06); }
}

.icon-anim-rotate {
  animation: icon-rotate 7s linear infinite;
}
@keyframes icon-rotate {
  to { transform: rotate(360deg); }
}

.icon-anim-bob-a { animation: icon-bob-a 2.6s ease-in-out infinite; }
.icon-anim-bob-b { animation: icon-bob-b 2.3s ease-in-out infinite 0.3s; }
.icon-anim-bob-c { animation: icon-bob-c 2.9s ease-in-out infinite 0.6s; }
@keyframes icon-bob-a {
  0%, 100% { transform: rotate(-12deg) translateY(0); }
  50% { transform: rotate(-12deg) translateY(-5px); }
}
@keyframes icon-bob-b {
  0%, 100% { transform: rotate(9deg) translateY(0); }
  50% { transform: rotate(9deg) translateY(-6px); }
}
@keyframes icon-bob-c {
  0%, 100% { transform: rotate(-4deg) translateY(0); }
  50% { transform: rotate(-4deg) translateY(-4px); }
}

.icon-anim-pulse {
  animation: icon-pulse 1.9s ease-in-out infinite;
}
@keyframes icon-pulse {
  0%, 100% { opacity: 0.65; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.15); }
}

.icon-anim-twinkle {
  animation: icon-twinkle 1.7s ease-in-out infinite;
}
@keyframes icon-twinkle {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 1; }
}

.icon-anim-ripple {
  transform: scale(0.4);
  opacity: 0.9;
  animation: icon-ripple 1.8s ease-out infinite;
}
@keyframes icon-ripple {
  0% { transform: scale(0.4); opacity: 0.9; }
  100% { transform: scale(1.7); opacity: 0; }
}

.icon-anim-flow {
  stroke-dasharray: 10 7;
  animation: icon-flow 1.4s linear infinite;
}
@keyframes icon-flow {
  to { stroke-dashoffset: -34; }
}

.icon-anim-slide {
  animation: icon-slide 2.4s ease-in-out infinite;
}
@keyframes icon-slide {
  0%, 100% { transform: translateX(-14px); }
  50% { transform: translateX(14px); }
}

/* ---------- Unlock ring (plays once, on chamber solve) ---------- */

.unlock-ring {
  position: fixed;
  z-index: 30;
  width: 20px;
  height: 20px;
  margin-left: -10px;
  margin-top: -10px;
  border-radius: 50%;
  border: 3px solid var(--sun-bright);
  pointer-events: none;
  animation: unlock-ring-expand 850ms ease-out forwards;
}
@keyframes unlock-ring-expand {
  0% { transform: scale(0.5); opacity: 1; }
  100% { transform: scale(6); opacity: 0; }
}

.chamber-stamp {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 6px;
}

.chamber-number {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent-2);
  margin: 0;
}

.chamber-title {
  margin: 0 0 12px;
  font-size: 1.25rem;
}

.chamber-flavor {
  color: var(--ink-dim);
  font-size: 0.92rem;
  line-height: 1.5;
  margin: 0 0 16px;
}

.chamber-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.hint-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  gap: 10px;
}

.hint-btn {
  font-size: 0.85rem;
  padding: 10px 14px;
}

.hint-count {
  font-size: 0.78rem;
  color: var(--ink-dim);
}

.hint-text {
  background: rgba(108, 224, 214, 0.1);
  border: 1px solid rgba(108, 224, 214, 0.3);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.86rem;
  color: var(--accent-2);
  margin-top: 10px;
}

.feedback {
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.88rem;
  margin-top: 4px;
}

.feedback.good { background: rgba(123, 224, 138, 0.14); color: var(--good); }
.feedback.bad { background: rgba(255, 107, 107, 0.14); color: var(--bad); }

.text-input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--ink);
  font-size: 1rem;
}

.tile-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tile {
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.06);
  font-weight: 700;
  font-size: 1.1rem;
  cursor: pointer;
  user-select: none;
}

.tile.used {
  opacity: 0.3;
  pointer-events: none;
}

.tile.answer {
  background: linear-gradient(135deg, var(--sun), var(--accent));
  color: #241200;
  border: none;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.choice-btn {
  padding: 16px 8px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
}

.choice-btn:active { transform: scale(0.96); }
.choice-btn.correct { background: rgba(123, 224, 138, 0.25); border-color: var(--good); }
.choice-btn.wrong { background: rgba(255, 107, 107, 0.25); border-color: var(--bad); }

.solved-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, rgba(123, 224, 138, 0.16), rgba(108, 224, 214, 0.12));
  border: 1px solid rgba(123, 224, 138, 0.35);
  border-radius: 12px;
  padding: 14px;
}

/* ---------- Leaderboard ---------- */

.lb-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
}

.lb-rank {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.05rem;
  color: #241200;
}

.rank-1 { background: linear-gradient(135deg, #ffe28a, #ffb347); }
.rank-2 { background: linear-gradient(135deg, #e7e7f2, #b9b9cf); }
.rank-3 { background: linear-gradient(135deg, #e3b98a, #a9713f); color: #241200; }
.rank-4 { background: linear-gradient(135deg, #7d86b8, #4a5286); color: #f4f1ea; }

.lb-main {
  flex: 1;
  min-width: 0;
}

.lb-player {
  font-weight: 700;
  font-size: 1.05rem;
}

.lb-meta {
  color: var(--ink-dim);
  font-size: 0.78rem;
  margin-top: 2px;
}

.lb-score {
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--sun-bright);
  white-space: nowrap;
}

/* ---------- Progress grid ---------- */

.progress-table {
  width: 100%;
  border-collapse: collapse;
}

.progress-table th, .progress-table td {
  padding: 6px 4px;
  text-align: center;
  font-size: 0.72rem;
}

.progress-table th:first-child, .progress-table td:first-child {
  text-align: left;
  font-weight: 700;
}

.cell-lock {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: inline-block;
  background: rgba(255, 255, 255, 0.08);
}

.cell-lock.done {
  background: linear-gradient(135deg, var(--sun), var(--accent));
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 16px);
  transform: translateX(-50%);
  background: rgba(10, 14, 34, 0.95);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 0.88rem;
  z-index: 20;
  max-width: 90vw;
  text-align: center;
}

/* ---------- Completion particles ---------- */

.particle {
  position: fixed;
  z-index: 30;
  border-radius: 50%;
  pointer-events: none;
  animation: particle-burst 900ms ease-out forwards;
}

@keyframes particle-burst {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--px), var(--py)) scale(0.3); opacity: 0; }
}

/* ---------- Final reveal ---------- */

.reveal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  background: linear-gradient(180deg, #0b1330, #3a2f6e 70%, #4a2f4e);
  overflow: hidden;
}

.reveal-sun {
  position: absolute;
  left: 50%;
  bottom: -30%;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--sun-bright), var(--sun) 55%, transparent 72%);
  transform: translateX(-50%);
  animation: reveal-rise 4s ease-out forwards;
}

@keyframes reveal-rise {
  from { bottom: -35%; opacity: 0.3; }
  to { bottom: 38%; opacity: 1; }
}

.reveal-title {
  position: relative;
  z-index: 2;
  font-size: 1.9rem;
  margin: 0 0 10px;
  opacity: 0;
  background: linear-gradient(90deg, var(--sun-bright), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: reveal-fade 1.4s ease 1.9s forwards;
}

.reveal-text {
  position: relative;
  z-index: 2;
  color: var(--ink-dim);
  max-width: 340px;
  opacity: 0;
  line-height: 1.5;
  animation: reveal-fade 1.4s ease 2.4s forwards;
}

.reveal-btn {
  position: relative;
  z-index: 2;
  margin-top: 26px;
  opacity: 0;
  animation: reveal-fade 1.4s ease 2.9s forwards;
}

@keyframes reveal-fade {
  to { opacity: 1; }
}

/* ---------- Utility ---------- */

[hidden] { display: none !important; }

@media (min-width: 560px) {
  .view { max-width: 520px; margin: 0 auto; width: 100%; }
  .bottom-nav { max-width: 560px; left: 50%; transform: translateX(-50%); }
}
