/* Daily Letter Grid — cream + teal theme */
:root {
  --bg: #FAF7F2;
  --surface: #FFFFFF;
  --surface-2: #F5F0E8;
  --text: #1C1917;
  --muted: #78716C;
  --border: #E7E0D5;
  --accent: #0D9488;
  --accent-dark: #0F766E;
  --accent-soft: rgba(13, 148, 136, 0.12);
  --amber: #F59E0B;
  --amber-soft: rgba(245, 158, 11, 0.15);
  --correct: #059669;
  --correct-soft: rgba(5, 150, 105, 0.15);
  --wrong: #DC2626;
  --wrong-soft: rgba(220, 38, 38, 0.12);
  --block: #292524;
  --cell-size: clamp(2rem, 8vw, 2.75rem);
  --header-h: 3.25rem;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(28, 25, 23, 0.08);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

[data-theme="dark"] {
  --bg: #1C1917;
  --surface: #292524;
  --surface-2: #44403C;
  --text: #FAFAF9;
  --muted: #A8A29E;
  --border: #57534E;
  --accent-soft: rgba(45, 212, 191, 0.15);
  --block: #0C0A09;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 9999;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: #fff;
}
.skip-link:focus { left: 0; }

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(250, 247, 242, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
[data-theme="dark"] .app-header { background: rgba(28, 25, 23, 0.92); }

.header-inner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 960px;
  margin: 0 auto;
  padding: 0.5rem 0.75rem;
  min-height: var(--header-h);
}

.brand {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.brand-mark {
  width: 2rem;
  height: 2rem;
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
}
.brand-mark span {
  background: var(--accent);
  border-radius: 3px;
}
.brand-mark span:nth-child(2) { background: var(--amber); }
.brand-mark span:nth-child(3) { background: var(--amber); opacity: 0.7; }
.brand-mark span:nth-child(4) { background: var(--accent-dark); }

.brand-name {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-name em {
  font-style: normal;
  color: var(--accent);
}

.mode-badge {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  white-space: nowrap;
}
[data-theme="dark"] .mode-badge { color: #5EEAD4; }

.header-actions { display: flex; gap: 0.25rem; }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg {
  width: 1.35rem;
  height: 1.35rem;
  fill: currentColor;
}

/* Stats bar */
.stats-bar {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.65rem 0.75rem 0;
  width: 100%;
}

.stats-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.stat-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.35rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 4.5rem;
  box-shadow: var(--shadow);
}
.stat-pill .val {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.2;
}
.stat-pill .lbl {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.month-nav button {
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  font-size: 1rem;
  color: var(--text);
}
.month-nav button:hover { border-color: var(--accent); }
.month-label {
  font-weight: 700;
  font-size: 0.9rem;
  min-width: 7rem;
  text-align: center;
}

/* Calendar strip */
.calendar-wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.5rem 0.75rem;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.calendar-strip {
  display: flex;
  gap: 0.35rem;
  min-width: min-content;
  padding-bottom: 0.25rem;
}

.cal-day {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 2.75rem;
  padding: 0.35rem 0.25rem;
  border: 2px solid transparent;
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.cal-day:hover { border-color: var(--border); transform: translateY(-1px); }
.cal-day .dow {
  font-size: 0.6rem;
  color: var(--muted);
  text-transform: uppercase;
}
.cal-day .num {
  font-size: 0.95rem;
  font-weight: 700;
}
.cal-day.is-today { border-color: var(--amber); background: var(--amber-soft); }
.cal-day.is-selected { border-color: var(--accent); background: var(--accent-soft); }
.cal-day.is-solved { background: var(--correct-soft); }
.cal-day.is-solved .num { color: var(--correct); }
.cal-day.is-future { opacity: 0.4; pointer-events: none; }

/* Main layout */
.main {
  flex: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 0.5rem 0.75rem 1.5rem;
  width: 100%;
  display: grid;
  gap: 1rem;
}

@media (min-width: 768px) {
  .main {
    grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
    align-items: start;
  }
}

.puzzle-title {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--muted);
  grid-column: 1 / -1;
}

/* Grid */
.grid-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.crossword-grid {
  display: grid;
  gap: 2px;
  user-select: none;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  position: relative;
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1rem, 4vw, 1.35rem);
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0;
}
.cell.is-block {
  background: var(--block);
  border-color: var(--block);
  cursor: default;
}
.cell.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  z-index: 2;
}
.cell.is-highlight {
  background: var(--amber-soft);
}
.cell.is-correct { background: var(--correct-soft); color: var(--correct); }
.cell.is-wrong { background: var(--wrong-soft); color: var(--wrong); }
.cell.is-revealed { color: var(--muted); }

.cell-num {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: 0.5rem;
  font-weight: 600;
  line-height: 1;
  color: var(--muted);
  pointer-events: none;
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: center;
  width: 100%;
}

.btn {
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-amber {
  background: var(--amber);
  border-color: var(--amber);
  color: #fff;
}

/* Clues */
.clues-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: min(60vh, 520px);
}

.clue-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.clue-tab {
  flex: 1;
  padding: 0.65rem;
  border: none;
  background: transparent;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--muted);
}
.clue-tab.is-active {
  color: var(--accent);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.clue-list {
  overflow-y: auto;
  padding: 0.5rem;
  flex: 1;
}

.clue-item {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.875rem;
  line-height: 1.35;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  color: var(--text);
}
.clue-item:hover { background: var(--surface-2); }
.clue-item.is-active {
  background: var(--accent-soft);
  font-weight: 600;
}
.clue-item.is-done { color: var(--correct); }
.clue-item.is-done .clue-num { color: var(--correct); }
.clue-num {
  font-weight: 800;
  color: var(--accent);
  min-width: 1.25rem;
}

/* Menu drawer */
.menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.menu-backdrop.is-open { opacity: 1; pointer-events: auto; }

.menu-panel {
  position: fixed;
  top: 0;
  left: 0;
  width: min(320px, 88vw);
  height: 100%;
  background: var(--surface);
  z-index: 201;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
.menu-panel.is-open { transform: translateX(0); }

.menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}

.menu-body {
  overflow-y: auto;
  padding: 0.75rem;
  flex: 1;
}

.menu-body h3 {
  margin: 1rem 0 0.5rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.menu-body h3:first-child { margin-top: 0; }

.menu-list { list-style: none; margin: 0; padding: 0; }
.menu-list button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.65rem 0.5rem;
  border: none;
  background: transparent;
  text-align: left;
  font-size: 0.9rem;
  cursor: pointer;
  border-radius: 8px;
  color: var(--text);
}
.menu-list button:hover { background: var(--surface-2); }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow);
  text-align: center;
}
.modal h2 { margin: 0 0 0.5rem; font-size: 1.25rem; }
.modal p { margin: 0 0 1rem; color: var(--muted); font-size: 0.9rem; }
.modal .points {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
  margin: 0.5rem 0;
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--text);
  color: var(--bg);
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 400;
  transition: transform 0.25s;
  pointer-events: none;
}
.toast.is-show { transform: translateX(-50%) translateY(0); }

.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

.is-embedded .app-header { display: none; }
.is-embedded .stats-bar { padding-top: 0.75rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
