:root {
  --bg-primary: #faf8f5;
  --bg-secondary: #f5f2ed;
  --text-primary: #2c2825;
  --text-secondary: #6b635a;
  --accent: #c9a66b;
  --accent-hover: #b8935a;
  --cell-bg: #ffffff;
  --cell-border: #d4cfc7;
  --cell-active: #fff8e7;
  --cell-correct: #e8f5e9;
  --cell-incorrect: #ffebee;
  --shadow-soft: 0 2px 8px rgba(44, 40, 37, 0.08);
  --shadow-medium: 0 4px 16px rgba(44, 40, 37, 0.12);
  --radius: 4px;
}

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

html {
  font-size: 16px;
}

body {
  font-family: 'Crimson Pro', Georgia, serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.6;
  background-image: 
    radial-gradient(ellipse at 20% 20%, rgba(201, 166, 107, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(201, 166, 107, 0.06) 0%, transparent 50%);
  overflow-x: hidden;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem;
  overflow-x: hidden;
}

@media (max-width: 480px) {
  .container {
    padding: 1rem 1.25rem;
  }
}

/* Header */
header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.title {
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.subtitle {
  font-size: clamp(0.9rem, 3vw, 1.1rem);
  color: var(--text-secondary);
  font-style: italic;
}

/* Main Layout */
main {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

@media (min-width: 1024px) {
  main {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: start;
    gap: 3rem;
  }
}

/* Puzzle Area */
.puzzle-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  width: 100%;
}

.grid-wrapper {
  width: 100%;
  display: flex;
  justify-content: center;
  overflow: hidden;
  padding: 0 4px;
}

.grid-container {
  background: var(--cell-bg);
  padding: 0.625rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-medium);
  width: fit-content;
  max-width: 100%;
  touch-action: manipulation;
  overflow: hidden;
}

.crossword-grid {
  display: grid;
  gap: 0;
  width: fit-content;
  margin: 0 auto;
  /* Add 1px to account for collapsed borders */
  padding-right: 1px;
  padding-bottom: 1px;
}

.cell {
  aspect-ratio: 1;
  position: relative;
  background: var(--cell-bg);
  border: 1px solid var(--cell-border);
  margin-right: -1px;
  margin-bottom: -1px;
  touch-action: manipulation;
}

.cell.empty {
  background: var(--text-primary);
  border-color: var(--text-primary);
}

.cell-number {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: clamp(0.5rem, 1.5vw, 0.65rem);
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-secondary);
  font-weight: 500;
  line-height: 1;
  pointer-events: none;
  z-index: 1;
}

.cell-input {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  text-align: center;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
  color: var(--text-primary);
  text-transform: uppercase;
  caret-color: var(--accent);
  outline: none;
  padding: 0;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.cell-input:focus {
  background: var(--cell-active);
}

.cell.active {
  z-index: 2;
  box-shadow: inset 0 0 0 2px var(--accent);
}

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

.cell.correct .cell-input {
  background: var(--cell-correct);
}

.cell.incorrect .cell-input {
  background: var(--cell-incorrect);
}

/* Controls */
.controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  max-width: 400px;
}

.btn {
  font-family: 'Crimson Pro', Georgia, serif;
  font-size: clamp(0.85rem, 2.5vw, 1rem);
  padding: 0.6rem 1rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
  flex: 1;
  min-width: 100px;
  touch-action: manipulation;
}

.btn-check {
  background: var(--accent);
  color: white;
}

.btn-check:hover, .btn-check:active {
  background: var(--accent-hover);
}

.btn-reveal {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--cell-border);
}

.btn-reveal:hover, .btn-reveal:active {
  background: var(--cell-border);
}

.btn-clear {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--cell-border);
}

.btn-clear:hover, .btn-clear:active {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* Clues */
.clues-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  width: 100%;
}

@media (max-width: 500px) {
  .clues-container {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
}

.clues-section h2 {
  font-size: clamp(1rem, 3vw, 1.25rem);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--accent);
  display: inline-block;
}

.clues-list {
  list-style: none;
}

.clues-list li {
  padding: 0.6rem 0.5rem;
  cursor: pointer;
  transition: all 0.15s ease;
  border-radius: var(--radius);
  font-size: clamp(0.9rem, 2.5vw, 1rem);
  -webkit-tap-highlight-color: transparent;
}

.clues-list li:hover {
  background: var(--bg-secondary);
}

.clues-list li:active {
  background: var(--cell-active);
}

.clues-list li.active {
  background: var(--cell-active);
}

.clues-list li.completed {
  color: var(--text-secondary);
  text-decoration: line-through;
}

.clue-number {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
  font-size: 0.85em;
  color: var(--accent);
  margin-right: 0.5rem;
}

.clue-text {
  color: var(--text-primary);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(44, 40, 37, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.3s ease;
  padding: 1rem;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--cell-bg);
  padding: clamp(1.5rem, 5vw, 3rem);
  border-radius: var(--radius);
  text-align: center;
  box-shadow: var(--shadow-medium);
  animation: slideUp 0.3s ease;
  max-width: 90%;
  width: 100%;
  max-width: 400px;
}

.modal-icon {
  width: 60px;
  height: 60px;
  background: var(--cell-correct);
  color: #4caf50;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin: 0 auto 1.5rem;
}

.modal-content h2 {
  font-size: clamp(1.25rem, 4vw, 1.75rem);
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.modal-content p {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

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

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

/* Mobile keyboard helper */
.keyboard-helper {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--cell-border);
  padding: 0.5rem;
  display: none;
  z-index: 100;
}

.keyboard-helper.visible {
  display: block;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 0.25rem;
  margin-bottom: 0.25rem;
}

.keyboard-row:last-child {
  margin-bottom: 0;
}

.key {
  min-width: clamp(28px, 8vw, 36px);
  height: clamp(36px, 10vw, 44px);
  border: none;
  border-radius: var(--radius);
  background: var(--cell-bg);
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(0.9rem, 3vw, 1.1rem);
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  transition: all 0.1s ease;
}

.key:active {
  background: var(--cell-active);
  transform: scale(0.95);
}

.key.wide {
  min-width: clamp(50px, 12vw, 70px);
  font-size: clamp(0.75rem, 2.5vw, 0.9rem);
}

/* Direction indicator */
.direction-indicator {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.direction-indicator.visible {
  display: flex;
}

.direction-indicator .dir-label {
  font-weight: 500;
  color: var(--accent);
}

.direction-toggle {
  padding: 0.25rem 0.75rem;
  background: var(--cell-bg);
  border: 1px solid var(--cell-border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  touch-action: manipulation;
}

/* Loading State */
.loading {
  text-align: center;
  padding: 3rem;
  color: var(--text-secondary);
  font-style: italic;
}

/* Print styles */
@media print {
  .controls, .modal, .keyboard-helper, .direction-indicator {
    display: none !important;
  }
  
  body {
    background: white;
  }
  
  .grid-container {
    box-shadow: none;
    border: 1px solid #ccc;
  }
}

/* Landscape mobile optimization */
@media (max-height: 500px) and (orientation: landscape) {
  .container {
    padding: 0.5rem;
  }
  
  header {
    margin-bottom: 0.5rem;
  }
  
  main {
    flex-direction: row;
    gap: 1rem;
    align-items: flex-start;
  }
  
  .puzzle-area {
    flex: 0 0 auto;
  }
  
  .clues-container {
    flex: 1;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
  }
}
