/* Valentine's Day Crossword */

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

:root {
  --page-bg-start: #f6f4ef;
  --page-bg-end: #f1ecf6;
  --surface: #ffffff;
  --surface-soft: #f7f7f8;
  --border: #222222;
  --border-soft: #adb2bf;

  --text-primary: #1b1b1f;
  --text-clue: #2a2d38;
  --text-muted: #697081;

  --accent: #d73a67;
  --accent-soft: #f8d4df;

  --cell-size: 38px;
  --cell-number-size: 10px;
  --cell-letter-size: 24px;

  --cell-bg: #ffffff;
  --cell-black: #000000;
  --cell-selected: #ffd866;
  --cell-highlighted: #cde8ff;
  --cell-correct: #cdeecd;
  --cell-incorrect: #ffd7dc;

  --shadow: 0 12px 34px rgba(27, 27, 31, 0.08);
}

body {
  min-height: 100vh;
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--text-primary);
  background: linear-gradient(165deg, var(--page-bg-start), var(--page-bg-end));
}

.page-header {
  padding: 24px 16px 10px;
  text-align: center;
}

.puzzle-title {
  font-family: "Iowan Old Style", "Georgia", serif;
  font-size: clamp(1.5rem, 2.3vw, 2rem);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--accent);
}

.puzzle-title.completed {
  color: #b22a53;
}

#app {
  padding: 8px 16px 24px;
}

.crossword-container {
  max-width: 1220px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto minmax(280px, 1fr);
  gap: 20px;
  align-items: start;
}

.grid-panel {
  background: var(--surface);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px;
}

#grid-container {
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 6px;
  -webkit-overflow-scrolling: touch;
}

.crossword-grid {
  display: grid;
  grid-template-columns: repeat(15, var(--cell-size));
  width: fit-content;
  margin: 0 auto;
  border: 2px solid var(--border);
  background: var(--border);
  user-select: none;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  position: relative;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.cell.white {
  background: var(--cell-bg);
  cursor: pointer;
  transition: background-color 0.1s ease;
}

.cell.white:hover {
  background: #f4f8ff;
}

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

.cell-number {
  position: absolute;
  top: 2px;
  left: 2px;
  font-size: var(--cell-number-size);
  line-height: 1;
  color: var(--text-muted);
  font-weight: 600;
  pointer-events: none;
}

.cell-letter {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--cell-letter-size);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  pointer-events: none;
}

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

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

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

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

.cell.locked {
  cursor: default;
}

.hidden-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  font-size: 16px; /* Prevent iOS auto-zoom on focus */
}

.actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.action-btn {
  border: 1px solid #b9bfcc;
  border-radius: 8px;
  background: #ffffff;
  color: var(--text-primary);
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.action-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: #fff8fb;
}

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

.message {
  margin-top: 10px;
  min-height: 22px;
  font-size: 14px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.message.visible {
  opacity: 1;
}

.message.info {
  color: #355f93;
}

.message.success {
  color: #2d6f37;
}

.message.error {
  color: #a01d2f;
}

.clue-container {
  background: var(--surface);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  max-height: calc(100vh - 120px);
  overflow: auto;
  scrollbar-width: thin;
}

.clue-container::-webkit-scrollbar {
  width: 8px;
}

.clue-container::-webkit-scrollbar-track {
  background: transparent;
  margin: 14px 0;
}

.clue-container::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
}

.clue-section h2 {
  margin-bottom: 8px;
  font-size: 16px;
  color: var(--accent);
}

.clue-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.clue-item {
  border-left: 3px solid transparent;
  border-radius: 6px;
  padding: 6px 8px;
  cursor: pointer;
  line-height: 1.3;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.clue-item:hover {
  background: #f4f7fb;
}

.clue-item.active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.clue-number {
  color: var(--text-muted);
  font-weight: 700;
  margin-right: 6px;
}

.clue-text {
  color: var(--text-clue);
  font-size: 14px;
  line-height: 1.45;
}

.completion-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(16, 14, 20, 0.45);
  padding: 20px;
  z-index: 100;
}

.completion-overlay.hidden {
  display: none;
}

.completion-content {
  width: min(420px, 100%);
  background: #ffffff;
  border-radius: 16px;
  border-top: 3px solid var(--accent);
  padding: 26px 22px;
  text-align: center;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.26);
}

.completion-message {
  font-size: 24px;
  line-height: 1.3;
  margin-bottom: 16px;
}

.cell.celebrate {
  animation: celebrate-pulse 0.65s ease;
}

@keyframes celebrate-pulse {
  0% { background: var(--cell-bg); }
  50% { background: var(--accent); }
  100% { background: var(--cell-correct); }
}

@media (max-width: 960px) {
  :root {
    --cell-size: clamp(28px, calc((100vw - 72px) / 15), 40px);
    --cell-number-size: clamp(7px, calc(var(--cell-size) * 0.26), 10px);
    --cell-letter-size: clamp(16px, calc(var(--cell-size) * 0.6), 24px);
  }

  .crossword-container {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .grid-panel {
    max-width: 660px;
    width: 100%;
  }

  #app {
    padding: 8px 12px 24px;
  }

  .clue-container {
    max-height: none;
  }
}

@media (max-width: 650px) {
  .clue-container {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .page-header {
    padding: 12px 12px 8px;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  #clear-btn {
    grid-column: 1 / -1;
  }

  .action-btn {
    padding: 10px 8px;
    font-size: 13px;
  }
}

@media (max-width: 500px) {
  :root {
    /* --cell-size is set dynamically by JS to fit 15 columns in viewport */
    --cell-number-size: 8px;
    --cell-letter-size: calc(var(--cell-size) * 0.55);
  }

  /* Lock viewport — only clue list scrolls */
  body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .page-header {
    flex-shrink: 0;
    padding: 12px 12px 8px;
  }

  #app {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 4px 0 0;
  }

  .crossword-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 0;
  }

  /* Pinned: grid + actions */
  .grid-panel {
    flex-shrink: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    padding: 8px;
    box-shadow: none;
    max-width: none;
  }

  #grid-container {
    overflow: visible;
    padding-bottom: 0;
  }

  .crossword-grid {
    margin: 0 auto;
  }

  .message {
    margin-top: 6px;
    font-size: 13px;
  }

  /* Scrollable: full clue list */
  .clue-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    box-shadow: none;
    padding: 14px 12px 32px;
    max-height: none;
  }

  .clue-item {
    padding: 8px 10px;
    font-size: 15px;
  }

  .clue-text {
    font-size: 15px;
  }
}

@media (max-width: 375px) {
  .page-header {
    padding: 8px 8px 6px;
  }

  .puzzle-title {
    font-size: 1.25rem;
  }

}
