.avatar-menu {
  position: absolute;
  right: 16px;
  display: flex;
  align-items: center;
}

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

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

.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;
}

.avatar-icon {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
}

.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;
  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-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;
}

.puzzle-grid {
  border-collapse: collapse;
  margin: 0 auto;
}

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

.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 {
  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;
}

.puzzle-grid.solved .cell {
  cursor: default;
  pointer-events: none;
}

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

.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;
  }
}

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

@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 {
  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;
}

.solve-complete {
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  margin: 0 0 4px;
  opacity: 0.6;
}

.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-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;
}

.solve-divider {
  width: 48px;
  height: 1px;
  background-color: rgba(255, 255, 255, 0.2);
  margin: 20px 0 16px;
  flex-shrink: 0;
}

.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-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-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 {
  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;
}

@media (max-width: 400px) {
  .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;
  }
}

/* ============================================================
   iOS Install Modal
   Bottom-sheet instructions for Safari "Add to Home Screen".
   Shown only on iOS devices where beforeinstallprompt is not
   supported.
   ============================================================ */

.ios-install-modal {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
}

.ios-install-modal[hidden] {
  display: none;
}

.ios-install-modal-box {
  position: relative;
  background-color: var(--bg-page);
  border-radius: 16px 16px 0 0;
  padding: 28px 24px calc(32px + env(safe-area-inset-bottom, 0px));
  width: 100%;
  max-width: 480px;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
}

.ios-install-modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: var(--bg-surface);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: background-color 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}

.ios-install-modal-close:hover {
  background-color: var(--hover-surface);
}

.ios-install-modal-close:focus-visible {
  outline: 2.5px solid var(--focus-ring);
  outline-offset: 2px;
}

.ios-install-modal-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  margin: 0 40px 20px 0;
}

.ios-install-steps {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ios-install-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 0.9375rem;
  color: var(--text-secondary);
  line-height: 1.5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.ios-step-num {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: 2px;
}

.ios-install-step strong {
  color: var(--text-primary);
  font-weight: 600;
}

.ios-share-icon {
  display: inline-block;
  vertical-align: middle;
  color: var(--primary);
  margin: 0 1px;
  position: relative;
  top: -1px;
}
