:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-soft: #ebe6db;
  --ink: #1e2d24;
  --ink-muted: #536358;
  --border: #d7d1c3;
  --accent: #22372b;
  --accent-hover: #355442;
  --marker-red: #c93b2b;
  --marker-amber: #d97706;
  --marker-amber-bg: #fef3c7;
  --easy-bg: #dff0d8;
  --easy-ink: #1f5130;
  --medium-bg: #e2ecf7;
  --medium-ink: #1c446b;
  --hard-bg: #fce8d5;
  --hard-ink: #8a3d0b;
  --expert-bg: #f7dce0;
  --expert-ink: #7f1d2d;
  --radius: 16px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Header */
.site-header {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 20px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.back-link {
  color: var(--ink-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}

.back-link:hover {
  color: var(--ink);
}

.wordmark {
  color: var(--ink);
  text-decoration: none;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.solved-badge {
  font-size: 13px;
  font-weight: 700;
  background: var(--surface-soft);
  color: var(--ink);
  padding: 4px 10px;
  border-radius: 999px;
}

/* Main container */
.app {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px 32px;
  flex: 1;
}

.hero {
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
}

.hero h1 {
  margin: 0 0 8px;
  font-size: clamp(28px, 6.5vw, 44px);
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.lead {
  margin: 0;
  font-size: 15px;
  color: var(--ink-muted);
  max-width: 52ch;
}

/* Difficulty pills */
.difficulty-bar {
  margin-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.difficulty-bar::-webkit-scrollbar {
  display: none;
}

.pill-group {
  display: flex;
  gap: 8px;
  padding: 2px 0;
}

.diff-pill {
  flex: 0 0 auto;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
  touch-action: manipulation;
}

.diff-pill small {
  font-size: 11px;
  font-weight: 600;
  opacity: 0.7;
}

.diff-pill[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.diff-pill[aria-selected="true"] small {
  opacity: 0.85;
}

/* Whiteboard centerpiece card */
.whiteboard-card {
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 18px 16px 16px;
  box-shadow: 0 6px 0 rgba(30, 45, 36, 0.12);
  margin-bottom: 16px;
}

.board-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.meta-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.tag {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--ink);
}

.tag-id {
  font-variant-numeric: tabular-nums;
}

.tag-diff[data-diff="easy"] { background: var(--easy-bg); color: var(--easy-ink); }
.tag-diff[data-diff="medium"] { background: var(--medium-bg); color: var(--medium-ink); }
.tag-diff[data-diff="hard"] { background: var(--hard-bg); color: var(--hard-ink); }
.tag-diff[data-diff="expert"] { background: var(--expert-bg); color: var(--expert-ink); }

.icon-btn {
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}

.icon-btn:hover {
  background: var(--surface-soft);
}

.theme-label {
  margin: 0 0 14px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-muted);
}

/* Word pair display */
.pair-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 8px 18px;
  flex-wrap: wrap;
}

.word-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.word-caption {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--ink-muted);
}

.pair-arrow {
  font-size: 24px;
  font-weight: 800;
  color: var(--ink-muted);
  margin-top: 14px;
}

.word-tiles {
  display: flex;
  gap: 5px;
}

.tile {
  width: 44px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: #faf8f3;
  border: 2px solid var(--border);
  border-radius: 10px;
  position: relative;
  user-select: none;
}

.tile.is-match::after {
  content: "";
  position: absolute;
  left: 7px;
  right: 7px;
  bottom: 5px;
  height: 4px;
  border-top: 2px solid var(--marker-red);
  border-bottom: 1.5px solid var(--marker-red);
  border-radius: 2px;
}

.tile.is-changed {
  background: var(--marker-amber-bg);
  border-color: var(--marker-amber);
  color: #78350f;
}

/* 5-letter tiles scale down smoothly on narrow 320-390px screens */
.word-tiles[data-len="5"] .tile {
  width: 38px;
  height: 46px;
  font-size: 22px;
}

/* Board Controls */
.board-controls {
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  gap: 10px;
  margin-top: 6px;
}

.btn {
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
  padding: 13px 16px;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.06s ease;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-soft);
  color: var(--ink);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: #e1dacb;
}

.btn-ghost {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-soft);
}

