:root {
  --paper: #faf7f0;
  --paper-line: #e4ddc9;
  --ink: #23262b;
  --ink-soft: #6b6f76;
  --blue: #1f3a5f;
  --blue-soft: #4a6fa5;
  --error: #a33a2d;
  --error-bg: #fbe9e6;
  --fixed-bg: #eee9db;
  --diamond: #1f8a8c;
  --deducible: #c9962c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(var(--paper-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--paper-line) 1px, transparent 1px);
  background-size: 24px 24px;
  background-color: var(--paper);
  font-family: "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  padding: 24px;
}

.hidden {
  display: none !important;
}

.screen {
  width: 100%;
  max-width: 420px;
}

.app {
  width: 100%;
  text-align: center;
}

/* ===================== صفحه‌ی شروع ===================== */

@keyframes splash-in {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes icon-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

.start-screen,
#start-screen {
  display: flex;
  justify-content: center;
}

.start-card {
  width: 100%;
  text-align: center;
  animation: splash-in 0.6s ease both;
}

.start-icon {
  width: 84px;
  height: 84px;
  border-radius: 16px;
  animation: icon-pulse 2.4s ease-in-out infinite;
}

.start-title {
  margin: 14px 0 2px;
  font-size: 30px;
  font-weight: 500;
  color: var(--blue);
  letter-spacing: 1px;
}

.start-meta {
  margin: 2px 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.music-btn {
  margin: 14px 0;
  font-size: 16px;
  background: none;
  border: 1px solid var(--blue-soft);
  border-radius: 50%;
  width: 34px;
  height: 34px;
  cursor: pointer;
  color: var(--blue-soft);
  line-height: 1;
}

.music-btn:active {
  background: #e4edf7;
}

.custom-music-row {
  margin-bottom: 16px;
  text-align: center;
}

.pick-music-btn {
  font-family: inherit;
  font-size: 13px;
  color: var(--blue-soft);
  background: #ffffff;
  border: 1px solid var(--blue-soft);
  border-radius: 20px;
  padding: 7px 16px;
  cursor: pointer;
}

.pick-music-btn:active {
  background: #e4edf7;
}

.music-file-name {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--ink-soft);
}

.start-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.start-btn {
  padding: 13px 0;
  font-size: 16px;
  font-family: inherit;
  color: #ffffff;
  background: var(--blue-soft);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.start-btn:hover {
  background: var(--blue);
}

.start-btn.primary {
  background: var(--blue);
  font-weight: 500;
}

.start-btn.primary:hover {
  background: #16304d;
}

.start-btn.ghost {
  background: transparent;
  color: var(--blue);
  border: 1px solid var(--blue-soft);
}

.start-btn.ghost:hover {
  background: #e4edf7;
}

.start-btn:disabled {
  background: var(--fixed-bg);
  color: var(--ink-soft);
  cursor: not-allowed;
}

/* ===================== صفحه‌ی راهنما ===================== */

.help-app {
  text-align: right;
}

.celebration-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 200;
}

.celebration-piece {
  position: absolute;
  bottom: -40px;
  opacity: 0;
  animation: celebration-rise 2.4s ease-out forwards;
}

@keyframes celebration-rise {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 0;
  }
  12% {
    opacity: 1;
  }
  100% {
    transform: translateY(-100vh) rotate(360deg);
    opacity: 0;
  }
}

.milestone-toast {
  position: fixed;
  top: 18%;
  left: 50%;
  transform: translateX(-50%) scale(0.85);
  background: var(--blue);
  color: #ffffff;
  padding: 12px 22px;
  border-radius: 30px;
  font-size: 15px;
  font-weight: 500;
  z-index: 201;
  opacity: 0;
  text-align: center;
  max-width: 85%;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.milestone-toast.show {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

.stats-table {
  margin-top: 14px;
  border: 1px solid var(--blue-soft);
  border-radius: 8px;
  overflow: hidden;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 9px 10px;
  text-align: center;
  font-size: 14px;
  border-bottom: 1px solid var(--paper-line);
}

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

.stats-row.stats-header {
  background: var(--blue);
  color: #ffffff;
  font-weight: 500;
  border-bottom: none;
}

.help-title {
  text-align: center;
  color: var(--blue);
  margin: 0 0 16px;
}

.help-content {
  background: #ffffff;
  border: 1px solid var(--paper-line);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 18px;
}

.help-content p {
  font-size: 14px;
  line-height: 2;
  margin: 0 0 10px;
  color: var(--ink);
}

.help-content p:last-child {
  margin-bottom: 0;
}

/* ===================== صفحه‌ی بازی ===================== */

.game-topbar {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 6px;
}

.home-btn {
  font-size: 18px;
  background: none;
  border: 1px solid var(--blue-soft);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  cursor: pointer;
  color: var(--blue-soft);
  line-height: 1;
}

.home-btn:active {
  background: #e4edf7;
}

.game-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-bottom: 10px;
}

.timer {
  font-family: "Consolas", "Courier New", monospace;
  font-size: 22px;
  color: var(--blue);
  letter-spacing: 2px;
  transition: color 0.2s ease;
}

.timer.overtime {
  color: var(--error);
}

.status-label {
  margin: 0;
  font-size: 13px;
  color: var(--blue-soft);
}

.status-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 16px;
}

.diamonds-display {
  font-family: inherit;
  font-size: 15px;
  color: var(--diamond);
  background: #eefaf9;
  border: 1px solid var(--diamond);
  border-radius: 20px;
  padding: 6px 16px;
  cursor: pointer;
}

.diamonds-display:active {
  background: var(--diamond);
  color: #ffffff;
}

.hint-feedback {
  min-height: 18px;
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--error);
}

/* ===================== انتخاب سطح سختی ===================== */

