@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/Vazirmatn-Regular.woff2") format("woff2"),
       url("fonts/Vazir-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/Vazirmatn-Bold.woff2") format("woff2"),
       url("fonts/Vazir-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #ffffff;
  --text: #222222;
  --blue: #174f9b;
  --blue-hover: #b13b25;
  --border: #d5d5d5;
  --border-light: #eeeeee;
  --muted: #777777;
  --dim: #999999;
  --green: #287a42;
  --red: #a33b32;
  --card-bg: #fafafa;
  --hover-bg: #f3f3f3;
  --active-tab-bg: #eaf1fa;
  --btn-bg: #eeeeee;
  --btn-border: #999999;
  --popover-bg: #ffffff;
  --popover-border: #999999;
}

[data-theme="dark"] {
  --bg: #141414;
  --text: #dfdfdf;
  --blue: #6fa0e2;
  --blue-hover: #e07060;
  --border: #333333;
  --border-light: #252525;
  --muted: #888888;
  --dim: #666666;
  --green: #48a868;
  --red: #c45850;
  --card-bg: #191919;
  --hover-bg: #232323;
  --active-tab-bg: #1e2838;
  --btn-bg: #222222;
  --btn-border: #444444;
  --popover-bg: #1a1a1a;
  --popover-border: #555555;
}

* {
  box-sizing: border-box;
  border-radius: 0 !important;
}

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Vazirmatn", "Vazir", sans-serif !important;
  font-size: 13px;
  line-height: 1.9;
  -webkit-font-smoothing: antialiased;
  transition: background-color 100ms, color 100ms;
}

body, button, input, select, textarea, .logo, h1, h2, h3, h4, .subtitle, nav a, .opt, .feedback, .stats-table, th, td, caption {
  font-family: "Vazirmatn", "Vazir", sans-serif !important;
}

a {
  color: var(--blue);
  text-decoration: underline;
  cursor: pointer;
}

a:hover {
  color: var(--blue-hover);
}

button, input {
  font-size: inherit;
  color: inherit;
}

.page-container {
  width: min(780px, calc(100% - 32px));
  margin: 28px auto 60px;
}

