@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700&family=Space+Grotesk:wght@500;700&display=swap');

:root {
  --bg0: #0f1b14;
  --bg1: #163024;
  --bg2: #1e3d2e;
  --ink: #eef6f0;
  --muted: #9bb5a6;
  --accent: #3dcf8e;
  --accent-2: #f0c14b;
  --danger: #ff6b6b;
  --panel: rgba(18, 36, 28, 0.88);
  --line: rgba(238, 246, 240, 0.12);
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --font: 'Outfit', sans-serif;
  --display: 'Space Grotesk', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(61, 207, 142, 0.22), transparent 55%),
    radial-gradient(900px 500px at 90% 0%, rgba(240, 193, 75, 0.12), transparent 50%),
    linear-gradient(160deg, var(--bg0), var(--bg1) 45%, #0c1511);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
button, input { font: inherit; }
button { cursor: pointer; }

.shell {
  width: min(1100px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 3rem;
}

.brand {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: -0.03em;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  margin: 0;
}

.sub { color: var(--muted); margin: 0.4rem 0 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  padding: 1.5rem;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 0.75rem 1.2rem;
  font-weight: 600;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--accent); color: #062014; }
.btn-secondary { background: rgba(255,255,255,0.08); color: var(--ink); border: 1px solid var(--line); }
.btn-danger { background: rgba(255,107,107,0.18); color: #ffb4b4; border: 1px solid rgba(255,107,107,0.35); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.field { display: grid; gap: 0.4rem; margin-bottom: 1rem; }
.field label { font-size: 0.9rem; color: var(--muted); }
.field input, .field select {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.25);
  color: var(--ink);
  padding: 0.8rem 0.95rem;
  outline: none;
}
.field input:focus, .field select:focus { border-color: rgba(61,207,142,0.6); }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 1.25rem;
}
@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.shell-console {
  width: min(1180px, calc(100% - 2rem));
}
.topbar-right {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}
.console-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, 0.85fr);
  gap: 1.25rem;
  align-items: start;
}
.create-panel { position: sticky; top: 1rem; }
.panel-head h2 {
  margin: 0 0 0.35rem;
  font-family: var(--display);
  font-size: 1.25rem;
}
.panel-head p { margin: 0 0 1.1rem; }
.btn-block { width: 100%; }

.link-list {
  display: grid;
  gap: 0.85rem;
}
.empty-state {
  padding: 1.5rem 0.25rem;
  text-align: center;
}
.link-card {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) auto auto;
  gap: 1rem 1.25rem;
  align-items: center;
  padding: 1rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.18);
}
.link-card.is-disabled { opacity: 0.72; }
.link-main { min-width: 0; }
.link-title-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  margin-bottom: 0.2rem;
}
.link-title-row h3 {
  margin: 0;
  font-size: 1.05rem;
  font-family: var(--display);
}
.link-subtitle {
  margin: 0 0 0.65rem;
  font-size: 0.9rem;
  line-height: 1.35;
}
.link-url-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}
.link-slug {
  display: inline-block;
  max-width: 100%;
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  color: var(--accent);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.link-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(64px, 1fr));
  gap: 0.55rem;
}
.meta-item {
  display: grid;
  gap: 0.2rem;
  text-align: center;
  padding: 0.55rem 0.4rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  min-width: 68px;
}
.meta-item strong {
  font-family: var(--display);
  font-size: 1.05rem;
}
.meta-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.link-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 110px;
}
.link-actions .btn {
  font-size: 0.82rem;
  padding: 0.45rem 0.75rem;
  width: 100%;
}
.link-url-row .btn {
  font-size: 0.82rem;
  padding: 0.4rem 0.75rem;
  width: auto;
  white-space: nowrap;
}

.sessions-table th,
.sessions-table td {
  vertical-align: middle;
  padding: 0.85rem 0.65rem;
}
.sessions-table th:nth-child(4),
.sessions-table td:nth-child(4),
.sessions-table th:nth-child(5),
.sessions-table td:nth-child(5) {
  text-align: center;
}

@media (max-width: 980px) {
  .console-layout { grid-template-columns: 1fr; }
  .create-panel { position: static; }
  .link-card {
    grid-template-columns: 1fr;
    gap: 0.9rem;
  }
  .link-actions {
    flex-direction: row;
    flex-wrap: wrap;
    min-width: 0;
  }
  .link-actions .btn { width: auto; flex: 1 1 auto; }
}

