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

:root {
  /* Dark mode (default) */
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-light: #334155;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --accent: #22c55e;
  --accent-dim: #16a34a;
  --warning: #eab308;
  --error: #ef4444;
  --cell-size: min(70px, 18vw);
  --cell-size-4x4: min(55px, 14vw);
  --target-size: min(45px, 12vw);
  --target-size-4x4: min(38px, 10vw);
}

/* Light mode */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f8fafc;
    --surface: #e2e8f0;
    --surface-light: #cbd5e1;
    --text: #0f172a;
    --text-dim: #64748b;
    --accent: #16a34a;
    --accent-dim: #15803d;
    --warning: #ca8a04;
    --error: #dc2626;
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  padding: 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}

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

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.icon-btn:hover {
  background: var(--surface-light);
}

.mode-toggle {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.mode-btn {
  padding: 0.5rem 1rem;
  border: 2px solid var(--surface-light);
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.mode-btn:hover:not(.locked) {
  border-color: var(--text-dim);
}

.mode-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(34, 197, 94, 0.1);
}

.mode-btn.locked {
  opacity: 0.5;
  cursor: not-allowed;
}

.mode-btn.unlocked {
  opacity: 1;
  cursor: pointer;
}

/* Game info bar */
.game-info {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-bottom: 1rem;
  font-size: 1rem;
  color: var(--text-dim);
}

.game-info.hidden {
  display: none;
}

.timer {
  font-variant-numeric: tabular-nums;
}

.hint-count {
  font-variant-numeric: tabular-nums;
}

.hint-count.empty {
  color: var(--error);
  opacity: 0.6;
}

/* Main content */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.grid-wrapper {
  padding: 0.5rem;
}

/* Grid - 3x3 */
.grid {
  display: grid;
  gap: 6px;
}

.grid-3x3 {
  grid-template-columns: repeat(3, var(--cell-size)) var(--target-size);
  grid-template-rows: repeat(3, var(--cell-size)) var(--target-size);
}

.grid-4x4 {
  grid-template-columns: repeat(4, var(--cell-size-4x4)) var(--target-size-4x4);
  grid-template-rows: repeat(4, var(--cell-size-4x4)) var(--target-size-4x4);
}

.cell {
  background: var(--surface);
  border: 2px solid var(--surface-light);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.grid-4x4 .cell {
  font-size: 1.4rem;
  border-radius: 6px;
}

.cell:hover {
  border-color: var(--text-dim);
}

.cell.selected {
  border-color: var(--accent);
  background: rgba(34, 197, 94, 0.1);
}

.cell.filled {
  color: var(--text);
}

.cell.hint {
  color: var(--accent);
  background: rgba(34, 197, 94, 0.15);
}

.target {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-dim);
  transition: color 0.2s ease;
}

.grid-4x4 .target {
  font-size: 0.8rem;
}

.target.satisfied {
  color: var(--accent);
}

.target.exceeded {
  color: var(--error);
}

.row-target {
  padding-left: 0.5rem;
  justify-content: flex-start;
}

.col-target {
  padding-top: 0.5rem;
  align-items: flex-start;
}

.corner {
  /* Empty corner cell */
}

/* Input pad */
.input-pad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 260px;
}

.input-pad.hidden {
  display: none;
}

.digit-btn {
  aspect-ratio: 1;
  border: none;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}

.digit-btn:hover {
  background: var(--surface-light);
}

.digit-btn:active {
  transform: scale(0.95);
}

.clear-btn {
  background: var(--surface-light);
  color: var(--error);
}

/* Controls */
.controls {
  display: flex;
  gap: 1rem;
}

.controls.hidden {
  display: none;
}

.control-btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.control-btn:hover:not(:disabled) {
  background: var(--surface-light);
}

.control-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Message */
.message {
  min-height: 1.5rem;
  color: var(--text-dim);
  font-size: 0.9rem;
  text-align: center;
}

.message.error {
  color: var(--error);
}

.message.success {
  color: var(--accent);
}

/* Completed state */
.completed-state {
  text-align: center;
  padding: 1rem;
}

.completed-state.hidden {
  display: none;
}

.completed-text {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.next-puzzle {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.next-puzzle span {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}

.today-times {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 1rem;
  line-height: 1.5;
}

.completed-state .share-btn {
  margin-bottom: 1rem;
  max-width: 200px;
}

/* Modal base */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--surface);
  padding: 1.75rem;
  border-radius: 16px;
  text-align: center;
  max-width: 340px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-content h2 {
  font-size: 1.4rem;
  margin-bottom: 1rem;
}

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

/* Tutorial modal */
.tutorial-content {
  text-align: left;
}

.tutorial-content h2 {
  text-align: center;
}

.tutorial-steps {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.tutorial-step {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.step-icon {
  width: 36px;
  height: 36px;
  background: var(--surface-light);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.tutorial-step p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text);
}

.tutorial-example {
  background: var(--bg);
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1.25rem;
}

.example-label {
  font-weight: 600;
  color: var(--text) !important;
  margin-bottom: 0.5rem !important;
  font-size: 0.9rem;
}

.example-text {
  font-size: 0.85rem;
  margin-bottom: 0.25rem !important;
}

.example-text.dim {
  color: var(--text-dim);
  font-style: italic;
}

/* Stats modal */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-item {
  text-align: center;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Win modal */
.win-title {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.win-time {
  color: var(--text-dim);
  margin-bottom: 1rem;
}

.win-times {
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 1rem;
}

/* Buttons */
.share-btn {
  width: 100%;
  padding: 0.875rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 0.75rem;
}

.share-btn:hover {
  background: var(--accent-dim);
}

.play-next-btn {
  width: 100%;
  padding: 0.75rem;
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 0.75rem;
}

.play-next-btn:hover {
  background: rgba(34, 197, 94, 0.1);
}

.close-btn {
  width: 100%;
  padding: 0.75rem;
  border: none;
  border-radius: 8px;
  background: var(--surface-light);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}

.close-btn:hover {
  background: var(--bg);
}

/* Unlock message */
.unlock-message {
  background: rgba(34, 197, 94, 0.15);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 1rem;
}

.unlock-message p {
  color: var(--accent);
  margin: 0;
  font-weight: 500;
}

/* Animations */
@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.cell.pop {
  animation: pop 0.2s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.cell.shake {
  animation: shake 0.3s ease;
}

@keyframes celebrate {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.grid.celebrate .cell {
  animation: celebrate 0.4s ease;
  border-color: var(--accent);
}