header {
  border-bottom: 1px solid #aaa;
  padding-bottom: 14px;
  margin-bottom: 24px;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-logo-img {
  height: 90px;
  width: auto;
  object-fit: contain;
  border: none !important;
  display: block;
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.logo {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  line-height: 1.3;
}

.subtitle {
  color: var(--muted);
  font-size: 12px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-btn {
  background: none;
  border: 1px solid var(--border);
  padding: 5px 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  line-height: 1;
}

.theme-btn:hover {
  background: var(--hover-bg);
  border-color: var(--blue);
}

.social-links {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
}

.social-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  text-decoration: none;
  padding: 3px 6px;
  border: 1px solid transparent;
}

.social-link:hover {
  color: var(--blue);
  border-color: var(--border);
  background: var(--hover-bg);
  text-decoration: none;
}

.social-link svg {
  vertical-align: middle;
}

nav {
  margin-top: 14px;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

nav a {
  font-size: 13px;
  color: var(--blue);
  text-decoration: none;
  padding-bottom: 2px;
  border-bottom: 1px dotted transparent;
}

nav a:hover {
  color: var(--blue-hover);
  border-bottom-color: var(--blue-hover);
}

nav a[aria-current="page"] {
  color: var(--text);
  font-weight: 700;
  border-bottom: 2px solid var(--text);
}

.notice {
  min-height: 20px;
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--blue);
}

h2 {
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 12px;
  color: var(--text);
}

h2::before {
  content: "// ";
  color: var(--dim);
}

section {
  margin-bottom: 28px;
}

.modes-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 18px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.mode-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-label {
  font-size: 12px;
  color: var(--muted);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tabs button {
  background: none;
  border: 1px solid #bbb;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text);
  transition: background 100ms;
}

.tabs button:hover {
  background: var(--hover-bg);
}

.tabs button[aria-pressed="true"] {
  background: var(--active-tab-bg);
  border-color: var(--blue);
  color: var(--blue);
  font-weight: 700;
}

.exercise-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  margin: 14px 0 6px;
}

.problem-area {
  position: relative;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border-top: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
  padding: 26px 12px 22px;
  background: var(--card-bg);
}

.problem-tools {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool-btn,
.hint-bubble-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid #bbb;
  color: var(--text);
  padding: 5px 6px;
  min-width: 28px;
  min-height: 28px;
  cursor: pointer;
  transition: all 100ms;
}

.tool-btn:hover,
.hint-bubble-btn:hover {
  background: var(--hover-bg);
  border-color: var(--blue);
  color: var(--blue);
}

.tool-btn[aria-pressed="true"] {
  background: rgba(198, 40, 40, 0.1);
  border-color: #c62828;
  color: #c62828;
  font-weight: 700;
}

[data-theme="dark"] .tool-btn[aria-pressed="true"] {
  background: rgba(239, 83, 80, 0.18);
  border-color: #ef5350;
  color: #ef5350;
}

.draw-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
  touch-action: none;
}

.draw-canvas.active {
  pointer-events: auto;
  cursor: crosshair;
}

.hint-popover {
  position: absolute;
  top: 42px;
  right: 10px;
  width: 310px;
  max-width: calc(100vw - 40px);
  background: var(--popover-bg);
  border: 1px solid var(--popover-border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.7;
  z-index: 35;
  direction: rtl;
  text-align: right;
}

.hint-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 4px;
  margin-bottom: 6px;
}

.hint-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hint-popover-title {
  font-weight: 700;
  color: var(--blue);
  font-size: 12px;
}

.hint-popover-close {
  background: none;
  border: 1px solid var(--border);
  color: var(--dim);
  cursor: pointer;
  padding: 2px 4px;
  display: inline-flex;
  align-items: center;
}

.hint-popover-close:hover {
  color: var(--text);
  border-color: var(--blue);
}

.hint-popover-text {
  margin: 6px 0;
  color: var(--text);
}

.hint-popover-formula {
  direction: ltr;
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--border-light);
  font-size: 14px;
  text-align: center;
  overflow-x: auto;
  color: var(--text);
}

.prompt {
  position: relative;
  z-index: 5;
  direction: ltr;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  line-height: 1.35;
  text-align: center;
  color: var(--text);
  margin-bottom: 18px;
  overflow-x: auto;
  max-width: 100%;
}

.prompt .katex {
  font-size: 1.1em;
}

.options-wrap {
  position: relative;
  z-index: 15;
  width: 100%;
  max-width: 460px;
}

.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}

.opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid #bbb;
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
  min-height: 44px;
  text-align: start;
  transition: background 100ms;
}

.opt .k {
  font-size: 11px;
  color: var(--dim);
}

.opt .v {
  direction: ltr;
  font-weight: normal;
  flex-grow: 1;
  text-align: center;
}

.opt:hover:not(:disabled) {
  background: var(--hover-bg);
  border-color: var(--blue);
}

.opt:disabled {
  cursor: default;
}

.opt.right {
  background: rgba(40, 122, 66, 0.12);
  border-color: var(--green);
  color: var(--green);
  font-weight: 700;
}

.opt.right .k {
  color: var(--green);
}

.opt.wrong {
  background: rgba(163, 59, 50, 0.12);
  border-color: var(--red);
  color: var(--red);
}

.opt.wrong .k {
  color: var(--red);
}

.feedback-area {
  position: relative;
  z-index: 15;
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.feedback {
  min-height: 24px;
  font-size: 12.5px;
  text-align: center;
}

.feedback.ok {
  color: var(--green);
  font-weight: 700;
}

.feedback:not(.ok):not(:empty) {
  color: var(--red);
}

.feedback .katex {
  direction: ltr;
}

.next-action {
  display: flex;
  align-items: center;
  gap: 12px;
}

.primary-btn {
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  padding: 7px 18px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text);
}

.primary-btn:hover {
  background: #e2e2e2;
}

[data-theme="dark"] .primary-btn:hover {
  background: #2a2a2a;
}

.key-hint {
  font-size: 11px;
  color: var(--dim);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
  margin-top: 8px;
}

