/* ============================================
   1to9 Puzzle — Design System
   North Star: "The Daily Notebook"
   Register: product
   ============================================ */

/* --- Design Tokens (Light Theme) --- */
:root {
  /* Backgrounds */
  --bg-page: #fcfaf5;
  --bg-surface: #f8f6f0;

  /* Text */
  --text-primary: #3a3835;
  --text-secondary: #5a5754;
  --text-muted: #706b65;

  /* Borders */
  --border-default: #ddd8d0;
  --border-hover: #c8c3ba;
  --border-divider: #eeeade;

  /* Interactive */
  --hover-surface: #f3f0e8;
  --btn-active-bg: #666;
  --btn-active-text: #fff;

  /* Focus & Glow */
  --focus-ring: #2e7d32;
  --focus-glow: rgba(46, 125, 50, 0.12);

  /* Puzzle Grid */
  --cell-green: #B6E3AB;
  --cell-yellow: #f3ef9b;
  --cell-coral: #e8a088;
  --cell-hint-bg: #CAD0D4;
  --cell-hint-text: #943020;
  --cell-border: #4CAF50;

  /* Primary / Accent */
  --primary: #2e7d32;
  --primary-hover: #256b29;
  --accent: #d45f4a;

  /* Difficulty */
  --difficulty-easy: #66BB6A;
  --difficulty-medium: #E5A93D;
  --difficulty-hard: #B85C44;

  /* Difficulty Pictogram Scale (OKLCH-interpolated: 1=easy, 5=medium, 9=hard) */
  --pictogram-1: #66BB6A;
  --pictogram-2: #8eb951;
  --pictogram-3: #b0b53d;
  --pictogram-4: #cdaf33;
  --pictogram-5: #E5A93D;
  --pictogram-6: #de943a;
  --pictogram-7: #d3803c;
  --pictogram-8: #c76d40;
  --pictogram-9: #B85C44;

  /* Status */
  --error-bg: #fdf0ee;
  --error-text: #b94030;
  --success: #3a7d40;

  /* Secondary text on dark or tinted surfaces */
  --text-on-accent: #fff;

  /* Code */
  --code-bg: #f0ece4;

  /* Shadows (tinted for warmth) */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 2px 6px rgba(0,0,0,0.10);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.10);
  --shadow-dropdown: 0 4px 16px rgba(0,0,0,0.10);

  /* Misc */
  --privacy-divider: #e8e4dc;
  --footer-text: #666;
  --link-hover: #3a3835;
}

/* --- Dark Theme --- */
@media (prefers-color-scheme: dark) {
  :root {
    /* Backgrounds — 3-step elevation: deeper → mid → elevated (depth from lightness, not shadows) */
    --bg-page: #141211;
    --bg-surface: #1c1917;
    --bg-elevated: #242120;

    /* Text — light-on-dark reads heavier, so we use slightly muted secondaries */
    --text-primary: #ede8e0;
    --text-secondary: #a8a098;
    --text-muted: #8a8480;

    /* Borders */
    --border-default: #3a3835;
    --border-hover: #504c46;
    --border-divider: #353330;

    /* Interactive */
    --hover-surface: #242120;
    --btn-active-bg: #a09890;
    --btn-active-text: #1a1916;

    /* Focus — explicit colors, no alpha transparency */
    --focus-ring: #66BB6A;
    --focus-glow: #1e2e1c;

    /* Puzzle Grid — hue identity preserved, chroma tuned for dark bg */
    --cell-green: #2a4a28;
    --cell-yellow: #4d4727;
    --cell-coral: #502822;
    --cell-hint-bg: #303538;
    --cell-hint-text: #d87868;
    --cell-border: #4a9a4e;

    /* Primary / Accent — coral desaturated slightly for dark surfaces */
    --primary: #2d6a2e;
    --primary-hover: #388e3c;
    --accent: #d06050;

    /* Difficulty (brightened for dark bg) */
    --difficulty-easy: #80d084;
    --difficulty-medium: #edb04f;
    --difficulty-hard: #d07058;

    /* Difficulty Pictogram Scale */
    --pictogram-1: #80d084;
    --pictogram-2: #a2ca6a;
    --pictogram-3: #bfc355;
    --pictogram-4: #d9ba4b;
    --pictogram-5: #edb04f;
    --pictogram-6: #e99f4d;
    --pictogram-7: #e38e4f;
    --pictogram-8: #da7e53;
    --pictogram-9: #d07058;

    /* Status */
    --error-bg: #3a2020;
    --error-text: #f0a090;
    --success: #7dca80;

    /* Secondary text on dark or tinted surfaces */
    --text-on-accent: #fff;

    /* Code */
    --code-bg: #242120;

    /* Shadows — reduced (depth comes from surface lightness, not shadow density) */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.10);
    --shadow-md: 0 2px 6px rgba(0,0,0,0.12);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.15);
    --shadow-dropdown: 0 4px 16px rgba(0,0,0,0.18);

    /* Misc */
    --privacy-divider: #353330;
    --footer-text: #a09890;
    --link-hover: #ede8e0;
  }

  /* Reduce body text weight — light-on-dark reads heavier than dark-on-light */
  body {
    font-weight: 350;
  }
}

