:root {
  --bg: #0f1410;
  --bg-elevated: #1a221c;
  --panel: #243028;
  --text: #e8f0e9;
  --muted: #8fa396;
  --accent: #6fbf73;
  --accent-dim: #3d7a42;
  --trunk: #8b5a2b;
  --branch: #c4a35a;
  --leaf: #5cb85c;
  --correct: #3d8b54;
  --present: #c9a227;
  --absent: #3a4240;
  --danger: #c45c5c;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: radial-gradient(ellipse at top, #1a2a1c 0%, var(--bg) 55%);
  color: var(--text);
  line-height: 1.45;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

header.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid #2c3a30;
  padding-bottom: 0.75rem;
}

header h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}

header h1 span {
  color: var(--accent);
}

.nav a {
  margin-left: 0.75rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.nav a:hover,
.nav a.active {
  color: var(--text);
}

.hero {
  text-align: center;
  padding: 2rem 0 1rem;
}

.hero h2 {
  margin: 0 0 0.5rem;
  font-size: 2rem;
}

.hero p {
  color: var(--muted);
  margin: 0 0 1.5rem;
}

.cards {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 560px) {
  .cards {
    grid-template-columns: 1fr 1fr;
  }
}

.card {
  background: var(--bg-elevated);
  border: 1px solid #2f3f34;
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: border-color 0.15s, transform 0.15s;
}

.card:hover {
  border-color: var(--accent-dim);
  transform: translateY(-2px);
}

.card h3 {
  margin: 0 0 0.35rem;
}

.card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.card .meta {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--accent);
}