.stats-table td {
  border-bottom: 1px solid var(--border-light);
  padding: 8px 6px;
}

.stats-table td:nth-child(odd) {
  color: var(--muted);
  width: 22%;
}

.stats-table td:nth-child(even) {
  direction: ltr;
  text-align: left;
  font-size: 15px;
  font-weight: 700;
  width: 28%;
}

.chart-box {
  margin: 16px 0;
  padding: 12px 0;
  border-top: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
}

.chart-title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.chart {
  direction: ltr;
}

.chart svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart .axis {
  stroke: var(--border);
  stroke-dasharray: 2 3;
}

.chart .line {
  fill: none;
  stroke: var(--blue);
  stroke-width: 1.5;
}

.chart .dot {
  fill: var(--blue);
}

.chart text {
  fill: var(--dim);
  font-size: 11px;
}

.stats-simple-tables {
  margin-top: 16px;
}

.table-wrap {
  margin-top: 12px;
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

table.data-table caption {
  caption-side: top;
  text-align: right;
  font-weight: 700;
  font-size: 12.5px;
  color: var(--text);
  margin-bottom: 6px;
}

table.data-table th {
  border-bottom: 1px solid #aaa;
  color: var(--muted);
  padding: 6px 8px;
  text-align: right;
  font-weight: normal;
}

table.data-table td {
  border-bottom: 1px solid var(--border-light);
  padding: 6px 8px;
  white-space: nowrap;
}

.stats-cards-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 16px 0;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  padding: 12px 10px;
  text-align: center;
}

.stat-card-title {
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 4px;
}

.stat-card-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--blue);
  line-height: 1.25;
}

.stat-card-sub {
  font-size: 10.5px;
  color: var(--dim);
  margin-top: 4px;
}

.techniques-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}

.tip-row {
  border-bottom: 1px solid var(--border-light);
  padding: 10px 0;
}

.tip-title {
  font-weight: 700;
  font-size: 13.5px;
  color: var(--text);
  margin-bottom: 3px;
}

.tip-desc {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.tip-math {
  direction: ltr;
  text-align: left;
  padding: 6px 10px;
  background: var(--card-bg);
  border: 1px solid var(--border-light);
  overflow-x: auto;
}

.about-layout {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-top: 14px;
}

.about-content {
  flex: 1;
  line-height: 2;
  color: var(--text);
}

.about-meta-info {
  margin-top: 16px;
  padding-top: 10px;
  border-top: 1px dotted var(--border);
  font-size: 12px;
  color: var(--muted);
}

.about-portrait {
  width: 170px;
  flex-shrink: 0;
  text-align: center;
}

.about-character-img {
  width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--border);
}

.character-caption {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 6px;
}

