/* ========================================
   MODAL OVERLAY
   ======================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeOverlay 0.25s ease;
}

@keyframes fadeOverlay {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ===== Modal Container ===== */
.modal {
  background: var(--surface);
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.15);
  animation: modalSlideUp 0.3s ease;
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ===== Modal Header ===== */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
}

.btn-modal-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.btn-modal-close:hover {
  background: var(--highlight-row);
  color: var(--text);
}

.btn-modal-close svg {
  width: 20px;
  height: 20px;
}

/* ===== Modal Body ===== */
.modal-body {
  padding: 24px;
}

/* ===== Modal Footer ===== */
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ========================================
   TUTORIAL MODAL
   ======================================== */
.modal-tutorial {
  max-width: 540px;
}

.tutorial-carousel {
  position: relative;
  min-height: 280px;
  max-height: 65vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px;
}

.tut-demo {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 10px 0 16px;
  min-height: 140px;
}

.tut-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  text-align: center;
}

.tutorial-step {
  display: none;
  animation: fadeIn 0.4s ease;
}

.tutorial-step.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tutorial-step h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

.tutorial-step p {
  color: var(--text-secondary);
  line-height: 1.6;
  font-size: 0.95rem;
}

/* ===== Tutorial Demo Grids ===== */
.tut-grid {
  display: inline-grid;
  gap: 2px;
  margin: 16px auto;
  background: var(--border);
  border: 2px solid var(--text);
  border-radius: 4px;
}

.tut-grid.grid-9 {
  grid-template-columns: repeat(9, 36px);
  grid-template-rows: 36px;
}

.tut-grid.grid-3x3 {
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 44px);
}

.tut-grid.grid-5x5 {
  grid-template-columns: repeat(5, 36px);
  grid-template-rows: repeat(5, 36px);
}

.tut-cell {
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  transition: all 0.3s ease;
}

.tut-cell.highlight {
  background: var(--highlight-num);
  animation: highlightPulse 1.5s ease-in-out infinite;
}

.tut-cell.fill-anim {
  animation: fillIn 0.5s ease-out forwards;
}

@keyframes fillIn {
  from {
    transform: scale(0);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes highlightPulse {
  0%, 100% {
    background: var(--highlight-row);
  }
  50% {
    background: var(--highlight-num);
  }
}

.tut-cell.notes-demo {
  font-size: 0.6rem;
  color: var(--text-secondary);
}

/* ===== Tutorial Dots & Buttons ===== */
.tutorial-dots {
  display: flex;
  gap: 8px;
}

.tutorial-dots .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: all 0.3s ease;
  border: none;
  padding: 0;
  cursor: pointer;
}

.tutorial-dots .dot.active {
  background: var(--primary);
  width: 20px;
  border-radius: 4px;
}

.tutorial-btns {
  display: flex;
  gap: 8px;
}

/* ========================================
   DIFFICULTY MODAL
   ======================================== */
.difficulty-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.diff-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.25s ease;
  text-align: center;
}

.diff-card:hover {
  border-color: var(--primary);
  background: var(--primary-bg);
  transform: translateY(-2px);
}

.diff-card:active {
  transform: scale(0.97);
}

.diff-card h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.diff-card p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.4;
}

.diff-card small {
  color: var(--text-secondary);
  font-size: 0.8rem;
  opacity: 0.7;
}

.diff-stars {
  font-size: 1.5rem;
  line-height: 1;
}

/* ========================================
   GAME OVER & SCORE BREAKDOWN MODAL
   ======================================== */
.modal-gameover {
  max-width: 440px;
  width: 92%;
  text-align: center;
}

.modal-gameover .modal-body {
  padding: 28px 22px;
}

.gameover-icon {
  font-size: 3.5rem;
  margin-bottom: 6px;
  line-height: 1;
}

.gameover-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text);
}

.gameover-subtitle {
  color: var(--text-secondary);
  margin-bottom: 16px;
  font-size: 0.88rem;
  line-height: 1.4;
}

/* Big Final Score Banner */
.gameover-final-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.08), rgba(99, 102, 241, 0.12));
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
}

.final-score-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--primary);
  text-transform: uppercase;
}

.final-score-val {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.1;
  margin-top: 2px;
}

/* Detailed Score Breakdown Card */
.score-breakdown-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
  text-align: left;
}

.breakdown-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border);
}

.breakdown-title svg {
  color: var(--primary);
  flex-shrink: 0;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 0.84rem;
}

.breakdown-row .row-label {
  color: var(--text-secondary);
}

.breakdown-row .row-val {
  font-weight: 600;
  color: var(--text);
}

.breakdown-row .highlight-combo {
  color: #EA580C;
  font-weight: 700;
}

.breakdown-row .highlight-time {
  color: #059669;
  font-weight: 700;
}

.breakdown-row .highlight-perfect {
  color: #059669;
  font-weight: 700;
}

.breakdown-row .highlight-penalty {
  color: #DC2626;
  font-weight: 700;
}

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

