:root {
  --bg: #f3efe6;
  --bg-deep: #e6dcc8;
  --bg-grid: rgba(28, 20, 14, 0.05);
  --surface: rgba(255, 252, 246, 0.82);
  --surface-strong: rgba(255, 252, 246, 0.96);
  --surface-accent: rgba(255, 245, 233, 0.95);
  --ink: #191613;
  --muted: #74695d;
  --line: rgba(25, 22, 19, 0.1);
  --accent: #b4543b;
  --accent-deep: #883925;
  --teal: #20594b;
  --gold: #d7a744;
  --shadow: 0 22px 70px rgba(40, 31, 23, 0.09);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --font-display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  --font-body: "Avenir Next", "Segoe UI", sans-serif;
  --font-mono: "SFMono-Regular", "Consolas", monospace;
}

* {
  box-sizing: border-box;
}

html {
  background:
    radial-gradient(circle at top left, rgba(180, 84, 59, 0.16), transparent 34%),
    radial-gradient(circle at bottom right, rgba(32, 89, 75, 0.16), transparent 28%),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.16), transparent 30%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

body.app-loading .play-stack,
body.app-loading .goal-card,
body.app-loading .board-meta,
body.app-loading .panel-topline {
  opacity: 0.72;
}

button,
input {
  font: inherit;
}

.page-shell {
  width: min(1160px, calc(100vw - 2rem));
  margin: 0 auto;
  padding: 1.1rem 0 2.5rem;
  position: relative;
}

.hero,
.layout {
  display: grid;
  gap: 1rem;
}

.hero {
  grid-template-columns: 1fr auto;
  align-items: end;
  margin-bottom: 1rem;
}

.hero-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.eyebrow,
.panel-label,
.meta-label,
.goal-label,
.helper-copy,
.archive-copy,
.archive-meta,
.share-metric-label {
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  margin: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
.meta-value,
.goal-word strong,
.status-title,
.share-logo,
.logo-ladder,
.logo-verse {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.03em;
  margin: 0;
}

h2 {
  font-size: clamp(1.8rem, 4vw, 2.5rem);
}

h3 {
  font-size: 1.7rem;
}

.brand-block {
  display: grid;
  gap: 0.45rem;
}

.brand-copy {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.5;
  margin: 0;
  max-width: 36rem;
}

.logo-mark {
  align-items: center;
  display: grid;
  gap: 0.9rem;
  grid-template-columns: auto 1fr;
}

.logo-rungs {
  background:
    linear-gradient(var(--accent-deep), var(--accent-deep)) left center / 4px 100% no-repeat,
    linear-gradient(var(--teal), var(--teal)) right center / 4px 100% no-repeat;
  border-radius: 999px;
  display: grid;
  gap: 0.42rem;
  padding: 0.5rem 0.5rem;
  width: 28px;
}

.logo-rungs span {
  background: linear-gradient(90deg, var(--gold), rgba(255, 252, 246, 0.95));
  border-radius: 999px;
  display: block;
  height: 6px;
  transform: rotate(-4deg);
}

.logo-text {
  display: grid;
  gap: 0.1rem;
}

.logo-ladder,
.logo-verse {
  display: flex;
  flex-wrap: wrap;
  gap: 0.02em;
  line-height: 0.9;
}

.logo-ladder {
  font-size: clamp(2.2rem, 5vw, 4rem);
}

.logo-verse {
  color: var(--teal);
  font-size: clamp(1.4rem, 3vw, 2.45rem);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.logo-ladder span:nth-child(odd),
.logo-verse span:nth-child(even) {
  transform: translateY(-0.08em) rotate(-2deg);
}

.logo-ladder span:nth-child(even),
.logo-verse span:nth-child(odd) {
  transform: translateY(0.08em) rotate(2deg);
}

.layout {
  grid-template-columns: minmax(0, 760px);
  justify-content: center;
}

.game-panel,
.archive-panel {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.2), transparent 38%),
    var(--surface);
  backdrop-filter: blur(20px);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.game-panel {
  overflow: hidden;
  padding: 1.25rem;
  position: relative;
}

.game-panel::before {
  background:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 26px 26px;
  content: "";
  inset: 0;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.24), transparent 65%);
  pointer-events: none;
  position: absolute;
}

