:root {
  --bg: #07111f;
  --panel: #0f172a;
  --line: rgba(148, 163, 184, 0.22);
  --line-strong: rgba(148, 163, 184, 0.5);
  --text: #e8edf5;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-text: #93c5fd;
  --given: #cbd5e1;
  --danger: #ef4444;
  --gold: #fbbf24;
}

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

html, body {
  min-height: 100%;
  background: radial-gradient(ellipse at 50% 0%, #15233a 0%, var(--bg) 70%);
  color: var(--text);
  font-family: "Vazirmatn", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body { min-height: 100vh; min-height: 100dvh; }

.s-wrap {
  max-width: 540px;
  margin: 0 auto;
  padding: 14px 10px 26px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.s-mast {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.s-mast h1 { font-size: clamp(1.25rem, 5vw, 1.6rem); font-weight: 800; }
.s-mast p { color: var(--muted); font-size: 0.74rem; margin-top: 2px; }

.s-stats { display: flex; gap: 10px; }
.s-stat {
  min-width: 60px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 5px 10px;
}
.s-stat .l { color: var(--muted); font-size: 0.66rem; }
.s-stat .v { font-size: 1rem; font-weight: 800; color: var(--accent-text); }

.s-diff { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.s-diff button {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 14px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.s-diff button:hover { border-color: var(--accent); color: var(--accent-text); }
.s-diff button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.s-diff .s-new { margin-inline-start: auto; color: var(--text); }
.s-diff .s-new:hover { color: var(--accent-text); }

.s-frame { position: relative; }

.s-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  background: var(--panel);
  border: 2px solid var(--line-strong);
  border-radius: 12px;
  overflow: hidden;
}

.s-cell {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-left: 1px solid var(--line);
  border-top: 1px solid var(--line);
  font-size: clamp(0.95rem, 4.4vw, 1.35rem);
  font-weight: 700;
  cursor: pointer;
  position: relative;
}
.s-cell:nth-child(9n) { border-left: none; }
.s-cell:nth-child(3n) { border-left: 1px solid var(--line-strong); }
.s-cell:nth-child(9n):nth-child(3n) { border-left: none; }
.s-cell:nth-child(-n+9) { border-top: none; }
.s-cell.c3 { border-left: 1px solid var(--line-strong); }
.s-cell.r3 { border-top: 1px solid var(--line-strong); }
.s-cell:nth-child(9n).c3 { border-left: none; }

.s-cell.given { color: var(--given); }
.s-cell.user { color: var(--accent-text); }
.s-cell.error { color: #f87171; background: rgba(239, 68, 68, 0.10); }
.s-cell.sel { background: rgba(59, 130, 246, 0.16); box-shadow: inset 0 0 0 2px var(--accent); }
.s-cell.peer { background: rgba(59, 130, 246, 0.06); }
.s-cell.same { color: var(--gold); }

.s-notes {
  position: absolute;
  inset: 2px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  font-size: clamp(0.42rem, 1.9vw, 0.58rem);
  font-weight: 600;
  color: var(--muted);
  line-height: 1;
}
.s-notes span { display: flex; align-items: center; justify-content: center; }

.s-pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.s-pad button {
  font-family: inherit;
  font-size: clamp(0.9rem, 4vw, 1.2rem);
  font-weight: 800;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 0;
  cursor: pointer;
  transition: all 0.12s ease;
}
.s-pad button:hover { border-color: var(--accent); color: var(--accent-text); }
.s-pad button.done { opacity: 0.35; }

.s-tools { display: flex; gap: 8px; justify-content: center; }
.st {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 18px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.st:hover { border-color: var(--accent); color: var(--accent-text); }
.st.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.st.on { background: var(--accent-soft, rgba(59, 130, 246, 0.18)); border-color: var(--accent); color: var(--accent-text); }

.s-overlay {
  position: fixed;
  inset: 0;
  background: rgba(7, 17, 31, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}
.s-overlay[hidden] { display: none !important; }
.s-over-card {
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 26px 34px;
}
.s-over-card h2 { color: var(--gold); font-size: 1.25rem; font-weight: 800; margin-bottom: 6px; }
.s-over-card p { color: var(--muted); font-size: 0.85rem; margin-bottom: 14px; }
