/* The Tucson Mini — adapted from Crosswording the Situation, repalette to TDB desert tones. */

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

:root {
  --cell-size: min(60px, (100vw - 40px) / 5);

  /* TDB desert palette */
  --sand: #f5f0e6;
  --tan: #e8dfd1;
  --terracotta: #c75b39;
  --terracotta-dark: #a84a2e;
  --sage: #7a8b6f;
  --brown: #3d3029;
  --brown-light: #5c4a3f;
  --rule: #d4c9b8;

  /* Crossword-specific (mapped onto desert palette) */
  --bg: var(--sand);
  --text: var(--brown);
  --grid-border: var(--brown);
  --cell-border: var(--rule);
  --cell-selected: #f3d2b5;       /* warm terracotta tint */
  --cell-highlight: #faedd9;      /* sand-cream */
  --cell-correct: var(--sage);
  --cell-present: #c9b458;
  --cell-absent: #787c7e;
  --clue-bar-bg: var(--tan);
  --accent: var(--terracotta);
  --accent-dark: var(--terracotta-dark);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

#app {
  width: 100%;
  max-width: 500px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

header {
  text-align: center;
  margin-bottom: 8px;
}

header h1 {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--brown);
}

header .tagline {
  color: var(--brown-light);
  font-size: 0.85rem;
  margin-top: 2px;
  font-style: italic;
}

.date {
  font-size: 0.85rem;
  color: var(--sage);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Timer */
#timer {
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  color: var(--brown-light);
  margin-bottom: 10px;
  margin-top: 8px;
}

/* Grid */
#grid-container {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
  position: relative;
}

#hidden-input {
  position: absolute;
  width: var(--cell-size);
  height: var(--cell-size);
  font-size: 16px;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  border: none;
  outline: none;
  z-index: 2;
  -webkit-appearance: none;
  appearance: none;
  padding: 0;
  margin: 0;
}

#grid {
  display: grid;
  grid-template-columns: repeat(5, var(--cell-size));
  grid-template-rows: repeat(5, var(--cell-size));
  border: 2px solid var(--grid-border);
  gap: 0;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border: 1px solid var(--cell-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell-size) * 0.5);
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  background: #fff;
  transition: background-color 0.1s;
}

.cell.black {
  background: var(--grid-border);
  cursor: default;
}

.cell.selected {
  background: var(--cell-selected);
}

.cell.highlighted {
  background: var(--cell-highlight);
}

.cell.selected.highlighted {
  background: var(--cell-selected);
}

.cell-number {
  position: absolute;
  top: 1px;
  left: 3px;
  font-size: calc(var(--cell-size) * 0.22);
  font-weight: 600;
  line-height: 1;
  color: var(--brown);
}

.cell-letter {
  margin-top: 4px;
  color: var(--brown);
}

/* Toolbar */
#toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

#toolbar button {
  background: #fff;
  border: 1.5px solid var(--rule);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--brown-light);
  cursor: pointer;
  transition: all 0.15s;
}

#toolbar button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

#toolbar button:active {
  transform: scale(0.96);
}

/* Revealed cells */
.cell.revealed .cell-letter {
  color: var(--brown-light);
  opacity: 0.7;
}

/* Incorrect cell flash */
@keyframes cellShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}

.cell.incorrect {
  background: #f4d4ce !important;  /* soft terracotta-pink for the flash */
  animation: cellShake 0.4s ease-in-out;
}

/* Clue bar */
#clue-bar {
  width: 100%;
  background: var(--clue-bar-bg);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  min-height: 44px;
}

#clue-bar button {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--brown-light);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
}

#clue-bar button:hover {
  color: var(--accent);
}

#clue-text {
  font-size: 0.92rem;
  flex: 1;
  text-align: center;
  line-height: 1.35;
  color: var(--brown);
}

.clue-label {
  font-weight: 700;
  color: var(--accent);
}

/* Clue lists */
#clue-lists {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.clue-section h3 {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  color: var(--sage);
}

.clue-section ol {
  list-style: none;
}

.clue-section li {
  font-size: 0.88rem;
  line-height: 1.4;
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.1s;
  color: var(--brown);
}