/* --- Screen Reader Only --- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Skip Link --- */
.skip-link {
  position: absolute;
  top: -100%;
  left: 16px;
  z-index: 200;
  padding: 8px 16px;
  background-color: var(--primary);
  color: var(--text-on-accent);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  text-decoration: none;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 0;
  outline: 2.5px solid var(--text-on-accent);
  outline-offset: 2px;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* --- Header --- */
.site-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px 16px 8px;
  position: relative;
}

.site-logo {
  height: 36px;
  width: auto;
  display: block;
  transition: transform 0.3s ease-out;
}

.site-logo:hover {
  transform: rotate(-4deg) scale(1.05);
}

.site-title {
  font-family: "Lora", "Times New Roman", serif;
  font-size: clamp(1.25rem, 4vw, 1.75rem);
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
  margin: 0;
}

/* Header link wrapper (used on auth pages) */
.site-header-link {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

/* Auth nav — right-aligned within header */
.avatar-menu {
  position: absolute;
  right: 16px;
  display: flex;
  align-items: center;
}

/* The circular avatar button */
.avatar-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border-default);
  background-color: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.avatar-btn:focus-visible {
  outline: 2.5px solid var(--focus-ring);
  outline-offset: 2px;
}

.avatar-btn:hover {
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 3px var(--focus-glow);
  transform: scale(1.06);
}

.avatar-btn:active {
  transform: scale(0.92);
  transition: transform 0.12s cubic-bezier(0.25, 1, 0.5, 1);
}

.avatar-btn.is-open {
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 3px var(--focus-glow);
}

/* Google profile picture */
.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

/* Initial letter fallback */
.avatar-initial {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--success);
  line-height: 1;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Generic person icon fallback */
.avatar-icon {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
}

/* Dropdown panel */
.avatar-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 180px;
  background-color: var(--bg-page);
  border: 1.5px solid var(--border-default);
  border-radius: 10px;
  box-shadow: var(--shadow-dropdown);
  padding: 6px;
  z-index: 100;
  /* Hidden state */
  opacity: 0;
  pointer-events: none;
  transform-origin: top right;
  transition: opacity 150ms ease;
}

