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

:root {
  --cell-size: min(60px, (100vw - 40px) / 5);
  --bg: #fafafa;
  --text: #1a1a1a;
  --grid-border: #333;
  --cell-border: #ccc;
  --cell-selected: #a8d8ff;
  --cell-highlight: #dceefb;
  --cell-correct: #6aaa64;
  --cell-present: #c9b458;
  --cell-absent: #787c7e;
  --clue-bar-bg: #f0f0f0;
  --accent: #2563eb;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, 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;
}

.date {
  font-size: 0.85rem;
  color: #666;
  margin-top: 2px;
}

/* Timer */
#timer {
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  color: #888;
  margin-bottom: 10px;
}

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

#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);
}

/* Selected takes priority over highlighted */
.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: #333;
}

.cell-letter {
  margin-top: 4px;
}

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

#toolbar button {
  background: #fff;
  border: 1.5px solid #ddd;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #555;
  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: #999;
}

/* 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: #666;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
}

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

#clue-text {
  font-size: 0.9rem;
  flex: 1;
  text-align: center;
  line-height: 1.3;
}

.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: #555;
}

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

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

.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(0, 0, 0, 0.5);
  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(0, 0, 0, 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: #999;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

#close-modal:hover {
  color: #333;
}

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

#complete-modal h2 {
  font-size: 1.5rem;
  margin-bottom: 2px;
}

.complete-subtitle {
  font-size: 0.95rem;
  color: #888;
  margin-bottom: 20px;
}

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

.stats-header {
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #e0e0e0;
}

.stats-date {
  font-weight: 700;
  font-size: 0.95rem;
}

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

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

.stats-label {
  font-size: 0.85rem;
  color: #888;
}

.stats-value {
  font-size: 0.85rem;
  font-weight: 700;
  text-align: right;
}

/* 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: #1d4ed8;
}

#done-btn {
  background: #e8e8e8;
  color: #333;
}

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

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

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

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

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

/* Prevent zoom on double-tap on iOS */
@media (hover: none) {
  .cell {
    touch-action: manipulation;
  }
}
