:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #20242d;
  --border: #2c313c;
  --text: #eef0f4;
  --text-2: #a7adba;
  --muted: #6f7686;
  --accent: #3ddc84;
  --accent-ink: #062a15;
  --accent-soft: rgba(61, 220, 132, 0.14);
  --fire: #ff8a3d;
  --danger: #ff5c5c;
  --water: #4fb3ff;
  --up: #3ddc84;
  --down: #ff7a7a;
  --radius: 16px;
  --tabbar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100vh; min-height: 100dvh; overscroll-behavior-y: none; }

button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; font-size: 16px; color: var(--text); }
[hidden] { display: none !important; }

/* ---------- Üst çubuk ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: rgba(15, 17, 21, 0.92);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 22px; font-weight: 750; letter-spacing: -0.01em; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 12px;
  background: transparent; border: none; color: var(--text-2); font-size: 20px;
}
.icon-btn:active { background: var(--surface-2); }

/* ---------- Ana alan ---------- */
main {
  padding: 16px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
  max-width: 640px; margin: 0 auto;
}

.grid { display: grid; gap: 16px; grid-template-columns: 1fr; }
.stack { display: flex; flex-direction: column; gap: 16px; }

@media (min-width: 768px) {
  main { max-width: 1100px; padding-left: 24px; padding-right: 24px; }
  .grid.two { grid-template-columns: 1fr 1fr; align-items: start; }
  .grid.measures { grid-template-columns: repeat(2, 1fr); }
  .span-2 { grid-column: span 2; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card h3 { margin: 0 0 12px; font-size: 17px; font-weight: 700; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head h3 { margin: 0; }

.section-title {
  margin: 8px 2px 0; font-size: 13px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted);
}

.muted { color: var(--muted); }
.small { font-size: 13px; }
.text-2 { color: var(--text-2); }

/* ---------- Butonlar ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-weight: 600; font-size: 15px;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: rgba(255, 92, 92, 0.4); background: rgba(255, 92, 92, 0.08); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }

/* ---------- Form ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--text-2); font-weight: 600; }
.input, textarea.input, select.input {
  width: 100%; min-height: 44px; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  outline: none;
}
.input:focus { border-color: var(--accent); }
textarea.input { min-height: 96px; resize: vertical; }
.input::placeholder { color: var(--muted); }

/* ---------- Tarih gezgini ---------- */
.datenav {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px;
}
.datenav .icon-btn { font-size: 22px; color: var(--text); }
.datenav .icon-btn:disabled { opacity: 0.25; }
.datenav-label { text-align: center; flex: 1; }
.datenav-label strong { display: block; font-size: 16px; }
.datenav-label button {
  background: none; border: none; color: var(--accent); font-size: 13px; padding: 2px 6px;
}

/* ---------- Seri (zincir) ---------- */
.streak-card { display: flex; align-items: center; gap: 16px; }
.streak-main { flex: 1; }
.streak-num { font-size: 64px; font-weight: 800; line-height: 1; letter-spacing: -0.03em; color: var(--fire); }
.streak-label { color: var(--text-2); font-weight: 600; margin-top: 4px; }
.streak-side { display: flex; flex-direction: column; gap: 10px; text-align: right; }
.stat-mini strong { display: block; font-size: 24px; font-weight: 750; }
.stat-mini span { font-size: 12px; color: var(--muted); }

/* ---------- Takvim ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head strong { font-size: 17px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: 12px; color: var(--muted); font-weight: 600; padding: 4px 0; }
.cal-day {
  position: relative; aspect-ratio: 1; border-radius: 10px;
  background: var(--surface-2); border: 1px solid transparent;
  display: flex; align-items: flex-start; justify-content: flex-start;
  padding: 4px 6px; font-size: 13px; font-weight: 600; color: var(--text-2);
  overflow: hidden;
}
.cal-day.empty { background: transparent; pointer-events: none; }
.cal-day.today { border-color: var(--accent); color: var(--text); }
.cal-day.future { opacity: 0.35; pointer-events: none; }
.cal-day.done { background: var(--accent-soft); color: var(--text); }
.cal-day .x {
  position: absolute; inset: 14% 14% 10% 14%; pointer-events: none;
}
.cal-day .x line { stroke: var(--accent); stroke-width: 12; stroke-linecap: round; }
.cal-hint { margin-top: 10px; font-size: 13px; color: var(--muted); text-align: center; }

/* ---------- Ölçüler ---------- */
.measure-card { cursor: pointer; }
.measure-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.measure-name { font-weight: 700; font-size: 16px; }
.measure-value { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.measure-value small { font-size: 14px; color: var(--text-2); font-weight: 600; margin-left: 2px; }
.delta { font-size: 13px; font-weight: 700; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.delta.flat { color: var(--muted); }
.chart { width: 100%; display: block; margin-top: 8px; touch-action: pan-y; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-text { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent-soft); }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .dot.active { r: 6; }
.chart .tip-bg { fill: var(--surface-2); stroke: var(--border); }
.chart .tip-text { fill: var(--text); font-size: 12px; font-weight: 600; }
.chart .cross { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-empty { padding: 18px 0 6px; color: var(--muted); font-size: 14px; }

.list { display: flex; flex-direction: column; }
.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.list-row .grow { flex: 1; min-width: 0; }

/* ---------- Spor ---------- */
.ex-card { padding: 14px; }
.ex-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.ex-name { font-weight: 700; font-size: 17px; word-break: break-word; }
.ex-prev { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.ex-prev b { color: var(--text); }
.ex-actions { display: flex; gap: 4px; flex-shrink: 0; }
.ex-actions .icon-btn { width: 38px; height: 38px; background: var(--surface-2); color: var(--text); font-size: 16px; }
.ex-actions .icon-btn.play { background: rgba(255, 70, 70, 0.16); color: #ff6b6b; }
.ex-inputs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.ex-inputs label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.ex-inputs .input { text-align: center; font-weight: 700; padding: 8px 6px; }
.ex-card.filled { border-color: rgba(61, 220, 132, 0.45); }
.ex-progress { font-size: 12px; font-weight: 700; margin-top: 8px; min-height: 16px; }

.cardio-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cardio-row { margin-bottom: 14px; }
.cardio-row:last-child { margin-bottom: 0; }
.cardio-title { font-weight: 700; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }

.mark-day {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px dashed var(--border); text-align: left;
}
.mark-day.on { background: var(--accent-soft); border: 1px solid var(--accent); }
.mark-day .big-x { font-size: 28px; font-weight: 900; color: var(--muted); width: 32px; text-align: center; }
.mark-day.on .big-x { color: var(--accent); }

.day-chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.day-chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; padding: 8px 14px; border-radius: 999px; min-height: 38px;
  background: var(--surface-2); border: 1px solid var(--border); font-weight: 600; font-size: 14px;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.prog-row { display: flex; align-items: center; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.prog-row:last-child { border-bottom: none; }
.prog-row .grow { flex: 1; min-width: 0; font-weight: 600; word-break: break-word; }
.prog-row .icon-btn { width: 36px; height: 36px; font-size: 16px; background: var(--surface-2); color: var(--text); }
.prog-row .icon-btn:disabled { opacity: 0.25; }
.prog-row .icon-btn.del { color: var(--danger); }

.lib-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%;
  padding: 12px; margin-bottom: 6px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border); text-align: left; font-weight: 600;
}

.video-wrap { position: relative; width: 100%; aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; background: #000; }
.video-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

.history-day { padding: 12px 0; border-bottom: 1px solid var(--border); }
.history-day:last-child { border-bottom: none; }
.history-day button.link { background: none; border: none; color: var(--accent); padding: 0; font-weight: 700; font-size: 16px; }
.history-day ul { margin: 6px 0 0; padding-left: 18px; color: var(--text-2); font-size: 14px; }

/* ---------- Yemek ---------- */
.meal-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 4px; border: none; border-bottom: 1px solid var(--border);
  background: transparent; text-align: left;
}
.meal-item:last-child { border-bottom: none; }
.check {
  width: 28px; height: 28px; flex-shrink: 0; border-radius: 9px;
  border: 2px solid var(--muted); display: flex; align-items: center; justify-content: center;
  color: transparent; font-weight: 900; font-size: 16px;
}
.meal-item.on .check { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.meal-item.on .meal-text { color: var(--text-2); text-decoration: line-through; text-decoration-color: var(--muted); }
.meal-text { flex: 1; word-break: break-word; }
.meal-item.deleted .meal-text::after { content: " (listeden silinmiş)"; color: var(--muted); font-size: 12px; }

.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.25s; }

.water-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.water-count { font-size: 40px; font-weight: 800; letter-spacing: -0.02em; }
.water-count small { font-size: 16px; color: var(--text-2); font-weight: 600; }
.water-btns { display: flex; gap: 8px; }
.water-btns .btn { min-width: 56px; font-size: 22px; }
.water-btns .btn.add { background: var(--water); border-color: var(--water); color: #04233a; }
.glasses { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.glass { width: 26px; height: 32px; }
.glass path.body { fill: none; stroke: var(--border); stroke-width: 2; }
.glass path.fill { fill: transparent; }
.glass.full path.body { stroke: var(--water); }
.glass.full path.fill { fill: var(--water); }

.edit-meal { margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.edit-meal:last-child { border-bottom: none; }
.edit-meal-head { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.edit-item { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.edit-item .input, .edit-meal-head .input { min-height: 40px; padding: 8px 10px; }
.edit-meal-head .input { font-weight: 700; }
.edit-item .icon-btn, .edit-meal-head .icon-btn { width: 36px; height: 36px; flex-shrink: 0; background: var(--surface-2); font-size: 15px; color: var(--text); }
.edit-item .icon-btn.del, .edit-meal-head .icon-btn.del { color: var(--danger); }

.empty-state { text-align: center; padding: 20px 10px; color: var(--muted); }

/* ---------- Alt sekmeler ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(19, 22, 28, 0.96);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: none; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0.06em;
}
.tab svg { width: 26px; height: 26px; }
.tab.active { color: var(--accent); }

/* ---------- Alt pencere (sheet) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 640px; max-height: 92vh; max-height: 92dvh;
  background: var(--surface); border: 1px solid var(--border); border-bottom: none;
  border-radius: 20px 20px 0 0; display: flex; flex-direction: column;
  animation: up 0.2s ease-out;
}
@media (min-width: 768px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 20px; border-bottom: 1px solid var(--border); max-height: 86vh; }
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 12px 10px 18px; border-bottom: 1px solid var(--border);
}
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-body { padding: 16px 18px calc(20px + var(--safe-bottom)); overflow-y: auto; -webkit-overflow-scrolling: touch; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-weight: 600; font-size: 14px; max-width: 90vw; text-align: center;
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
}
.ex-progress:empty { display: none; }
