/* ========== RESET & BASE ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --orange: #E07B39;
  --orange-light: #F09050;
  --orange-dark: #C4622A;
  --orange-faint: #FFF0E8;
  --orange-pale: #FFE4D0;
  --white: #FFFFFF;
  --bg: #F7F4F1;
  --card: #FFFFFF;
  --border: #EDE8E3;
  --text: #1A1208;
  --text-mid: #5A4A38;
  --text-soft: #9A8A78;
  --shadow: 0 2px 12px rgba(224,123,57,0.10);
  --shadow-md: 0 4px 24px rgba(224,123,57,0.16);
  --radius: 16px;
  --radius-sm: 10px;
  font-size: 16px;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Vazirmatn', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  direction: rtl;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* ========== HEADER ========== */
.app-header {
  background: var(--white);
  border-bottom: 1.5px solid var(--border);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
}

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

.header-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.header-sub {
  font-size: 0.68rem;
  color: var(--text-soft);
  font-weight: 400;
}

.header-actions {
  display: flex;
  gap: 6px;
}

.icon-btn {
  background: var(--orange-faint);
  border: none;
  border-radius: 10px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--orange);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.icon-btn:active { transform: scale(0.92); background: var(--orange-pale); }

/* ========== MAIN ========== */
.app-main {
  padding: 16px 14px 100px;
  max-width: 520px;
  margin: 0 auto;
}

.section-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
  padding-right: 4px;
}

/* ========== SUBJECT CARD ========== */
.subject-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  margin-bottom: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: border-color 0.2s;
}
.subject-card.has-input { border-color: var(--orange-light); }

.subject-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 15px 10px;
  background: linear-gradient(135deg, var(--orange-faint) 0%, var(--white) 100%);
  border-bottom: 1px solid var(--border);
}

.subject-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

.subject-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.coeff-badge {
  background: var(--orange);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
}

.q-count-badge {
  background: var(--bg);
  color: var(--text-mid);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

.subject-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  padding: 12px 14px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.input-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-soft);
  text-align: center;
}