.archive-panel {
  padding: 1.25rem;
  position: fixed;
  right: max(1rem, calc((100vw - 1160px) / 2));
  top: 1rem;
  width: min(360px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  z-index: 25;
}

.archive-backdrop {
  background: rgba(25, 22, 19, 0.24);
  backdrop-filter: blur(6px);
  inset: 0;
  position: fixed;
  z-index: 20;
}

.panel-topline,
.goal-card,
.board-meta,
.entry-row,
.actions,
.archive-head,
.hint-head,
.victory-head,
.share-actions,
.share-surface-head {
  display: flex;
  gap: 0.9rem;
}

.panel-topline,
.board-meta,
.archive-head,
.hint-head,
.victory-head,
.share-surface-head {
  justify-content: space-between;
  align-items: center;
}

.pill-group,
.actions,
.share-actions {
  flex-wrap: wrap;
}

.pill {
  align-items: center;
  background: rgba(25, 22, 19, 0.05);
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.92rem;
  gap: 0.4rem;
  padding: 0.55rem 0.85rem;
}

.goal-card,
.status-card,
.hint-card,
.victory-card,
.optimal-card,
.path-card,
.share-surface {
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  position: relative;
  z-index: 1;
}

.goal-card {
  align-items: center;
  justify-content: space-between;
  margin-top: 1.2rem;
  padding: 1.1rem 1rem;
}

.goal-word {
  display: grid;
  gap: 0.35rem;
}

.goal-word strong {
  font-size: clamp(1.6rem, 6vw, 2.8rem);
  text-transform: lowercase;
}

.goal-divider {
  background: linear-gradient(90deg, transparent, var(--line), transparent);
  flex: 1;
  height: 1px;
}

.board-meta {
  margin: 1rem 0 0.8rem;
  position: relative;
  z-index: 1;
}

.meta-value {
  font-size: 1.25rem;
}

#puzzle-title {
  font-size: 1.25rem;
}

.play-stack {
  display: grid;
  gap: 1rem;
  max-height: 1400px;
  opacity: 1;
  overflow: hidden;
  transform-origin: top center;
  transition:
    max-height 460ms ease,
    opacity 320ms ease,
    transform 420ms ease,
    margin 420ms ease;
}

body.victory-mode .play-stack {
  margin-top: -0.25rem;
  max-height: 0;
  opacity: 0;
  transform: scaleY(0.92);
}

.ladder-list {
  display: grid;
  gap: 0.75rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.ladder-item {
  align-items: center;
  background: rgba(255, 252, 246, 0.9);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 44px 1fr auto;
  min-height: 60px;
  padding: 0.9rem 1rem;
}

.ladder-index {
  color: var(--muted);
  font-size: 0.9rem;
}

.ladder-word {
  font-family: var(--font-display);
  font-size: clamp(1.1rem, 5vw, 1.5rem);
  letter-spacing: 0.14em;
  text-transform: lowercase;
}

.ladder-tag {
  background: rgba(25, 22, 19, 0.06);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  padding: 0.35rem 0.55rem;
  text-transform: uppercase;
}

.ladder-item.finish {
  border-color: rgba(32, 89, 75, 0.18);
}

.entry-form,
.status-card,
.hint-card,
.victory-card,
.optimal-card {
  position: relative;
  z-index: 1;
}

.entry-label {
  display: block;
  margin-bottom: 0.55rem;
}

.entry-row input {
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  flex: 1;
  min-width: 0;
  padding: 0.95rem 1rem;
  text-transform: lowercase;
}

.entry-row input:focus {
  border-color: rgba(180, 84, 59, 0.45);
  box-shadow: 0 0 0 4px rgba(180, 84, 59, 0.08);
  outline: none;
}

.helper-copy {
  margin-top: 0.6rem;
}

.hint-card,
.status-card,
.victory-card,
.optimal-card,
.path-card,
.share-surface {
  padding: 1rem;
}

.hint-copy,
.status-copy,
.result-copy,
.archive-copy {
  color: var(--muted);
  line-height: 1.55;
  margin: 0.35rem 0 0;
}

.hint-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.9rem;
}

.hint-chip {
  background: rgba(180, 84, 59, 0.1);
  border: 1px solid rgba(180, 84, 59, 0.12);
  border-radius: 999px;
  color: var(--ink);
  display: inline-flex;
  font-family: var(--font-display);
  font-size: 1rem;
  letter-spacing: 0.08em;
  padding: 0.55rem 0.8rem;
  text-transform: lowercase;
}

.primary-button,
.ghost-button,
.archive-item {
  appearance: none;
  border: 0;
  cursor: pointer;
  transition:
    transform 160ms ease,
    background-color 160ms ease,
    opacity 160ms ease,
    box-shadow 160ms ease;
}

.primary-button {
  background: var(--ink);
  border-radius: 999px;
  color: #fffaf2;
  padding: 0.95rem 1.15rem;
}

