@font-face {
  font-family: 'Vazirmatn';
  src: url('fonts/Vazirmatn-Regular.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('fonts/Vazirmatn-Medium.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('fonts/Vazirmatn-Bold.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root, [data-theme="dark"] {
  --bg: #1a1612;
  --surface: #241f1a;
  --surface2: #2e2822;
  --text: #f5efe6;
  --muted: #b0a595;
  --primary: #e8a54b;
  --primary-soft: #c4842e;
  --on-primary: #1a1208;
  --accent: #f0c27a;
  --success: #7bc47f;
  --danger: #e57373;
  --outline: #3d362e;
  --today: #332a1f;
  --scrim: rgba(0,0,0,.55);
  --r: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,.35);
}

[data-theme="light"] {
  --bg: #faf6f0;
  --surface: #ffffff;
  --surface2: #f3ebe0;
  --text: #2a2218;
  --muted: #7a6e60;
  --primary: #d4922a;
  --primary-soft: #e8a54b;
  --on-primary: #fff;
  --accent: #c4842e;
  --success: #3d8b4a;
  --danger: #c62828;
  --outline: #e0d5c8;
  --today: #fff5e6;
  --scrim: rgba(40,30,15,.35);
  --shadow: 0 4px 20px rgba(60,40,10,.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Vazirmatn', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  transition: background .3s ease, color .3s ease;
}

.app {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 12px 80px;
}

/* Icons */
.icon, .nav-icon svg {
  width: 22px;
  height: 22px;
  display: block;
}
.icon-btn .icon, .btn-icon .icon {
  width: 20px;
  height: 20px;
}
.nav-icon {
  position: relative;
  width: 22px;
  height: 22px;
  display: block;
}
.nav-icon .ico {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .2s ease, transform .2s ease;
}
.nav-icon .ico.filled { opacity: 0; transform: scale(.85); }
.nav-btn.active .nav-icon .ico.outline { opacity: 0; transform: scale(.85); }
.nav-btn.active .nav-icon .ico.filled { opacity: 1; transform: scale(1); }

/* Top */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 4px 14px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  transition: background .3s;
}
.top-bar h1 { font-size: 1.3rem; font-weight: 700; }
.week-range { font-size: .85rem; color: var(--muted); margin-top: 2px; }

.icon-btn, .btn-icon {
  width: 40px; height: 40px;
  border: none;
  background: var(--surface2);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform .15s, background .2s;
}
.icon-btn:active, .btn-icon:active { transform: scale(.92); }
.btn-icon.primary { background: var(--primary); color: var(--on-primary); }

/* Panels */
.panel {
  display: none;
  animation: fadeSlide .28s ease;
}
.panel.active { display: block; }

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

.card {
  background: var(--surface);
  border: 1px solid var(--outline);
  padding: 14px;
  margin-bottom: 12px;
  transition: background .3s, border-color .3s;
}
.card h2 {
  font-size: .95rem;
  font-weight: 700;
  margin-bottom: 12px;
}

/* Table */
.table-card { padding: 0; overflow: hidden; }
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--r);
}
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: .82rem;
  min-width: 260px;
}
.data-table th, .data-table td {
  padding: 10px 8px;
  text-align: center;
  border-bottom: 1px solid var(--outline);
}
.data-table th {
  font-weight: 700;
  color: var(--muted);
  background: var(--surface2);
}
.data-table th:first-child,
.data-table td:first-child {
  text-align: right;
  position: sticky;
  right: 0;
  background: var(--surface);
  z-index: 2;
  min-width: 70px;
  font-weight: 600;
}
.data-table th:first-child { background: var(--surface2); z-index: 3; }
.data-table tr.today td { background: var(--today); }
.data-table tr.today td:first-child {
  background: var(--today);
  color: var(--primary);
  box-shadow: inset -3px 0 0 var(--primary);
}