@keyframes dropdown-enter {
  0%   { opacity: 0; transform: translateY(-8px) scale(0.96); }
  65%  { opacity: 1; transform: translateY(1px) scale(1.005); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes item-enter {
  from { opacity: 0; transform: translateY(-5px); }
  to   { opacity: 1; transform: translateY(0); }
}

.avatar-dropdown.is-open {
  pointer-events: auto;
  animation: dropdown-enter 250ms cubic-bezier(0.25, 1, 0.5, 1) both;
}

.avatar-dropdown.is-open > * {
  animation: item-enter 200ms cubic-bezier(0.25, 1, 0.5, 1) both;
}

.avatar-dropdown.is-open > *:nth-child(1) { animation-delay: 60ms; }
.avatar-dropdown.is-open > *:nth-child(2) { animation-delay: 100ms; }
.avatar-dropdown.is-open > *:nth-child(3) { animation-delay: 140ms; }

.avatar-dropdown-display-name {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 6px 10px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.avatar-dropdown-divider {
  height: 1px;
  background-color: var(--border-divider);
  margin: 4px 0;
}

.avatar-dropdown-item {
  display: block;
  width: 100%;
  padding: 8px 10px;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text-primary);
  text-decoration: none;
  background: none;
  border: none;
  border-radius: 6px;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s ease, transform 0.12s ease;
}

.avatar-dropdown-item:hover {
  background-color: var(--hover-surface);
  transform: translateX(3px);
}

.avatar-dropdown-item.is-disabled,
.avatar-dropdown-item[aria-disabled="true"] {
  color: var(--text-muted);
  opacity: 0.55;
  cursor: default;
  pointer-events: none;
}

.avatar-dropdown-item.is-disabled:hover,
.avatar-dropdown-item[aria-disabled="true"]:hover {
  background-color: transparent;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  .avatar-btn {
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
  }
  .avatar-btn:hover,
  .avatar-btn:active,
  .avatar-btn.is-open {
    transform: none;
  }
  .avatar-dropdown,
  .avatar-dropdown.is-open,
  .avatar-dropdown.is-open > * {
    animation: none;
    transition: opacity 0.15s ease;
  }
  .avatar-dropdown.is-open {
    opacity: 1;
    transform: none;
  }
  .avatar-dropdown-item {
    transition: background-color 0.12s ease;
  }
  .avatar-dropdown-item:hover {
    transform: none;
  }
}

/* --- Timer --- */
.timer-wrapper {
  text-align: center;
  padding: 4px 16px 20px;
}

.timer {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.offline-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: -14px 16px 0;
  min-height: 1.125rem;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--text-muted);
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.offline-indicator::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background-color: var(--accent);
  flex: 0 0 auto;
}

.offline-indicator.is-visible {
  visibility: visible;
  opacity: 1;
}

/* --- Main Content --- */
.main-content {
  width: 100%;
  max-width: 480px;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* --- Puzzle Grid --- */
.puzzle-grid {
  border-collapse: collapse;
  margin: 0 auto;
}

.puzzle-grid td {
  padding: 0;
  text-align: center;
}

/* Match the td width of game columns to the cell size */
.puzzle-grid td:nth-child(2),
.puzzle-grid td:nth-child(3),
.puzzle-grid td:nth-child(4) {
  min-width: clamp(52px, 18vw, 75px);
}

/* Cell buttons */
.cell {
  width: clamp(52px, 18vw, 75px);
  height: clamp(52px, 18vw, 75px);
  padding: 0;
  margin: 3px;
  border: 3px solid var(--cell-border);
  border-radius: 12px;
  font-size: clamp(24px, 8vw, 36px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 400;
  text-align: center;
  cursor: pointer;
  display: block;
  box-shadow: var(--shadow-md);
  transition: box-shadow 0.1s ease-out, transform 0.1s ease-out;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.cell:focus-visible {
  outline: 2.5px solid var(--focus-ring);
  outline-offset: 2px;
}

.cell:active {
  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
  transform: translateY(1px);
}

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

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

.cell-hint {
  background-color: var(--cell-hint-bg);
  color: var(--cell-hint-text);
  cursor: default;
  box-shadow: none;
}

.cell-hint:active {
  transform: none;
  box-shadow: none;
}

/* Solved state — cells are display-only */
.puzzle-grid.solved .cell {
  cursor: default;
  pointer-events: none;
}

/* Cell digit settle animation */
.just-filled {
  animation: digitSettle 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes digitSettle {
  0% { transform: scale(0.8); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* Clue cells around the grid */
.clue-cell {
  text-align: center;
  font-size: clamp(14px, 4vw, 20px);
  font-weight: 500;
  color: var(--text-primary);
  padding: 2px 6px;
  line-height: 1;
}

.clue-corner {
  font-size: clamp(12px, 3.5vw, 18px);
  font-weight: 500;
  text-align: center;
  padding: 2px 4px;
  display: inline-block;
}

.clue-corner-left {
  transform: rotate(45deg);
}

.clue-corner-right {
  transform: rotate(-45deg);
}

/* --- Difficulty Dot --- */
.grid-wrapper {
  position: relative;
  display: inline-block;
}

.difficulty-dot {
  position: absolute;
  top: 10px;
  right: 15px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: dotFadeIn 0.4s ease-out;
}

.difficulty-dot--easy {
  background-color: var(--difficulty-easy);
}

.difficulty-dot--medium {
  background-color: var(--difficulty-medium);
}

.difficulty-dot--hard {
  background-color: var(--difficulty-hard);
}

@keyframes dotFadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .difficulty-dot {
    animation: none;
  }
}

/* --- Number Pad Area --- */
.pad-area {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.number-pad {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 320px;
  padding: 4px 0;
}

.pad-btn {
  width: clamp(44px, 14vw, 56px);
  height: clamp(44px, 14vw, 56px);
  padding: 0;
  border: none;
  border-radius: 6px;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-size: clamp(18px, 6vw, 26px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.2s ease-out, color 0.2s ease-out, box-shadow 0.2s ease-out;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.pad-btn:focus-visible {
  outline: 2.5px solid var(--focus-ring);
  outline-offset: 2px;
}

.pad-btn:hover {
  background-color: var(--btn-active-bg);
  color: var(--btn-active-text);
  box-shadow: 0 2px 4px rgba(0,0,0,0.12);
}

/* Smooth press-and-release animation — one continuous curve */
@keyframes btnPress {
  0% { transform: scale(1); }
  30% { transform: scale(0.92); }
  100% { transform: scale(1); }
}

.pad-btn.pressed {
  animation: btnPress 0.22s ease-out;
}

.pad-btn.active {
  background-color: var(--btn-active-bg);
  color: var(--btn-active-text);
  box-shadow: 0 2px 4px rgba(0,0,0,0.12);
}

/* --- Solve Panel (replaces number pad on completion) --- */
.solve-panel {
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 24px 24px 20px;
  background-color: var(--accent);
  border-radius: 12px;
  color: var(--text-on-accent);
  text-align: center;
  cursor: default;
  width: 100%;
  max-width: 320px;
  animation: solveFadeIn 0.6s ease-out;
}

.solve-panel.is-visible {
  display: flex;
}

.solve-panel.no-anim.is-visible {
  animation: none;
}

/* "Well done!" badge */
.solve-complete {
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  margin: 0 0 4px;
  opacity: 0.6;
}

/* Score hero — the main event */
.solve-score-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.solve-score-number {
  font-size: clamp(2.75rem, 12vw, 4rem);
  font-weight: 700;
  line-height: 1;
  color: var(--text-on-accent);
}

.solve-score-unit {
  font-size: 0.45em;
  font-weight: 500;
  opacity: 0.75;
  vertical-align: super;
}

.solve-score-label-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.solve-score-label {
  font-size: 0.8125rem;
  font-weight: 500;
  opacity: 0.85;
}

/* MRS tooltip */
.mrs-tip-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: inherit;
  opacity: 0.5;
  cursor: pointer;
  padding: 2px;
  border-radius: 50%;
  transition: opacity 0.15s ease;
  flex-shrink: 0;
}
.mrs-tip-btn:hover {
  opacity: 0.9;
}
.mrs-tip-btn:focus-visible {
  outline: 2.5px solid var(--bg-page);
  outline-offset: 2px;
}

.mrs-tip {
  max-width: 260px;
  padding: 10px 14px;
  background-color: rgba(0, 0, 0, 0.15);
  border-radius: 8px;
}
.mrs-tip p {
  font-size: 0.75rem;
  line-height: 1.5;
  margin: 0;
  opacity: 0.85;
}

/* Divider between hero and footer */
.solve-divider {
  width: 48px;
  height: 1px;
  background-color: rgba(255, 255, 255, 0.2);
  margin: 20px 0 16px;
  flex-shrink: 0;
}

/* Footer — groups save status, sign-in nudge, reset button */
.solve-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.solve-footer-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.score-save-status {
  font-size: 0.8125rem;
  margin: 0;
  opacity: 0.82;
  line-height: 1.4;
}

.solve-signin-nudge {
  font-size: 0.8125rem;
  margin: 0;
  opacity: 0.82;
  line-height: 1.4;
}

.solve-signin-nudge a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.solve-reset-btn {
  background: none;
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  color: var(--text-on-accent);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 7px 16px;
  opacity: 0.75;
  transition: opacity 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}
.solve-reset-btn:hover {
  opacity: 1;
  border-color: rgba(255, 255, 255, 0.55);
}
.solve-reset-btn:active {
  transform: scale(0.96);
}
.solve-reset-btn:focus-visible {
  outline: 2.5px solid var(--bg-page);
  outline-offset: 2px;
}

/* Ghost button (used mid-puzzle, outside solve panel) */
.ghost-btn {
  background: none;
  border: 1.5px solid var(--border-default);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 7px 16px;
  transition: color 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}
.ghost-btn:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}
.ghost-btn:active {
  transform: scale(0.96);
}
.ghost-btn:focus-visible {
  outline: 2.5px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Pictogram action buttons (download + share) */
.pictogram-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin-top: 2px;
}

.download-pictogram-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: none;
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  color: var(--text-on-accent);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 7px 12px;
  opacity: 0.75;
  transition: opacity 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}
.download-pictogram-btn:hover {
  opacity: 1;
  border-color: rgba(255, 255, 255, 0.55);
}
.download-pictogram-btn:active {
  transform: scale(0.96);
}
.download-pictogram-btn:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}
.download-pictogram-btn:focus-visible {
  outline: 2.5px solid var(--bg-page);
  outline-offset: 2px;
}

.share-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  background: none;
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  color: var(--text-on-accent);
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}
.share-icon-btn:hover {
  opacity: 1;
  border-color: rgba(255, 255, 255, 0.55);
}
.share-icon-btn:active {
  transform: scale(0.92);
}
.share-icon-btn:disabled {
  opacity: 0.4;
  cursor: default;
  transform: none;
}
.share-icon-btn:focus-visible {
  outline: 2.5px solid var(--bg-page);
  outline-offset: 2px;
}

.share-error {
  font-size: 0.75rem;
  color: var(--text-on-accent);
  opacity: 0.75;
  margin: 4px 0 0;
}

@media (prefers-reduced-motion: reduce) {
  .solve-reset-btn,
  .ghost-btn,
  .download-pictogram-btn,
  .share-icon-btn { transition: none; }
}

@keyframes solveFadeIn {
  0% { opacity: 0; transform: translateY(16px) scale(0.96); }
  65% { opacity: 1; transform: translateY(-3px) scale(1.03); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* --- Instructions --- */
.instructions {
  text-align: center;
  font-size: clamp(0.8125rem, 2.5vw, 0.9375rem);
  color: var(--text-secondary);
  max-width: 45ch;
  line-height: 1.5;
  margin: 0;
  padding: 0 8px;
}

/* --- Privacy Policy --- */
.privacy-page-content {
  max-width: 660px;
  align-items: flex-start;
  padding-top: 32px;
}

.privacy-content {
  width: 100%;
  padding: 0 0 48px;
}

.privacy-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 4px;
}

.privacy-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0 0 20px;
}

.privacy-content .policy-ai-disclosure {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: italic;
  margin: 0 0 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--privacy-divider);
}

.privacy-content section {
  margin-bottom: 24px;
}

.privacy-content h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 6px;
}

.privacy-content p,
.privacy-content li {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.65;
  margin: 0 0 8px;
}

.privacy-content ul {
  padding-left: 20px;
  margin: 4px 0 8px;
}

.privacy-content code {
  font-size: 0.82rem;
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 3px;
}

.privacy-content a {
  color: var(--text-primary);
  text-underline-offset: 2px;
}

/* --- Footer --- */
.site-footer {
  width: 100%;
  text-align: center;
  padding: 32px 16px 24px;
  margin-top: auto;
  font-size: 0.75rem;
  color: var(--footer-text);
}

.footer-link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.footer-link:hover {
  color: var(--link-hover);
}

/* --- Responsive --- */
@media (max-width: 400px) {
  .site-header {
    gap: 8px;
    padding: 16px 12px 4px;
  }

  .site-logo {
    height: 28px;
  }

  .main-content {
    gap: 14px;
    padding: 0 12px;
  }

  .timer-wrapper {
    padding: 2px 12px 12px;
  }

  .number-pad {
    gap: 6px;
    max-width: 280px;
  }

  .solve-panel {
    padding: 20px 16px 16px;
    max-width: 280px;
  }

  .solve-divider {
    margin: 16px 0 12px;
  }

  .solve-score-number {
    font-size: clamp(2.25rem, 14vw, 3rem);
  }
}

@media (min-width: 768px) {
  .cell {
    width: 75px;
    height: 75px;
    font-size: 36px;
  }

  .puzzle-grid td:nth-child(2),
  .puzzle-grid td:nth-child(3),
  .puzzle-grid td:nth-child(4) {
    min-width: 75px;
  }

  .clue-cell {
    font-size: 20px;
  }

  .clue-corner {
    font-size: 18px;
  }

  .pad-btn {
    width: 56px;
    height: 56px;
    font-size: 26px;
  }
}


/* --- Auth Pages --- */

.auth-content {
  flex: 1;
  justify-content: flex-start;
  padding-top: 32px;
}

.auth-form-wrapper {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form-wrapper form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-heading {
  font-family: "Lora", "Times New Roman", serif;
  font-size: clamp(1.25rem, 4vw, 1.5rem);
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 4px;
}

.auth-subtext {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  margin: 0 0 4px;
  line-height: 1.5;
}

/* Auth button (logout confirm, etc.) */
.auth-btn {
  display: inline-block;
  width: 100%;
  padding: 10px 24px;
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text-on-accent);
  background-color: var(--primary);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
  -webkit-appearance: none;
}

.auth-btn:hover {
  background-color: var(--primary-hover);
}

.auth-btn:active {
  transform: translateY(1px);
}

/* Auth link (footer navigation) */
.auth-link {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-size: 0.875rem;
}

.auth-link:hover {
  color: var(--primary);
}

/* Auth footer text wrapper */
.auth-footer-text {
  margin-top: 4px;
  text-align: center;
}

/* Auth title (used on error pages) */
.auth-title {
  font-family: "Lora", "Times New Roman", serif;
  font-size: clamp(1.25rem, 4vw, 1.5rem);
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 16px;
}

/* Auth subtitle (used on error pages) */
.auth-subtitle {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin: 0 0 12px;
}

.auth-subtitle--spacer {
  margin-top: 12px;
}

/* Auth error list (used on error pages) */
.auth-error-list {
  margin: 8px 0 16px 20px;
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

/* Auth retry button (used on error pages) */
.auth-retry-btn {
  display: block;
  text-align: center;
  text-decoration: none;
  margin-top: 8px;
}

/* Error list */
.auth-errors {
  list-style: none;
  margin: 0 0 4px;
  padding: 10px 14px;
  background-color: var(--error-bg);
  border-radius: 6px;
  font-size: 0.875rem;
  color: var(--error-text);
}

.auth-errors li + li {
  margin-top: 4px;
}

/* Google OAuth button */
.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 11px 16px;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-size: 0.9375rem;
  font-weight: 500;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  border: 1.5px solid var(--border-default);
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn-google:hover {
  background-color: var(--hover-surface);
  border-color: var(--border-hover);
}

.google-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* ── Email auth button ─────────────────────────────────────────────────── */

.btn-email {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 11px 16px;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-size: 0.9375rem;
  font-weight: 500;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  border: 1.5px solid var(--border-default);
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn-email:hover {
  background-color: var(--hover-surface);
  border-color: var(--border-hover);
}

.email-icon {
  width: 18px;
  height: 14px;
  flex-shrink: 0;
  color: var(--text-secondary);
}

/* ── "or" divider between auth buttons ────────────────────────────────── */

.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background-color: var(--border-divider);
}

/* ── Auth form input (email / code fields on OTP pages) ───────────────── */

.auth-field {
  margin-bottom: 0;
}

.auth-input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border-default);
  border-radius: 8px;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  outline: none;
  box-sizing: border-box;
  -webkit-appearance: none;
}

.auth-input:focus {
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 3px var(--focus-glow);
}

.auth-input--error {
  border-color: var(--error-text);
}

/* ── OTP code input — larger, centered, monospaced feel ───────────────── */

.auth-code-input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border-default);
  border-radius: 8px;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-size: 1.75rem;
  font-weight: 600;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  letter-spacing: 0.35em;
  text-align: center;
  line-height: 1.3;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  outline: none;
  box-sizing: border-box;
  -webkit-appearance: none;
}