.clue-section li:hover {
  background: var(--clue-bar-bg);
}

.clue-section li.active {
  background: var(--cell-highlight);
  font-weight: 600;
}

.clue-number {
  font-weight: 700;
  color: var(--accent);
  margin-right: 4px;
}

/* Completion overlay */
#complete-overlay {
  position: fixed;
  inset: 0;
  background: rgba(61, 48, 41, 0.5);  /* brown-tinted overlay */
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.3s;
}

#complete-overlay.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

#complete-modal {
  background: #fff;
  border-radius: 16px;
  padding: 32px 28px;
  text-align: center;
  max-width: 340px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(61, 48, 41, 0.3);
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

#close-modal {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.6rem;
  color: var(--brown-light);
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

#close-modal:hover {
  color: var(--brown);
}

/* Star */
#complete-star {
  font-size: 3rem;
  margin-bottom: 4px;
}

#complete-modal h2 {
  font-size: 1.5rem;
  margin-bottom: 2px;
  color: var(--brown);
}

.complete-subtitle {
  font-size: 0.95rem;
  color: var(--brown-light);
  margin-bottom: 20px;
}

/* Stats card */
#stats-card {
  background: var(--sand);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  text-align: left;
}

.stats-header {
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule);
}

.stats-date {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--brown);
}

.stats-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--rule);
}

.stats-row-last {
  border-bottom: none;
}

.stats-label {
  font-size: 0.85rem;
  color: var(--brown-light);
}

.stats-value {
  font-size: 0.85rem;
  font-weight: 700;
  text-align: right;
  color: var(--brown);
}

/* Share grid */
#share-grid {
  font-family: monospace;
  font-size: 1.4rem;
  line-height: 1.5;
  margin-bottom: 16px;
  letter-spacing: 0.1em;
}

/* Buttons */
#complete-buttons {
  display: flex;
  gap: 10px;
}

#complete-buttons button {
  flex: 1;
  border: none;
  border-radius: 999px;
  padding: 12px 0;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, background-color 0.1s;
}

#share-btn {
  background: var(--accent);
  color: #fff;
}

#share-btn:hover {
  background: var(--accent-dark);
}

#done-btn {
  background: var(--tan);
  color: var(--brown);
}

#done-btn:hover {
  background: #ddd2bf;
}

#complete-buttons button:active {
  transform: scale(0.97);
}

#copied-msg {
  font-size: 0.85rem;
  color: var(--sage);
  margin-top: 8px;
  font-weight: 600;
}

#copied-msg.hidden {
  display: none;
}

/* Modal CTA */
#modal-cta {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--rule);
  text-align: center;
}

.cta-line {
  font-size: 0.92rem;
  color: var(--brown);
  margin: 0 0 4px 0;
  line-height: 1.4;
}

.cta-detail {
  font-size: 0.85rem;
  color: var(--brown-light);
  margin: 0 0 14px 0;
  line-height: 1.4;
}

.cta-btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  border-radius: 999px;
  padding: 10px 28px;
  font-size: 0.92rem;
  font-weight: 600;
  transition: background-color 0.1s, transform 0.1s;
}

.cta-btn:hover {
  background: var(--accent-dark);
}

.cta-btn:active {
  transform: scale(0.97);
}

/* Footer CTA */
.footer-cta {
  font-size: 0.9rem !important;
  color: var(--brown-light) !important;
  margin-bottom: 12px !important;
}

.footer-cta a {
  color: var(--accent) !important;
  font-weight: 600;
}

/* Footer */
#site-footer {
  margin-top: 32px;
  padding: 20px 16px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--brown-light);
  line-height: 1.6;
}

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

#site-footer a:hover {
  text-decoration: underline;
}

/* No-puzzle empty state */
#no-puzzle {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--brown-light);
}

#no-puzzle.hidden {
  display: none;
}

#no-puzzle a {
  color: var(--accent);
  font-weight: 600;
}

/* Focus ring */
.cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

@media (hover: none) {
  .cell {
    touch-action: manipulation;
  }
}
