:root {
  --accent: #e67e22;
  --accent-dark: #c96a12;
  --accent-soft: #fff4e8;
  --accent-glow: rgba(230, 126, 34, 0.35);
  --play-new: #e67e22;
  --play-new-bg: #fff0e0;
  --play-existing: #5b8def;
  --play-existing-bg: #eaf1ff;
  --text: #1a1a1a;
  --muted: #5c5c5c;
  --border: #e6e0d8;
  --bg: #faf8f5;
  --card: #ffffff;
  --danger: #c0392b;
  --danger-dark: #a93226;
  --cell-size: 40px;
  --cell-gap: 6px;
  --tap: 44px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.04);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent-dark);
}

a:hover {
  color: var(--accent);
}

/* NAV */
nav.navbar {
  width: 100%;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 1000;
}

.nav-brand {
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
  padding: 8px 4px;
  white-space: nowrap;
}

.nav-brand:hover {
  color: var(--accent-dark);
}

.nav-links {
  display: flex;
  gap: 4px;
  flex: 1;
  align-items: center;
}

nav.navbar a:not(.nav-brand) {
  text-decoration: none;
  color: var(--text);
  font-weight: 500;
  padding: 10px 14px;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}

nav.navbar a:not(.nav-brand):hover {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  margin-left: auto;
  background: none;
  border: none;
  padding: 10px;
  min-width: var(--tap);
  min-height: var(--tap);
}

.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background-color: var(--text);
  border-radius: 1px;
}

@media (max-width: 600px) {
  .nav-links {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 8px 12px 16px;
    box-shadow: var(--shadow);
  }

  .nav-links.active {
    display: flex;
  }

  .hamburger {
    display: flex;
  }
}

/* PAGE */
.page {
  max-width: 1200px;
  width: 100%;
  margin: 24px auto 40px;
  padding: 0 16px;
  flex: 1;
}

.page--solver {
  display: flex;
  gap: 28px;
  align-items: flex-start;
}

.page--content {
  display: block;
  max-width: 720px;
}

.left {
  flex: 2;
  min-width: 0;
}

.right {
  flex: 1;
  min-width: 260px;
  max-width: 380px;
}

h1 {
  margin: 0 0 8px;
  font-size: clamp(1.5rem, 4vw, 1.85rem);
  letter-spacing: -0.02em;
}

h2 {
  margin: 0 0 12px;
  font-size: 1.15rem;
}

.solver-sub,
.lede {
  color: var(--muted);
  margin: 0 0 16px;
}

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

.content-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow);
}

.content-card.legal ul {
  padding-left: 1.2em;
}

.content-card.legal li {
  margin-bottom: 0.5em;
}

.hero .btn {
  margin: 8px 0 4px;
}

.toggle-container {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  margin: 12px 0 8px;
}

.toggle-container label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 4px 8px;
  cursor: pointer;
  font-weight: 500;
}

.ad-block {
  width: 100%;
  height: 90px;
  background: #f0ece6;
  text-align: center;
  line-height: 90px;
  margin: 20px 0;
  color: var(--muted);
  font-weight: 600;
  border-radius: 8px;
}

/* BOARD */
#boardWrapper,
#rackWrapper {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.rack-label {
  margin: 8px 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  align-self: flex-start;
  width: 100%;
  max-width: calc(var(--board-size, 8) * (var(--cell-size) + var(--cell-gap)));
  text-align: center;
}

#board,
#rack {
  display: grid;
  gap: var(--cell-gap);
  margin: 12px 0;
  grid-template-columns: repeat(var(--board-cols, 8), var(--cell-size));
}

#rack {
  --board-cols: 7;
}

.cell-container {
  position: relative;
  width: var(--cell-size);
  height: var(--cell-size);
}

.cell,
.rack-cell {
  width: 100%;
  height: 100%;
  font-size: calc(var(--cell-size) * 0.45);
  font-weight: 600;
  text-align: center;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  outline: none;
  caret-color: transparent;
  background: var(--card);
  color: var(--text);
  text-transform: uppercase;
  padding: 0;
  transition: border-color 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.rack-cell {
  width: var(--cell-size);
  height: var(--cell-size);
}

.cell.active,
.rack-cell.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.cell.play-highlight,
.cell-container.play-highlight .cell {
  border-color: var(--accent);
  background: rgba(230, 126, 34, 0.16);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.cell-container.play-highlight {
  z-index: 1;
}

.number-box {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 36%;
  height: 36%;
  font-size: 0.55em;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-weight: 600;
}

.button-row {
  display: flex;
  justify-content: stretch;
  gap: 12px;
  margin: 8px 0 12px;
  max-width: 100%;
}

.btn,
#solveBtn,
#clearBtn {
  flex: 1;
  min-height: var(--tap);
  padding: 12px 20px;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.btn-primary,
#solveBtn {
  background: var(--accent);
}

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

.btn-danger,
#clearBtn {
  background: var(--danger);
}