.auth-code-input:focus {
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 3px var(--focus-glow);
}

.auth-code-input--error {
  border-color: var(--error-text);
}

/* ── Ghost link-button (for "Send a new code" resend action) ──────────── */

.auth-link-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-size: 0.875rem;
  font-family: inherit;
}

.auth-link-btn:hover {
  color: var(--primary);
}

/* ── Secondary button (outlined, for resend/cancel-style actions) ─────── */

.btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 9px 24px;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text-muted);
  background: none;
  border: 1.5px solid var(--border-default);
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease, transform 0.1s ease;
  -webkit-appearance: none;
  text-decoration: none;
  text-align: center;
}

.btn-secondary:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.btn-secondary:active {
  transform: translateY(1px);
}

.btn-secondary:focus-visible {
  outline: 2.5px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ============================================================
   Profile page
   ============================================================ */

.profile-page {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding-bottom: 48px;
}

/* Avatar section */
.profile-avatar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.profile-avatar-img {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  box-shadow: 0 2px 10px rgba(0,0,0,0.10);
}

.profile-avatar-initial {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background-color: var(--cell-green);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--success);
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}

.profile-avatar-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0;
}

/* Identity section */
.profile-identity {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* View mode: name */
.profile-display-name {
  font-family: "Lora", "Times New Roman", serif;
  font-size: clamp(1.25rem, 4vw, 1.5rem);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

/* Edit form */
.profile-edit-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.profile-field-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.profile-field-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin: -4px 0 0;
}

.profile-field-wrap {
  position: relative;
}

.profile-input {
  width: 100%;
  padding: 10px 48px 10px 12px;
  border: 1.5px solid var(--border-default);
  border-radius: 8px;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  outline: none;
}

.profile-input:focus {
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 3px var(--focus-glow);
}

.profile-char-count {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.6875rem;
  color: var(--text-muted);
  pointer-events: none;
}

.profile-error {
  font-size: 0.8125rem;
  color: var(--difficulty-hard);
  margin: 0;
}

.profile-form-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.profile-save-btn {
  width: 100%;
  padding: 10px 24px;
  font-size: 0.9375rem;
  background-color: var(--primary);
  color: var(--text-on-accent);
  font-weight: 600;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
  -webkit-appearance: none;
}

.profile-save-btn:hover {
  background-color: var(--primary-hover);
}

.profile-save-btn:active {
  transform: translateY(1px);
}

.profile-save-btn.is-saving {
  opacity: 0.6;
  cursor: default;
}

.profile-cancel-btn {
  width: 100%;
  background: none;
  border: 1.5px solid var(--border-default);
  border-radius: 8px;
  padding: 9px 24px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  transition: color 0.12s ease, border-color 0.12s ease;
}

.profile-cancel-btn:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}