.btn-compact {
  padding: 12px 18px;
}

.btn-small {
  font-size: 14px;
  padding: 8px 14px;
}

.board-subcontrols {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--surface-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-muted);
}

.btn-link {
  border: none;
  background: none;
  padding: 2px 4px;
  font: inherit;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-link[aria-pressed="true"] {
  color: var(--easy-ink);
}

.red-underline-sample {
  font-weight: 800;
  color: var(--ink);
  border-bottom: 3px double var(--marker-red);
  padding: 0 2px;
}

/* Panels */
.panel {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.panel-sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--ink-muted);
}

.counter-pill {
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-soft);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

/* On-screen scratchpad */
.ladder-trail {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.rung {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: #faf8f3;
  border: 1px solid var(--surface-soft);
}

.rung.is-current {
  border-color: var(--ink);
  background: #ffffff;
}

.rung.is-win {
  border-color: var(--easy-ink);
  background: var(--easy-bg);
}

.rung-step {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-muted);
  min-width: 50px;
}

.rung-tiles {
  display: flex;
  gap: 4px;
}

.rung-tile {
  width: 34px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 800;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 7px;
  position: relative;
  cursor: default;
}

.rung.is-current .rung-tile {
  cursor: pointer;
}

.rung.is-current .rung-tile:hover {
  border-color: var(--accent);
}

.rung-tile.is-match::after {
  content: "";
  position: absolute;
  left: 5px;
  right: 5px;
  bottom: 3px;
  height: 3px;
  border-top: 2px solid var(--marker-red);
  border-bottom: 1px solid var(--marker-red);
}

.rung-tile.is-changed {
  background: var(--marker-amber-bg);
  border-color: var(--marker-amber);
  color: #78350f;
}

.rung-note {
  font-size: 12px;
  color: var(--ink-muted);
  text-align: right;
  min-width: 60px;
}

.move-form {
  display: flex;
  gap: 8px;
}

.move-input {
  flex: 1;
  min-width: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 11px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: #faf8f3;
  color: var(--ink);
}

.move-input:focus {
  outline: none;
  border-color: var(--accent);
  background: #ffffff;
}

.move-feedback {
  margin: 8px 0 0;
  min-height: 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--marker-red);
}

.move-feedback.is-success {
  color: var(--easy-ink);
}

.scratchpad-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* Walkthrough */
.walkthrough-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.walkthrough-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.wt-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: #faf8f3;
  border: 1px solid var(--surface-soft);
}

.wt-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.wt-step-num {
  font-size: 12px;
  font-weight: 800;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.wt-text {
  margin: 0;
  font-size: 14px;
  color: var(--ink);
}

/* Browse 200 */
.browse-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
  list-style: none;
}

.browse-summary::-webkit-details-marker {
  display: none;
}

.browse-body {
  margin-top: 12px;
}

.search-input {
  width: 100%;
  font-size: 15px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: #faf8f3;
  color: var(--ink);
  margin-bottom: 10px;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  background: #ffffff;
}

.browse-list {
  max-height: 360px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 2px;
}

.browse-row {
  width: 100%;
  text-align: left;
  border: 1px solid var(--surface-soft);
  background: #faf8f3;
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
}

.browse-row:hover {
  background: var(--surface-soft);
}

.browse-row.is-active {
  border-color: var(--accent);
  background: #e6efe2;
}

.browse-pair {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.03em;
}

.browse-meta {
  font-size: 12px;
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Rules box */
.rules-box {
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface-soft);
  font-size: 14px;
}

.rules-box summary {
  font-weight: 700;
  cursor: pointer;
}

.rules-box p {
  margin: 10px 0 0;
  color: var(--ink-muted);
}

/* Footer */
.site-footer {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 20px 28px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--ink-muted);
}

@media (max-width: 420px) {
  .pair-stage {
    gap: 6px;
  }
  .tile {
    width: 38px;
    height: 46px;
    font-size: 22px;
  }
  .word-tiles[data-len="5"] .tile {
    width: 32px;
    height: 40px;
    font-size: 18px;
  }
  .pair-arrow {
    font-size: 18px;
  }
  .site-footer {
    flex-direction: column;
    gap: 4px;
  }
}