.breakdown-row.breakdown-total {
  font-size: 0.95rem;
  font-weight: 700;
  padding-top: 4px;
}

.breakdown-row.breakdown-total .row-label {
  color: var(--text);
}

.breakdown-row.breakdown-total .total-number {
  color: var(--primary);
  font-size: 1.18rem;
}

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

/* Win state */
.modal-gameover.win .gameover-title {
  color: var(--success);
}

/* Lose state */
.modal-gameover.lose .gameover-title {
  color: var(--error);
}

/* Give-up state */
.modal-gameover.give-up .gameover-title {
  color: #D97706;
}

/* ========================================
   CONFIRM MODAL
   ======================================== */
.modal-confirm {
  max-width: 360px;
  text-align: center;
}

.modal-confirm .modal-body {
  padding: 32px 24px;
}

.confirm-icon {
  margin-bottom: 8px;
  font-size: 3rem;
  line-height: 1;
}

.confirm-icon svg {
  width: 48px;
  height: 48px;
  margin: 0 auto;
  color: var(--warning);
}

.confirm-footer {
  justify-content: center;
  gap: 12px;
}

/* ========================================
   TOAST NOTIFICATIONS
   ======================================== */
.toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  animation: toastIn 0.4s ease;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translate(-50%, -20px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.toast.hiding {
  animation: toastOut 0.3s ease forwards;
}

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translate(-50%, -20px);
  }
}

.toast-content {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  background: var(--surface);
  border-radius: 50px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.toast-icon {
  color: var(--primary);
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.toast-icon svg {
  width: 20px;
  height: 20px;
}

.toast-icon.success {
  color: var(--success);
}

.toast-icon.error {
  color: var(--error);
}

.toast-icon.warning {
  color: var(--warning);
}


/* ========================================
   SETTINGS MODAL
   ======================================== */
.modal-settings {
  max-width: 520px;
  width: 95%;
  border-radius: var(--radius);
  overflow: hidden;
}

.modal-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-header-title svg {
  color: var(--primary);
  flex-shrink: 0;
}

.modal-header-title h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
}

.settings-body {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 75vh;
  overflow-y: auto;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.settings-group-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 0;
}

.setting-row:not(:last-child) {
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}

.setting-row-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.setting-row-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
}

.setting-row-desc {
  font-size: 0.76rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

/* ===== Segmented Control (Pill Switcher) ===== */
.segmented-control {
  display: inline-flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 3px;
  gap: 3px;
  flex-shrink: 0;
}

.seg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 50px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  white-space: nowrap;
}

.seg-btn:hover {
  color: var(--text);
}

.seg-btn.active {
  background: var(--primary);
  color: #FFFFFF;
  box-shadow: 0 2px 6px rgba(59, 130, 246, 0.35);
}

.seg-btn svg {
  width: 14px;
  height: 14px;
}

/* ===== Modern Toggle Switch ===== */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--border);
  border-radius: 50px;
  transition: all 0.25s ease;
  border: 1px solid var(--border);
}

.toggle-slider::before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 2px;
  bottom: 2px;
  background-color: #FFFFFF;
  border-radius: 50%;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--primary);
  border-color: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* ===== Danger Zone in Settings ===== */
.settings-danger-group {
  background: rgba(239, 68, 68, 0.05);
  border-color: rgba(239, 68, 68, 0.2);
  padding: 10px 16px;
}

[data-theme="dark"] .settings-danger-group {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.3);
}

.danger-title {
  color: var(--error);
}

.danger-text {
  color: var(--error);
}

.danger-row {
  border-bottom: none !important;
}

.setting-row .btn-small {
  flex-shrink: 0;
  white-space: nowrap;
}

#modal-confirm {
  z-index: 1100;
}

/* ===== Revive & Buy Hint Modals ===== */
.modal-revive,
.modal-buy-hint {
  max-width: 440px;
  text-align: center;
}

.revive-icon,
.buy-hint-icon {
  font-size: 2.8rem;
  line-height: 1;
  margin-bottom: 8px;
  animation: modalScaleIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.revive-desc,
.buy-hint-desc {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 16px;
}

.revive-cost-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 14px;
  text-align: left;
}

.revive-cost-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  font-size: 0.88rem;
}

.revive-cost-row .cost-label {
  color: var(--text-secondary);
  font-weight: 500;
}

.revive-cost-row .cost-value {
  font-weight: 700;
  color: var(--text-primary);
  font-size: 0.95rem;
}

.revive-cost-row .highlight-cost {
  color: var(--error);
}

.revive-cost-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

.revive-insufficient-notice {
  background: #FEF2F2;
  border: 1px solid #FECACA;
  color: #DC2626;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  text-align: left;
  line-height: 1.4;
}

[data-theme="dark"] .revive-insufficient-notice {
  background: rgba(220, 38, 38, 0.15);
  border-color: rgba(220, 38, 38, 0.35);
  color: #F87171;
}

.revive-info-note {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-align: left;
  line-height: 1.4;
}

.revive-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding-top: 12px;
}