.cell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 30px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .12s, background .15s;
  user-select: none;
}
.cell:active { transform: scale(.9); }
.cell.pos { color: var(--success); background: color-mix(in srgb, var(--success) 12%, transparent); }
.cell.neg { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.cell.zero { color: var(--muted); }
.cell.empty {
  color: var(--outline);
  border: 1px dashed var(--outline);
  background: transparent;
}

.summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-top: 1px solid var(--outline);
}
.summary .muted { display: block; font-size: .75rem; color: var(--muted); }
.summary strong { font-size: 1.3rem; color: var(--primary); font-weight: 700; }

.qual-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--outline);
  padding: 6px 12px;
  cursor: pointer;
  font-family: inherit;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
  transition: transform .15s;
}
.qual-chip:active { transform: scale(.96); }
.emoji-img { width: 22px; height: 22px; object-fit: contain; }

/* Tasks */
.add-row { display: flex; gap: 8px; margin-bottom: 12px; }
.add-row input {
  flex: 1;
  padding: 11px 12px;
  border: 1px solid var(--outline);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: .95rem;
  outline: none;
  transition: border-color .2s;
}
.add-row input:focus { border-color: var(--primary); }

.list { display: flex; flex-direction: column; gap: 6px; }
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 12px;
  background: var(--bg);
  border: 1px solid var(--outline);
  animation: fadeSlide .25s ease;
}
.list-item button {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  padding: 4px;
  display: grid;
  place-items: center;
}

/* Forms */
input[type="text"], input[type="number"] {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--outline);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: .95rem;
  outline: none;
  margin-bottom: 10px;
  transition: border-color .2s;
}
input:focus { border-color: var(--primary); }

.btn {
  width: 100%;
  padding: 11px 18px;
  border: none;
  font-family: inherit;
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 6px;
  transition: transform .12s, opacity .15s, background .2s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.ghost {
  background: transparent;
  border: 1px solid var(--outline);
  color: var(--primary);
}
.btn.text {
  background: transparent;
  color: var(--primary);
  width: auto;
  padding: 10px 14px;
}
.btn.text.danger, .btn.danger { color: var(--danger); }

.hint { font-size: .8rem; color: var(--muted); margin-bottom: 8px; }
.row-between { display: flex; justify-content: space-between; align-items: center; }

.switch { position: relative; width: 48px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0;
  background: var(--outline);
  cursor: pointer;
  transition: .2s;
}
.slider::before {
  content: '';
  position: absolute;
  width: 22px; height: 22px;
  left: 3px; bottom: 3px;
  background: var(--muted);
  transition: .2s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before {
  transform: translateX(20px);
  background: var(--on-primary);
}

.qual-row {
  display: grid;
  grid-template-columns: 52px 52px 1fr 44px 32px;
  gap: 6px;
  margin-bottom: 8px;
  align-items: center;
}
.qual-row input { margin: 0; padding: 8px; font-size: .85rem; }
.qual-row .emoji-pick {
  width: 40px; height: 40px;
  padding: 0;
  border: 1px solid var(--outline);
  background: var(--bg);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.qual-row .emoji-pick img { width: 28px; height: 28px; }
.qual-row .q-del {
  background: none; border: none; color: var(--danger); cursor: pointer; font-size: 1rem;
}

.report-stats {
  margin-top: 12px;
  font-size: .85rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.report-stats strong { color: var(--primary); }
.report-stats .qi { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--text); }
.report-stats .qi img { width: 16px; height: 16px; object-fit: contain; }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--outline);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  z-index: 30;
  max-width: 680px;
  margin: 0 auto;
  transition: background .3s;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 2px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: .68rem;
  cursor: pointer;
  transition: color .2s, transform .15s;
}

.nav-btn.active { color: var(--primary); font-weight: 700; }
.nav-btn:active { transform: scale(.95); }

/* Overlay / sheet */
.overlay {
  position: fixed; inset: 0;
  background: var(--scrim);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn .2s ease;
}
.overlay[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  background: var(--surface);
  border: 1px solid var(--outline);
  border-bottom: none;
  width: 100%;
  max-width: 440px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 10px 18px 24px;
  animation: slideUp .28s cubic-bezier(.2,.8,.2,1);
  box-shadow: var(--shadow);
}
@keyframes slideUp {
  from { transform: translateY(48px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.handle {
  width: 36px; height: 4px;
  background: var(--outline);
  margin: 4px auto 14px;
}
.sheet h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 4px; }
.meta { font-size: .85rem; color: var(--muted); margin-bottom: 14px; }

.score-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.score-chip {
  min-width: 52px; height: 44px;
  border: 2px solid var(--outline);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s;
}
.score-chip.selected {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 22%, transparent);
  color: var(--accent);
}
.score-chip.pos { color: var(--success); }
.score-chip.neg { color: var(--danger); }

.sheet-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 8px;
}

/* Emoji picker */
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin: 12px 0 8px;
}
.emoji-opt {
  aspect-ratio: 1;
  border: 2px solid var(--outline);
  background: var(--bg);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 6px;
  transition: border-color .15s, transform .12s;
}
.emoji-opt:active { transform: scale(.92); }
.emoji-opt.selected { border-color: var(--primary); }
.emoji-opt img { width: 100%; height: 100%; object-fit: contain; }