.panel {
  background: var(--bg-elevated);
  border: 1px solid #2f3f34;
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.stats strong {
  color: var(--text);
}

.msg {
  min-height: 1.4rem;
  margin: 0.5rem 0 0.75rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.msg.error {
  color: var(--danger);
}

.msg.ok {
  color: var(--accent);
}

/* Letter Budget */
.grid {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 1rem 0;
  align-items: center;
}

.row {
  display: flex;
  gap: 0.4rem;
}

.tile {
  width: 3rem;
  height: 3rem;
  border-radius: 8px;
  border: 2px solid #3a4a40;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  font-weight: 700;
  text-transform: uppercase;
  background: var(--panel);
}

.tile.correct {
  background: var(--correct);
  border-color: var(--correct);
}

.tile.present {
  background: var(--present);
  border-color: var(--present);
  color: #1a1505;
}

.tile.absent {
  background: var(--absent);
  border-color: var(--absent);
  opacity: 0.85;
}

.input-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

input[type="text"] {
  flex: 1;
  padding: 0.7rem 0.85rem;
  border-radius: 8px;
  border: 1px solid #3a4a40;
  background: var(--panel);
  color: var(--text);
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

input[type="text"]:focus {
  outline: 2px solid var(--accent-dim);
  border-color: var(--accent);
}

button,
.btn {
  appearance: none;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #0c140e;
  font-weight: 700;
  padding: 0.7rem 1rem;
  cursor: pointer;
  font-size: 0.95rem;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.secondary {
  background: var(--panel);
  color: var(--text);
  border: 1px solid #3a4a40;
}

/* Spelling Tree — click-to-spell board */
.tree-board {
  position: relative;
  margin: 1rem 0 0.5rem;
  padding: 0.75rem 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid #2f3f34;
  background: rgba(26, 34, 28, 0.72);
  user-select: none;
  -webkit-user-select: none;
}

.spell-preview {
  text-align: center;
  min-height: 1.85rem;
  margin-bottom: 0.5rem;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.spell-preview.has-word {
  color: var(--accent);
}

.tree {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  margin: 0;
  padding: 0.35rem 0.25rem 0.5rem;
  background: transparent !important;
  border: none;
  backdrop-filter: none !important;
}

.zone {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  justify-content: center;
  position: relative;
}

.zone-label {
  width: 100%;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #c5d4c8;
  margin-bottom: 0.2rem;
  pointer-events: none;
}

.letter {
  appearance: none;
  -webkit-appearance: none;
  width: 3.15rem;
  height: 3.15rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.2rem;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  border: 2px solid transparent;
  padding: 0;
  margin: 0;
  transition: transform 0.12s, filter 0.12s, box-shadow 0.12s;
}

.letter:hover {
  transform: scale(1.06);
  filter: brightness(1.08);
}

.letter:active,
.letter.just-tapped {
  transform: scale(0.94);
  box-shadow: 0 0 0 3px rgba(111, 191, 115, 0.65);
}

.letter.trunk {
  background: var(--trunk);
  color: #fff8ef;
}

.letter.branch {
  background: var(--branch);
  color: #1a1505;
}

.letter.leaf {
  background: var(--leaf);
  color: #0c140e;
}

.spell-controls {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.85rem;
  flex-wrap: wrap;
}

.spell-controls button {
  min-width: 3.25rem;
}

.spell-controls #backspace {
  font-size: 1.15rem;
  line-height: 1;
  padding-left: 0.9rem;
  padding-right: 0.9rem;
}

.spell-controls #submit {
  min-width: 5.5rem;
}

@media (min-width: 480px) {
  .letter {
    width: 3.4rem;
    height: 3.4rem;
    font-size: 1.3rem;
  }
}

.found-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.found-list span {
  background: var(--panel);
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
}

.footer-note {
  margin-top: 2rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}

/* Spelling Tree page — grove backdrop */
.page-tree {
  position: relative;
  isolation: isolate;
}

.grove-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
}

.grove-svg {
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0.95;
}

.wrap-tree {
  position: relative;
  z-index: 1;
}

.wrap-tree .panel,
.wrap-tree .input-row input {
  backdrop-filter: blur(6px);
  background: rgba(26, 34, 28, 0.88);
}

/* Do NOT frost .tree — it sits above .path-svg and was washing the trail out */
.wrap-tree .tree {
  background: transparent;
  border: none;
  backdrop-filter: none;
}

/* Growth rank rollup */
.rank-panel {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.rank-current {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.rank-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 12px;
  background: rgba(111, 191, 115, 0.12);
  border: 1px solid rgba(111, 191, 115, 0.25);
  flex-shrink: 0;
}

.rank-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.rank-name {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--accent);
  line-height: 1.2;
}

.rank-ladder {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.4rem;
}

.rank-step {
  text-align: center;
  padding: 0.45rem 0.2rem;
  border-radius: 10px;
  border: 1px solid #2f3f34;
  background: rgba(15, 20, 16, 0.45);
  opacity: 0.4;
  transition: opacity 0.2s, border-color 0.2s, background 0.2s, transform 0.15s;
}

.rank-step.unlocked {
  opacity: 0.85;
  border-color: #3d5a42;
}

.rank-step.active {
  opacity: 1;
  border-color: var(--accent);
  background: rgba(111, 191, 115, 0.12);
  transform: translateY(-2px);
  box-shadow: 0 0 0 1px rgba(111, 191, 115, 0.2);
}

.rank-step-icon {
  display: flex;
  justify-content: center;
  margin-bottom: 0.15rem;
}

.rank-step-name {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.rank-step-pct {
  display: none;
}

.rank-bar-wrap {
  height: 6px;
  border-radius: 999px;
  background: #1a221c;
  border: 1px solid #2f3f34;
  overflow: hidden;
}

.rank-bar {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #5a3a1c, #c4a35a, #5cb85c);
  transition: width 0.35s ease;
  min-width: 0;
}

@media (max-width: 520px) {
  .rank-step-name {
    font-size: 0.62rem;
  }
}

/* User identity */
header.app-header {
  flex-wrap: wrap;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--muted);
  max-width: 100%;
}

.user-chip .user-email {
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

button.linkish,
.linkish {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.8rem;
  padding: 0.2rem 0.35rem;
  cursor: pointer;
  text-decoration: none;
}

button.linkish:hover,
.linkish:hover {
  text-decoration: underline;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(8, 12, 9, 0.78);
  backdrop-filter: blur(6px);
}

.auth-gate[hidden] {
  display: none !important;
}

.auth-card {
  width: min(100%, 400px);
  background: var(--bg-elevated);
  border: 1px solid #2f3f34;
  border-radius: var(--radius);
  padding: 1.5rem 1.35rem 1.25rem;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

.auth-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.35rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 1rem;
}

.auth-form input[type="email"] {
  width: 100%;
  padding: 0.75rem 0.85rem;
  border-radius: 8px;
  border: 1px solid #3a4a40;
  background: var(--panel);
  color: var(--text);
  font-size: 1rem;
  text-transform: none;
  letter-spacing: normal;
}

.auth-form input[type="email"]:focus {
  outline: 2px solid var(--accent-dim);
  border-color: var(--accent);
}

.auth-form button {
  width: 100%;
}

/* Result modal (win / lose) */
.result-modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(8, 12, 9, 0.78);
  backdrop-filter: blur(6px);
  animation: result-fade-in 0.22s ease-out;
}

.result-modal[hidden] {
  display: none !important;
}

@keyframes result-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.result-card {
  width: min(100%, 400px);
  background: var(--bg-elevated);
  border: 1px solid #2f3f34;
  border-radius: var(--radius);
  padding: 1.65rem 1.4rem 1.35rem;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  text-align: center;
  animation: result-pop 0.28s ease-out;
}

@keyframes result-pop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.result-card.loss {
  border-color: rgba(196, 92, 92, 0.45);
}

.result-emoji {
  font-size: 2.25rem;
  line-height: 1;
  margin-bottom: 0.55rem;
}

.result-card h2 {
  margin: 0 0 0.45rem;
  font-size: 1.4rem;
}

.result-card .result-body {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0 0 1rem;
  line-height: 1.45;
}

.result-answer-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.result-answer {
  display: inline-flex;
  gap: 0.3rem;
  justify-content: center;
  margin-bottom: 0.85rem;
}

.result-answer .tile {
  width: 2.6rem;
  height: 2.6rem;
  font-size: 1.2rem;
  background: var(--correct);
  border-color: var(--correct);
}

.result-meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 1.15rem;
}

.result-card button {
  min-width: 8rem;
}