/* Success message */
.profile-success {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--success);
  margin: 0;
}

/* Email (read-only) */
.profile-email {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0;
}

/* ============================================================
   Charts page
   ============================================================ */

.charts-page {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  padding-bottom: 48px;
}

.charts-heading {
  font-family: "Lora", "Times New Roman", serif;
  font-size: clamp(1.25rem, 4vw, 1.5rem);
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.charts-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 4px 0 24px;
  line-height: 1.5;
}

.charts-empty {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  text-align: center;
  margin: 32px 0;
}

.week-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding-top: 16px;
  margin-bottom: 24px;
  border-top: 1px solid var(--border-divider);
}

.week-nav-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--border-default);
  background: transparent;
  color: var(--text-secondary);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  user-select: none;
  outline: none;
}

.week-nav-arrow:hover:not(:disabled) {
  background: var(--bg-surface);
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.week-nav-arrow:focus-visible {
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 3px var(--focus-glow);
}

.week-nav-arrow:disabled {
  opacity: 0.3;
  cursor: default;
  border-color: var(--border-divider);
}

.week-nav-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 150px;
  text-align: center;
}

.chart-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chart-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chart-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.chart-description {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
}

.chart-canvas-wrap {
  position: relative;
  width: 100%;
  background-color: var(--bg-surface);
  border-radius: 10px;
  padding: 20px 16px 12px;
}