footer {
  border-top: 1px solid #aaa;
  margin-top: 36px;
  padding-top: 14px;
  color: var(--dim);
  font-size: 11.5px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

footer span {
  direction: ltr;
}

/* ==========================================================================
   Mobile Responsive Rules
   ========================================================================== */
@media (max-width: 640px) {
  .page-container {
    width: calc(100% - 24px);
    margin: 14px auto 36px;
  }

  header {
    margin-bottom: 16px;
    padding-bottom: 12px;
  }

  .header-top {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .logo-group {
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .header-logo-img {
    height: 62px;
    width: auto;
  }

  .logo {
    font-size: 21px;
    line-height: 1.25;
  }

  .subtitle {
    font-size: 11.5px;
  }

  .header-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding-top: 8px;
    border-top: 1px dotted var(--border);
  }

  .social-links {
    gap: 6px;
    flex-wrap: wrap;
  }

  .social-link {
    font-size: 11px;
    padding: 4px 8px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    min-height: 28px;
  }

  .theme-btn {
    padding: 5px 10px;
    min-height: 28px;
  }

  nav {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0;
    margin-top: 12px;
    border-bottom: 1px solid var(--border);
  }

  nav a {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 2px;
    font-size: 12.5px;
    text-align: center;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  nav a:hover {
    color: var(--blue-hover);
    border-bottom-color: var(--blue-hover);
  }

  nav a[aria-current="page"] {
    color: var(--text);
    font-weight: 700;
    border-bottom: 2px solid var(--blue);
  }

  .modes-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 10px 0;
    margin-bottom: 14px;
  }

  .mode-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
  }

  .mode-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    min-width: 44px;
    flex-shrink: 0;
  }

  #skills.tabs {
    display: grid;
    grid-template-columns: 1fr 1.2fr 1.6fr;
    gap: 4px;
    flex: 1;
    width: 100%;
  }

  #levels.tabs {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    flex: 1;
    width: 100%;
  }

  .tabs button {
    padding: 6px 2px;
    font-size: 11.5px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    white-space: nowrap;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .problem-area {
    min-height: 200px;
    padding: 28px 10px 20px;
  }

  .problem-tools {
    top: 8px;
    right: 8px;
    gap: 5px;
  }

  .tool-btn,
  .hint-bubble-btn {
    padding: 6px 7px;
    min-width: 32px;
    min-height: 32px;
    touch-action: manipulation;
  }

  .hint-popover {
    position: absolute;
    top: 38px;
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
    z-index: 40;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  }

  .prompt {
    font-size: 30px;
    min-height: 60px;
    margin: 12px 0 16px;
    padding: 4px 0;
    -webkit-overflow-scrolling: touch;
  }

  .prompt .katex {
    font-size: 1em;
  }

  .options-wrap {
    width: 100%;
    max-width: 100%;
  }

  .options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }

  .opt {
    min-height: 48px;
    padding: 8px 10px;
    font-size: 16px;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  .opt:active:not(:disabled) {
    transform: scale(0.98);
  }

  .feedback-area {
    margin-top: 12px;
    width: 100%;
  }

  .feedback {
    min-height: 22px;
    font-size: 12px;
  }

  .next-action {
    width: 100%;
    justify-content: center;
  }

  .primary-btn {
    width: 100%;
    max-width: 260px;
    min-height: 42px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
  }

  .primary-btn:active {
    transform: scale(0.98);
  }

  .stats-table td {
    padding: 7px 4px;
    font-size: 12px;
  }

  .stats-table td:nth-child(odd) {
    width: 28%;
    font-size: 11.5px;
  }

  .stats-table td:nth-child(even) {
    width: 22%;
    font-size: 14px;
  }

  .table-wrap {
    margin-top: 10px;
    -webkit-overflow-scrolling: touch;
  }

  .stats-cards-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .about-layout {
    flex-direction: column;
    align-items: center;
    gap: 16px;
  }

  .about-portrait {
    width: 130px;
  }

  .about-content {
    width: 100%;
    line-height: 2.1;
    text-align: justify;
    text-justify: inter-word;
  }

  footer {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 6px;
    padding-top: 16px;
    margin-top: 32px;
  }
}

@media (max-width: 440px) {
  .header-logo-img {
    height: 52px;
  }

  .logo {
    font-size: 18px;
  }

  .subtitle {
    font-size: 10.5px;
  }

  .social-links {
    gap: 4px;
  }

  .social-link {
    padding: 3px 6px;
    font-size: 10.5px;
  }

  nav a {
    font-size: 11.5px;
    padding: 7px 1px;
  }

  .mode-item {
    gap: 6px;
  }

  .mode-label {
    min-width: 38px;
    font-size: 11px;
  }

  #skills.tabs {
    grid-template-columns: 1fr 1.15fr 1.55fr;
  }

  .tabs button {
    font-size: 10.5px;
    padding: 5px 1px;
    min-height: 34px;
  }

  .prompt {
    font-size: 25px;
  }

  .opt {
    min-height: 44px;
    padding: 6px 8px;
    font-size: 15px;
  }

  .opt .k {
    font-size: 10px;
  }

  .stats-table td:nth-child(odd) {
    font-size: 11px;
    width: 30%;
  }

  .stats-table td:nth-child(even) {
    font-size: 13px;
    width: 20%;
  }
}

@media (max-width: 360px) {
  .mode-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .mode-label {
    min-width: auto;
  }

  #skills.tabs,
  #levels.tabs {
    width: 100%;
  }
}