.btn-danger:hover,
#clearBtn:hover:not(:disabled) {
  background: var(--danger-dark);
}

#solveBtn:disabled,
#clearBtn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.solve-status {
  min-height: 1.4em;
  margin: 0 0 8px;
  font-size: 0.95rem;
  color: var(--muted);
}

.solve-status.is-error {
  color: var(--danger);
}

.solve-status.is-loading {
  color: var(--accent-dark);
}

/* RESULTS */
.results-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 96px);
  display: flex;
  flex-direction: column;
}

.results-heading {
  margin-bottom: 4px;
}

.results-meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
  min-height: 1.2em;
}

.results-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.results-empty {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.results-empty[hidden],
.results-meta:empty {
  display: none;
}

.result-item {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  padding: 10px 12px;
  min-height: var(--tap);
  cursor: pointer;
  font: inherit;
  color: inherit;
  gap: 2px;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.result-item:hover {
  background: var(--accent-soft);
}

.result-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.result-item.is-selected {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.result-item + .result-item {
  border-top: 1px solid var(--border);
  border-radius: 0;
}

.result-item.is-selected + .result-item,
.result-item + .result-item.is-selected {
  border-top-color: transparent;
}

.result-item.is-selected {
  border-radius: 8px;
}

.result-main {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.result-score {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent-dark);
  min-width: 2.2em;
}

.result-word {
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.result-adds {
  font-size: 0.82rem;
  color: var(--muted);
  padding-left: calc(2.2em + 12px);
}

.result-adds strong {
  color: var(--text);
  font-weight: 600;
}

/* FOOTER */
.site-footer {
  margin-top: auto;
  padding: 28px 20px 36px;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
  border-top: 1px solid var(--border);
  background: var(--card);
  width: 100%;
}

.footer-disclaimer {
  max-width: 640px;
  margin: 0 auto 14px;
  line-height: 1.45;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  margin-bottom: 12px;
}

.footer-links a {
  color: var(--muted);
  text-decoration: none;
  padding: 8px 4px;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
}

.footer-links a:hover {
  color: var(--accent-dark);
  text-decoration: underline;
}

.footer-copy {
  margin: 0;
  font-size: 0.85rem;
}

/* RESPONSIVE — prefer smaller cells over transform:scale */
@media (max-width: 900px) {
  .page--solver {
    flex-direction: column;
    gap: 20px;
  }

  .right {
    max-width: none;
    width: 100%;
    position: static;
    max-height: none;
  }

  .results-panel {
    position: static;
    max-height: none;
  }

  .results-list {
    max-height: 420px;
  }
}

@media (max-width: 600px) {
  :root {
    --cell-size: 34px;
    --cell-gap: 4px;
  }

  .page {
    margin-top: 16px;
  }

  .content-card {
    padding: 20px 16px;
  }
}

@media (max-width: 400px) {
  :root {
    --cell-size: 30px;
    --cell-gap: 3px;
  }
}

/* Slightly tighter cells when 10×10 is active */
#board.board-10 {
  --cell-size: clamp(26px, 7.2vw, 36px);
  --cell-gap: clamp(2px, 0.8vw, 5px);
}

@media (max-width: 600px) {
  #board.board-10 {
    --cell-size: clamp(24px, 7.5vw, 30px);
  }
}


/* Cookie / analytics consent */
.consent-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2000;
  padding: 12px;
  pointer-events: none;
}
.consent-banner__inner {
  pointer-events: auto;
  max-width: 920px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: center;
  justify-content: space-between;
  background: #1f2933;
  color: #f7f7f7;
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.28);
}
.consent-banner__title {
  margin: 0 0 4px;
  font-weight: 700;
  font-size: 0.95rem;
}
.consent-banner__text {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.4;
  color: #e5e7eb;
}
.consent-banner__text a {
  color: #ffd7a8;
}
.consent-banner__actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.btn-ghost {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.35);
}
.btn-ghost:hover {
  background: rgba(255,255,255,0.08);
}
@media (max-width: 550px) {
  .consent-banner__inner {
    flex-direction: column;
    align-items: stretch;
  }
  .consent-banner__actions .btn {
    flex: 1;
  }
}

.solver-note {
  margin: 0 0 12px;
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.4;
}