.table-wrap { overflow: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
th, td {
  text-align: left;
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
th { color: var(--muted); font-weight: 500; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.04em; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9rem; }
.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(61,207,142,0.15);
  color: var(--accent);
}
.badge.warn { background: rgba(240,193,75,0.15); color: var(--accent-2); }
.badge.danger { background: rgba(255,107,107,0.15); color: #ffb4b4; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 12, 9, 0.72);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 50;
  animation: fadeIn 0.25s ease;
}
.modal {
  width: min(560px, 100%);
  background: linear-gradient(180deg, #1a3327, #14261d);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 1.6rem;
  box-shadow: var(--shadow);
  animation: rise 0.3s ease;
}
.modal h2 { font-family: var(--display); margin: 0 0 0.5rem; }
.modal ol { margin: 0.8rem 0 0; padding-left: 1.2rem; color: var(--muted); }
.modal ol li { margin: 0.35rem 0; }
.modal-actions { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.4rem; flex-wrap: wrap; }

.play-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.stat-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.stat {
  background: rgba(0,0,0,0.22);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.55rem 0.85rem;
  min-width: 110px;
}
.stat b { display: block; font-family: var(--display); font-size: 1.15rem; }
.stat span { color: var(--muted); font-size: 0.78rem; }

.game-stage {
  min-height: 420px;
  display: grid;
  place-items: center;
  padding: 1rem 0;
}

.ref-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
}
.prompt {
  font-size: 0.98rem;
  color: var(--muted);
  text-align: center;
  max-width: 480px;
  line-height: 1.5;
  min-height: 2.6rem;
}
.prompt strong { color: var(--ink); }
.level-note { font-size: 0.85rem; letter-spacing: 0.02em; }
.level-clock {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
}
.answer-line { font-size: 0.82rem; color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* Memory Mazes */
.maze-grid {
  display: grid;
  gap: 4px;
  touch-action: manipulation;
}
.cell {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 1.25rem;
}
.cell.tight { width: 44px; height: 44px; font-size: 1rem; }
.cell.wall { background: #040806; border-color: #1a2a20; }
.cell.bump { background: var(--accent); border-color: var(--accent); color: #062014; animation: shake 0.25s; }
.cell.door { border-color: var(--accent); border-style: dashed; }
.cell.you { background: var(--accent); border-color: var(--accent); color: #062014; }

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 48px);
  gap: 6px;
  justify-content: center;
  margin-top: 0.25rem;
}
.dpad button {
  height: 44px;
  background: rgba(0,0,0,0.28);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-size: 1rem;
  cursor: pointer;
}
.dpad button:hover { border-color: var(--accent); }
.dpad .blank { visibility: hidden; }

/* Select Bubbles */
.bubbles {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
  max-width: 640px;
}
.bubble {
  width: 118px;
  height: 118px;
  border-radius: 50%;
  border: 2px solid rgba(61,207,142,0.45);
  background: radial-gradient(circle at 30% 30%, rgba(61,207,142,0.28), rgba(10,20,15,0.92));
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.05rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  transition: transform 0.15s ease, opacity 0.2s ease, border-color 0.15s ease, background 0.15s ease;
  animation: floatIn 0.35s ease both;
  padding: 0.4rem;
  text-align: center;
  line-height: 1.2;
}
.bubble.sm { width: 96px; height: 96px; font-size: 0.9rem; }
.bubble:hover { transform: scale(1.04); border-color: var(--accent); }
.bubble.picked {
  background: var(--accent);
  border-color: var(--accent);
  color: #062014;
}
.bubble.dead { opacity: 0.28; cursor: default; }

/* Path Finder */
.pf-grid {
  display: grid;
  gap: 5px;
}
.tile {
  width: 56px;
  height: 56px;
  background: rgba(0,0,0,0.28);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  display: block;
}
.tile.tight { width: 48px; height: 48px; }
.tile.empty {
  background: rgba(0,0,0,0.18);
  border-color: transparent;
  cursor: default;
}
.tile:hover:not(.empty) { border-color: var(--accent); }
.tile svg { display: block; }
.tile.lit {
  border-color: rgba(110, 240, 176, 0.65);
  background: rgba(61, 207, 142, 0.14);
  box-shadow: 0 0 18px rgba(61, 207, 142, 0.28);
}
.tile.flow-head {
  transform: scale(1.06);
  box-shadow: 0 0 28px rgba(110, 240, 176, 0.55);
  border-color: #6ef0b0;
}
.pf-grid-wrap {
  position: relative;
  transition: filter 0.3s ease;
}
.pf-grid-wrap.connected {
  animation: pfConnectedPulse 0.9s ease;
}
.connected-msg {
  color: var(--accent) !important;
  letter-spacing: 0.01em;
}
.level-clock.connected {
  color: var(--accent);
  border-color: rgba(61, 207, 142, 0.55);
  background: rgba(61, 207, 142, 0.12);
}
@keyframes pfConnectedPulse {
  0% { filter: brightness(1); }
  35% { filter: brightness(1.25); }
  100% { filter: brightness(1); }
}
.budget {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
}
.budget.low { color: var(--accent-2); border-color: rgba(240,193,75,0.45); }

@media (max-width: 520px) {
  .cell { width: 42px; height: 42px; font-size: 1rem; }
  .tile { width: 46px; height: 46px; }
  .bubble { width: 96px; height: 96px; font-size: 0.9rem; }
}

.toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: #12241c;
  border: 1px solid var(--line);
  padding: 0.7rem 1rem;
  border-radius: 999px;
  z-index: 60;
  animation: rise 0.25s ease;
}

.hidden { display: none !important; }
.error { color: #ffb4b4; font-size: 0.9rem; min-height: 1.2em; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes floatIn { from { opacity: 0; transform: translateY(10px) scale(0.95); } to { opacity: 1; transform: none; } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.hero-home {
  min-height: 100vh;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 2rem 1rem;
}
.hero-home .brand { font-size: clamp(2.8rem, 8vw, 5rem); }
.hero-home p { max-width: 34rem; margin: 0.8rem auto 1.6rem; color: var(--muted); font-size: 1.1rem; }
.copy-btn { font-size: 0.85rem; padding: 0.4rem 0.7rem; }