.ghost-button {
  background: rgba(25, 22, 19, 0.05);
  border-radius: 999px;
  color: var(--ink);
  padding: 0.85rem 1rem;
}

.primary-button:hover,
.ghost-button:hover,
.archive-item:hover {
  transform: translateY(-1px);
}

.primary-button:disabled,
.ghost-button:disabled {
  cursor: default;
  opacity: 0.5;
  transform: none;
}

.victory-card {
  background:
    radial-gradient(circle at top right, rgba(215, 167, 68, 0.16), transparent 34%),
    radial-gradient(circle at bottom left, rgba(32, 89, 75, 0.14), transparent 28%),
    var(--surface-accent);
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
  overflow: hidden;
}

.victory-card:not(.hidden) {
  animation: victory-rise 560ms cubic-bezier(0.18, 0.86, 0.22, 1) both;
}

.victory-seal {
  background: radial-gradient(circle at top, rgba(255, 255, 255, 0.45), transparent 60%),
    var(--teal);
  border-radius: 999px;
  color: white;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  padding: 0.75rem 0.95rem;
  text-transform: uppercase;
}

.victory-stats {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
}

.stat-tile {
  background: rgba(255, 252, 246, 0.72);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0.8rem 0.9rem;
}

.stat-tile strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.45rem;
  margin-top: 0.35rem;
}

.path-summary,
.optimal-route {
  font-family: var(--font-display);
  font-size: 1.08rem;
  line-height: 1.65;
  margin: 0.4rem 0 0;
  word-break: break-word;
}

.share-surface {
  display: grid;
  gap: 1rem;
}

.share-card-preview {
  background:
    radial-gradient(circle at top left, rgba(180, 84, 59, 0.18), transparent 34%),
    radial-gradient(circle at bottom right, rgba(32, 89, 75, 0.2), transparent 34%),
    linear-gradient(135deg, #fff8ef, #f3ecdf);
  border: 1px solid rgba(25, 22, 19, 0.08);
  border-radius: 24px;
  display: grid;
  gap: 1rem;
  overflow: hidden;
  padding: 1.3rem;
  position: relative;
}

.share-card-preview::before {
  background:
    linear-gradient(rgba(25, 22, 19, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(25, 22, 19, 0.05) 1px, transparent 1px);
  background-size: 24px 24px;
  content: "";
  inset: 0;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.24), transparent 75%);
  position: absolute;
}

.share-card-preview > * {
  position: relative;
  z-index: 1;
}

.share-logo {
  font-size: clamp(1.9rem, 6vw, 2.7rem);
  line-height: 0.94;
}

.share-date,
.share-tagline {
  color: var(--muted);
  line-height: 1.45;
  margin: 0;
}

.share-date {
  font-size: 0.92rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.share-words {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 5vw, 2.4rem);
  text-transform: lowercase;
}

.share-arrow {
  color: var(--accent-deep);
}

.share-metrics {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.share-metric {
  background: rgba(255, 252, 246, 0.68);
  border: 1px solid rgba(25, 22, 19, 0.08);
  border-radius: var(--radius-md);
  padding: 0.85rem;
}

.share-metric strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.7rem;
  margin-top: 0.3rem;
}

.archive-list {
  display: grid;
  gap: 0.7rem;
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
}

.archive-item {
  align-items: center;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--ink);
  display: grid;
  gap: 0.15rem;
  padding: 0.9rem 1rem;
  text-align: left;
  width: 100%;
}

.archive-item[aria-current="true"] {
  border-color: rgba(180, 84, 59, 0.28);
  box-shadow: 0 0 0 3px rgba(180, 84, 59, 0.08);
}

.archive-date {
  font-weight: 600;
}

.archive-words {
  color: var(--muted);
  font-size: 0.95rem;
  text-transform: lowercase;
}

.hidden {
  display: none;
}

@keyframes victory-rise {
  0% {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }

  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .archive-panel {
    max-height: none;
    position: fixed;
    right: 0.5rem;
    top: 0.5rem;
    width: calc(100vw - 1rem);
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100vw - 1rem, 100%);
    padding-top: 0.5rem;
  }

  .hero {
    align-items: start;
    grid-template-columns: 1fr;
  }

  .panel-topline,
  .goal-card,
  .board-meta,
  .hint-head,
  .victory-head,
  .archive-head,
  .entry-row,
  .share-actions,
  .share-surface-head {
    align-items: stretch;
    flex-direction: column;
  }

  .goal-divider {
    height: 1px;
    width: 100%;
  }

  .ladder-item {
    grid-template-columns: 36px 1fr;
  }

  .ladder-tag {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .share-metrics,
  .victory-stats {
    grid-template-columns: 1fr;
  }
}