.chart-divider {
  height: 1px;
  background-color: var(--border-divider);
  margin: 8px 0;
}

@media (min-width: 768px) {
  .charts-page {
    max-width: 580px;
  }

  .chart-canvas-wrap {
    padding: 24px 20px 16px;
  }
}

/* ============================================================
   Archive page
   ============================================================ */

.archive-page {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding-bottom: 48px;
}

.archive-heading {
  font-family: "Lora", "Times New Roman", serif;
  font-size: clamp(1.25rem, 4vw, 1.5rem);
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

/* Month filter */
.archive-month-form {
  width: 100%;
  max-width: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.archive-month-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.archive-month-wrap {
  position: relative;
  width: 100%;
}

.archive-month-select {
  width: 100%;
  padding: 9px 36px 9px 14px;
  font-size: 0.9375rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 500;
  color: var(--text-primary);
  background-color: var(--bg-page);
  border: 1.5px solid var(--border-default);
  border-radius: 8px;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  outline: none;
}

.archive-month-select:focus {
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 3px var(--focus-glow);
}

.archive-month-select:hover {
  border-color: var(--border-hover);
}

.archive-month-arrow {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

/* Calendar table */
.archive-calendar-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.archive-calendar {
  border-collapse: separate;
  border-spacing: 5px;
  margin: 0 auto;
}

.archive-calendar thead tr {
  display: table-row;
}

.archive-weekday {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  padding: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.archive-cell-wrap {
  padding: 0;
  text-align: center;
  vertical-align: top;
}

/* Archive cell — matches puzzle grid cell aesthetic */
.archive-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  width: clamp(36px, 10vw, 58px);
  height: clamp(36px, 10vw, 58px);
  padding: 4px 2px;
  border: 3px solid var(--cell-border);
  border-radius: 12px;
  text-decoration: none;
  box-shadow: var(--shadow-md);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.archive-cell:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.archive-cell:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

/* Difficulty colors — matching the main puzzle grid cell palette */
.archive-cell--easy {
  background-color: var(--cell-green);
}

.archive-cell--medium {
  background-color: var(--cell-yellow);
}

.archive-cell--hard {
  background-color: var(--cell-coral);
}

/* Unscheduled / empty date */
.archive-cell--empty {
  background-color: var(--cell-hint-bg);
  border-color: var(--border-default);
  box-shadow: none;
  pointer-events: none;
  opacity: 0.45;
}

/* Star icon */
.archive-star {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 18px;
}

.archive-star-icon {
  display: block;
}

.archive-star-icon--filled {
  color: var(--text-primary);
}

.archive-star-icon--outlined {
  color: var(--text-primary);
  opacity: 0.35;
}

/* Day number */
.archive-day {
  font-size: clamp(0.6875rem, 2vw, 0.8125rem);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1;
  text-align: center;
}

.archive-cell--empty .archive-day {
  color: var(--text-muted);
}

/* Dark mode overrides */
@media (prefers-color-scheme: dark) {
  .archive-star-icon--outlined {
    opacity: 0.3;
  }

  .archive-cell--empty {
    opacity: 0.35;
  }

  .archive-cell:hover {
    box-shadow: 0 0 0 1px var(--dark-cell-border);
  }
}

@media (min-width: 768px) {
  .archive-calendar {
    border-spacing: 6px;
  }

  .archive-cell {
    width: 60px;
    height: 60px;
  }
}