/* Toast */
.toast-host {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: min(360px, calc(100% - 24px));
}
.toast {
  background: var(--surface2);
  border: 1px solid var(--outline);
  color: var(--text);
  padding: 12px 16px;
  font-size: .9rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn .3s cubic-bezier(.2,.8,.2,1);
  pointer-events: auto;
}
.toast.out { animation: toastOut .25s ease forwards; }
.toast.success { border-color: color-mix(in srgb, var(--success) 50%, var(--outline)); }
.toast.error { border-color: color-mix(in srgb, var(--danger) 50%, var(--outline)); }
.toast .icon { flex-shrink: 0; width: 20px; height: 20px; }
.toast.success .icon { color: var(--success); }
.toast.error .icon { color: var(--danger); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
  to { opacity: 0; transform: translateY(-8px); }
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
  font-size: .9rem;
}

@media (min-width: 560px) {
  .overlay { align-items: center; }
  .sheet { border: 1px solid var(--outline); margin-bottom: 20px; }
}

/* Month / year report cards */
.month-card, .year-block {
  border: 1px solid var(--outline);
  background: var(--bg);
  padding: 12px;
  margin-bottom: 10px;
}
.month-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 8px;
  flex-wrap: wrap;
}
.month-card-head strong { font-size: .95rem; }
.month-card-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.month-card-stats .muted {
  display: block;
  font-size: .7rem;
  color: var(--muted);
}
.month-card-stats strong {
  font-size: 1rem;
  color: var(--primary);
}
.pct-bar {
  height: 4px;
  background: var(--outline);
  overflow: hidden;
}
.pct-fill {
  height: 100%;
  background: var(--primary);
  transition: width .4s ease;
}
.year-block { margin-bottom: 14px; }
@media (max-width: 480px) {
  .month-card-stats { grid-template-columns: repeat(2, 1fr); }
}

/* Week navigator */
.week-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  background: var(--surface);
  border: 1px solid var(--outline);
  padding: 2px;
  max-width: 280px;
}
.week-nav-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, opacity .15s, transform .12s;
}
.week-nav-btn:active:not(:disabled) { transform: scale(.9); background: var(--surface2); }
.week-nav-btn:disabled {
  opacity: .3;
  cursor: not-allowed;
}
.week-nav-btn .icon { width: 18px; height: 18px; pointer-events: none; }
.week-nav-label {
  flex: 1;
  text-align: center;
  font-size: .85rem;
  color: var(--muted);
  padding: 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Compact qual emoji in reports */
.qi {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .8rem;
  font-weight: 600;
}
.qi img {
  width: 16px !important;
  height: 16px !important;
  object-fit: contain;
  flex-shrink: 0;
}
.month-card-head .qi img,
.year-block .qi img {
  width: 16px !important;
  height: 16px !important;
}