.input-label.correct { color: #22A55A; }
.input-label.wrong { color: #E03B3B; }
.input-label.skip { color: #A08060; }

.num-input {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 9px 6px;
  font-size: 1.1rem;
  font-weight: 700;
  font-family: 'Vazirmatn', sans-serif;
  text-align: center;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
  -webkit-appearance: none;
  width: 100%;
}
.num-input:focus { border-color: var(--orange); background: var(--white); }
.num-input.correct:focus { border-color: #22A55A; }
.num-input.wrong:focus { border-color: #E03B3B; }

/* Quick Input Buttons */
.quick-btns {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-top: 2px;
}
.q-btn {
  background: var(--border);
  border: none;
  border-radius: 6px;
  padding: 3px 7px;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-mid);
  cursor: pointer;
  font-family: 'Vazirmatn', sans-serif;
}
.q-btn:active { background: var(--orange-pale); color: var(--orange); }

/* ========== CALC FOOTER ========== */
.calc-footer {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.calc-btn {
  background: linear-gradient(135deg, var(--orange) 0%, var(--orange-light) 100%);
  color: white;
  border: none;
  border-radius: 14px;
  padding: 16px 24px;
  font-size: 1.05rem;
  font-weight: 700;
  font-family: 'Vazirmatn', sans-serif;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(224,123,57,0.35);
  transition: transform 0.15s, box-shadow 0.15s;
}
.calc-btn:active { transform: scale(0.97); box-shadow: 0 2px 8px rgba(224,123,57,0.25); }

.reset-btn {
  background: transparent;
  color: var(--text-soft);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 11px;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: 'Vazirmatn', sans-serif;
  cursor: pointer;
}
.reset-btn:active { background: var(--bg); }

/* ========== RESULTS ========== */
.final-score-card {
  border-radius: var(--radius);
  padding: 28px 24px;
  text-align: center;
  margin-bottom: 18px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(145deg, var(--orange) 0%, var(--orange-dark) 100%);
  box-shadow: 0 6px 28px rgba(224,123,57,0.4);
  color: white;
}
.final-score-card::before {
  content: '%';
  position: absolute;
  font-size: 9rem;
  font-weight: 800;
  opacity: 0.08;
  right: -10px;
  top: -20px;
  line-height: 1;
}

.final-label {
  font-size: 0.75rem;
  font-weight: 600;
  opacity: 0.85;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.final-number {
  font-size: 4rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
}

.final-badge {
  display: inline-block;
  background: rgba(255,255,255,0.2);
  border-radius: 20px;
  padding: 4px 16px;
  font-size: 0.82rem;
  font-weight: 600;
  margin-top: 10px;
  backdrop-filter: blur(4px);
}

/* Subject Result Cards */
.subj-result {
  background: var(--card);
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  padding: 13px 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.subj-res-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.subj-res-name {
  font-size: 0.92rem;
  font-weight: 700;
}

.subj-res-coeff {
  font-size: 0.7rem;
  color: var(--text-soft);
  background: var(--bg);
  border-radius: 8px;
  padding: 3px 8px;
}

.subj-res-bars {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.bar-item {
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 10px;
}

.bar-label {
  font-size: 0.63rem;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 4px;
}

.bar-val {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text);
}

.bar-track {
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  margin-top: 5px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--orange);
  transition: width 0.6s ease;
}
.bar-fill.raw { background: #AAC; }

/* Analysis Card */
.analysis-card, .what-if-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.analysis-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--orange);
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.analysis-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--bg);
  font-size: 0.84rem;
}
.analysis-row:last-child { border-bottom: none; }

.analysis-icon { font-size: 1.1rem; flex-shrink: 0; }

.analysis-text strong {
  color: var(--orange-dark);
  font-weight: 700;
}

.what-if-row {
  background: var(--orange-faint);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 0.82rem;
}
.what-if-row:last-child { margin-bottom: 0; }
.what-if-row .wi-title { font-weight: 700; color: var(--orange-dark); margin-bottom: 3px; }
.what-if-row .wi-val { color: var(--text-mid); }

/* Result Actions */
.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
  margin-bottom: 20px;
}

.save-btn {
  background: linear-gradient(135deg, var(--orange) 0%, var(--orange-light) 100%);
  color: white;
  border: none;
  border-radius: 14px;
  padding: 15px 24px;
  font-size: 1rem;
  font-weight: 700;
  font-family: 'Vazirmatn', sans-serif;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 14px rgba(224,123,57,0.3);
}
.save-btn:active { transform: scale(0.97); }

.back-btn {
  background: transparent;
  color: var(--text-soft);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: 'Vazirmatn', sans-serif;
  cursor: pointer;
}

/* ========== MODAL ========== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: flex-end;
}
.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(3px);
}

.modal-panel {
  position: relative;
  background: var(--white);
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px 14px;
  border-bottom: 1.5px solid var(--border);
  font-size: 1rem;
  font-weight: 700;
  flex-shrink: 0;
}

.modal-close {
  background: var(--bg);
  border: none;
  border-radius: 50%;
  width: 32px; height: 32px;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text-mid);
}

.modal-body {
  overflow-y: auto;
  padding: 16px;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

/* Chart */
.chart-container {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chart-container canvas { max-height: 170px; }

/* History List */
.hist-item {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: border-color 0.15s;
}
.hist-item:active { border-color: var(--orange); }

.hist-date { font-size: 0.75rem; color: var(--text-soft); margin-bottom: 3px; }
.hist-score { font-size: 1.4rem; font-weight: 800; color: var(--orange); }
.hist-detail { font-size: 0.7rem; color: var(--text-soft); }
.hist-delete {
  background: #FFE9E9;
  border: none;
  border-radius: 8px;
  width: 32px; height: 32px;
  color: #E03B3B;
  font-size: 0.9rem;
  cursor: pointer;
  flex-shrink: 0;
}

.empty-hist {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-soft);
  font-size: 0.9rem;
}
.empty-hist .big-icon { font-size: 3rem; margin-bottom: 10px; }

/* Settings */
.setting-item {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  margin-bottom: 10px;
}

.setting-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.setting-name-input, .setting-num {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.88rem;
  font-family: 'Vazirmatn', sans-serif;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.setting-name-input { flex: 1; }
.setting-num { width: 60px; text-align: center; }
.setting-name-input:focus, .setting-num:focus { border-color: var(--orange); }

.setting-sub {
  display: flex;
  gap: 8px;
  align-items: center;
}

.setting-label {
  font-size: 0.7rem;
  color: var(--text-soft);
  font-weight: 600;
}

.del-subject-btn {
  background: #FFE9E9;
  border: none;
  border-radius: 8px;
  padding: 7px 10px;
  color: #E03B3B;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: 'Vazirmatn', sans-serif;
  cursor: pointer;
  margin-right: auto;
}

.add-subject-btn {
  width: 100%;
  background: var(--orange-faint);
  border: 2px dashed var(--orange-light);
  border-radius: 12px;
  padding: 14px;
  color: var(--orange);
  font-size: 0.9rem;
  font-weight: 700;
  font-family: 'Vazirmatn', sans-serif;
  cursor: pointer;
  margin-top: 8px;
}
.add-subject-btn:active { background: var(--orange-pale); }

/* ========== TOAST ========== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 12px 22px;
  border-radius: 24px;
  font-size: 0.88rem;
  font-weight: 600;
  z-index: 9999;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  white-space: nowrap;
}
.toast.hidden { display: none; }

/* ========== UTILS ========== */
.hidden { display: none !important; }

input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; }
input[type=number] { -moz-appearance: textfield; }