.difficulty {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}

.diff-btn {
  padding: 6px 18px;
  font-size: 14px;
  font-family: inherit;
  color: var(--blue);
  background: #ffffff;
  border: 1px solid var(--blue-soft);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.diff-btn:hover {
  background: #e4edf7;
}

.diff-btn.active {
  background: var(--blue);
  color: #ffffff;
}

/* ===================== جدول بازی ===================== */

.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--blue);
  border: 3px solid var(--blue);
  border-radius: 4px;
  overflow: hidden;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  box-sizing: border-box;
  background: #ffffff;
  border: 0.5px solid #cfd3da;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 20px;
  color: var(--blue);
  text-align: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.cell.fixed {
  cursor: default;
  background: var(--fixed-bg);
  color: var(--ink);
  font-weight: 500;
}

/* Thicker borders around each 3x3 block */
.cell[data-col="0"] { border-right-width: 2.5px; border-right-color: var(--blue); }
.cell[data-col="2"], .cell[data-col="5"] { border-left-width: 2.5px; border-left-color: var(--blue); }
.cell[data-col="8"] { border-left-width: 2.5px; border-left-color: var(--blue); }
.cell[data-row="0"] { border-top-width: 2.5px; border-top-color: var(--blue); }
.cell[data-row="2"], .cell[data-row="5"] { border-bottom-width: 2.5px; border-bottom-color: var(--blue); }
.cell[data-row="8"] { border-bottom-width: 2.5px; border-bottom-color: var(--blue); }

.cell.error {
  background: var(--error-bg);
  color: var(--error);
}

.cell.same-number {
  box-shadow: inset 0 0 0 2px var(--diamond);
}

.cell.selected {
  background: #d7e6f7;
  box-shadow: inset 0 0 0 2px var(--blue-soft);
}

.cell.hint,
.cell.auto-fill {
  background: #e4edf7;
  color: var(--blue-soft);
  font-weight: 500;
}

@keyframes deducible-pulse {
  0%, 100% {
    box-shadow: inset 0 0 0 2px var(--deducible);
  }
  50% {
    box-shadow: inset 0 0 0 4px var(--deducible);
  }
}

.cell.deducible {
  animation: deducible-pulse 1.2s ease-in-out infinite;
}

@keyframes unit-pop {
  0% {
    transform: translateY(-16px) scale(1.3) rotate(-6deg);
  }
  55% {
    transform: translateY(2px) scale(1.28) rotate(6deg);
  }
  100% {
    transform: translateY(0) scale(1) rotate(0deg);
  }
}

.cell.unit-complete {
  animation: unit-pop 1s cubic-bezier(0.22, 1, 0.36, 1);
  position: relative;
  z-index: 5;
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
}

.note {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-family: "Consolas", "Courier New", monospace;
  color: var(--ink-soft);
}

.mode-row {
  display: flex;
  justify-content: center;
  margin-top: 14px;
}

.note-toggle-btn {
  padding: 8px 20px;
  font-size: 14px;
  font-family: inherit;
  color: var(--diamond);
  background: #ffffff;
  border: 1px solid var(--diamond);
  border-radius: 20px;
  cursor: pointer;
}

.note-toggle-btn.active {
  background: var(--diamond);
  color: #ffffff;
}

/* ===================== صفحه‌کلید ===================== */

.cell-value {
  font-size: inherit;
}

.keypad {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.keypad-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.key {
  padding: 14px 0;
  font-size: 18px;
  font-family: "Consolas", "Courier New", monospace;
  color: var(--blue);
  background: #ffffff;
  border: 1px solid var(--blue-soft);
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  transition: background 0.15s ease;
}

.key:hover {
  background: #e4edf7;
}

.key:active {
  background: var(--blue-soft);
  color: #ffffff;
}

.key.clear {
  font-family: inherit;
  font-size: 13px;
  color: var(--error);
  border-color: var(--error);
}

.key.clear:active {
  background: var(--error);
  color: #ffffff;
}

.key.completed {
  opacity: 0.35;
  cursor: not-allowed;
  background: var(--fixed-bg);
  color: var(--ink-soft);
  border-color: var(--ink-soft);
}

.key.completed:hover,
.key.completed:active {
  background: var(--fixed-bg);
  color: var(--ink-soft);
}

.hint-btn {
  margin-top: 18px;
  padding: 10px 28px;
  font-size: 15px;
  font-family: inherit;
  color: var(--paper);
  background: var(--blue);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.hint-btn:hover {
  background: var(--blue-soft);
}

.hint-btn:disabled {
  background: var(--ink-soft);
  cursor: not-allowed;
}

/* ===================== پنجره‌ی فیلم تبلیغاتی ===================== */

.ad-overlay {
  position: fixed;
  inset: 0;
  background: rgba(35, 38, 43, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}

.ad-box {
  width: 100%;
  max-width: 360px;
  background: var(--paper);
  border: 2px solid var(--blue);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
}

.ad-text {
  margin: 0 0 18px;
  font-size: 15px;
  line-height: 1.7;
  color: var(--ink);
}

.ad-video {
  width: 100%;
  border-radius: 6px;
  margin-bottom: 16px;
  background: #000;
}

.ad-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.ad-btn {
  padding: 10px 20px;
  font-size: 14px;
  font-family: inherit;
  border-radius: 6px;
  cursor: pointer;
  border: none;
}

.ad-btn.watch {
  background: var(--blue);
  color: #ffffff;
}

.ad-btn.watch:hover {
  background: var(--blue-soft);
}

.ad-btn.cancel {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--ink-soft);
}

.message {
  min-height: 24px;
  margin-top: 20px;
  font-size: 15px;
  color: var(--blue-soft);
}

.message.success {
  color: #1e7a4c;
  font-weight: 500;
}
