:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --text: #22201c;
  --muted: #7c766c;
  --line: #e6e0d6;
  --accent: #2f6f5e;
  --accent-soft: #dcebe5;
  --warn: #c98a16;
  --warn-soft: #fbefd5;
  --danger: #b6452c;
  --danger-soft: #f6ddd5;
  --good: #3f8f5a;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a18;
    --card: #26241f;
    --text: #f1ede6;
    --muted: #a39d92;
    --line: #3a372f;
    --accent: #6cbfa6;
    --accent-soft: #24392f;
    --warn: #e5b04a;
    --warn-soft: #3d3220;
    --danger: #e9826a;
    --danger-soft: #42271f;
    --good: #7cc792;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  padding-top: env(safe-area-inset-top);
}
main { max-width: 560px; margin: 0 auto; padding: 12px 16px calc(96px + env(safe-area-inset-bottom)); }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -0.01em; }
button, input, textarea { font: inherit; color: inherit; }

.tab { display: none; }
.tab.active { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.label { font-weight: 600; margin: 0 0 8px; display: block; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 8px 0 0; }
.hint:empty { display: none; }

/* başlıklar */
.day-nav { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 12px; }
.day-title { text-align: center; }
.day-title small { color: var(--muted); }
.plain-head { margin: 4px 0 12px; padding: 8px 0; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card);
  font-size: 1.4rem; line-height: 1; cursor: pointer;
}
.icon-btn:disabled { opacity: 0.3; }

/* toplam */
.total-row { display: flex; align-items: baseline; gap: 6px; }
.total-num { font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.total-unit { color: var(--muted); }
.total-limit { margin-left: auto; color: var(--muted); font-size: 0.9rem; }
.bar { position: relative; height: 12px; background: var(--line); border-radius: 99px; margin-top: 8px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .4s, background .3s; }
.bar-fill.w1 { background: var(--warn); }
.bar-fill.w2 { background: var(--danger); }
.bar-mark { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--card); }
.warn { margin: 10px 0 0; padding: 8px 12px; border-radius: 10px; font-weight: 600; }
.warn.w1 { background: var(--warn-soft); color: var(--warn); }
.warn.w2 { background: var(--danger-soft); color: var(--danger); }

/* form */
textarea, select, input[type=number], input[type=text], input[type=password], input[type=date] {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 16px; /* iPhone'da yakınlaştırmayı engeller */
}
textarea { resize: vertical; }
.entry-options { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 0; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: 20px; height: 20px; accent-color: var(--danger); }
.manual { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.85rem; }
.manual input { width: 90px; padding: 6px 10px; }
.primary, .secondary {
  display: block; width: 100%; text-align: center;
  border-radius: 12px; padding: 12px; font-weight: 600; cursor: pointer;
}
.primary { background: var(--accent); color: #fff; border: none; }
.primary:disabled { opacity: 0.6; }
.secondary { background: transparent; border: 1px solid var(--line); }
.file-btn { cursor: pointer; }

/* kayıtlar */
.entry { position: relative; }
.entry-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.entry-text { margin: 0; color: var(--muted); font-size: 0.9rem; }
.entry-time { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.entry-total { font-weight: 700; white-space: nowrap; }
.badge { display: inline-block; font-size: 0.7rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--danger-soft); color: var(--danger); margin-left: 6px; vertical-align: middle; }
.items { list-style: none; margin: 10px 0 0; padding: 0; border-top: 1px dashed var(--line); }
.items li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.items .nm { flex: 1; }
.items .am { color: var(--muted); font-size: 0.85rem; }
.items input { width: 76px; padding: 4px 8px; text-align: right; }
.entry-actions { display: flex; justify-content: flex-end; margin-top: 8px; }
.link-btn { background: none; border: none; color: var(--danger); font-size: 0.85rem; cursor: pointer; padding: 4px; }
.empty { text-align: center; color: var(--muted); padding: 24px 0; }

/* segment */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg button {
  padding: 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); font-weight: 600; cursor: pointer;
}
#alcoholToday button.on[data-v="0"], #workoutToday button.on[data-v="1"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
#alcoholToday button.on[data-v="1"] { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
#workoutToday button.on[data-v="0"] { background: var(--line); }

/* istatistik */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { display: flex; flex-direction: column; align-items: flex-start; }
.stat-num { font-size: 2.4rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); }
.stat.muted .stat-num { color: var(--muted); }
.stat-label { color: var(--muted); font-size: 0.9rem; }

/* takvim */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal .wd { font-size: 0.7rem; color: var(--muted); padding-bottom: 4px; }
.cal .d {
  aspect-ratio: 1; border-radius: 10px; border: none; background: var(--bg);
  font-size: 0.85rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums;
}
.cal .d.blank { background: transparent; cursor: default; }
.cal .d.future { opacity: 0.35; cursor: default; }
.cal .d.today { outline: 2px solid var(--text); outline-offset: -2px; }
.cal .d.red { background: var(--danger); color: #fff; }
.cal .d.green { background: var(--accent-soft); color: var(--accent); }
.cal .d.done { background: var(--accent); color: #fff; }
.legend { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.8rem; margin-top: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.red { background: var(--danger); }
.dot.green { background: var(--accent-soft); border: 1px solid var(--accent); margin-left: 8px; }

/* antrenman haftası */
.week-dots { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.week-dots div { text-align: center; font-size: 0.75rem; color: var(--muted); }
.week-dots span {
  display: block; margin: 4px auto 0; width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid var(--line);
}
.week-dots span.on { background: var(--accent); border-color: var(--accent); }
.week-dots span.today { border-color: var(--text); }
.week-msg { margin: 12px 0 0; font-weight: 600; }

/* geçmiş */
.hist { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.hist .hd { flex: 1; }
.hist .hd small { color: var(--muted); display: block; }
.hist .hk { font-weight: 700; font-variant-numeric: tabular-nums; }
.hist .hk.w1 { color: var(--warn); }
.hist .hk.w2 { color: var(--danger); }
.hist .tags { font-size: 0.75rem; }

/* ayarlar */
.form-grid { display: grid; gap: 12px; }
.form-grid label { display: grid; gap: 6px; font-size: 0.9rem; font-weight: 600; }
.form-grid a { color: var(--accent); }
.version { text-align: center; color: var(--muted); font-size: 0.8rem; }

/* alt menü */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar button {
  background: none; border: none; font-size: 0.68rem; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; cursor: pointer;
}
.tabbar .ti { font-size: 1.25rem; line-height: 1.2; }
.tabbar button.active { color: var(--accent); font-weight: 600; }

/* bildirim */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom));
  max-width: 528px; margin: 0 auto;
  background: var(--text); color: var(--bg);
  padding: 12px 16px; border-radius: 12px; font-weight: 600; text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast.w1 { background: var(--warn); color: #fff; }
.toast.w2 { background: var(--danger); color: #fff; }

/* hesap bekleyen kayıtlar */
.entry.pending { border-style: dashed; }
.badge.wait { background: var(--line); color: var(--muted); }
.retry-btn { margin-top: 10px; padding: 10px; }
.retry-btn:disabled { opacity: .6; }
.pending-note { margin: 10px 0 0; color: var(--muted); font-size: .85rem; }

.badge.calc { background: var(--accent-soft); color: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.entry-error { margin: 10px 0 0; font-size: .85rem; color: var(--warn); }
.manual-fix { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--muted); font-size: .85rem; }
.manual-fix input { width: 90px; padding: 6px 10px; }
.devil { font-size: 1.4rem; line-height: 1; }
.emoji-tag { margin-left: 6px; font-size: 1rem; vertical-align: middle; }

/* ---------- alışkanlıklar (v1.0) ---------- */
:root { --hab: #9a7bd0; --hab-soft: #ece4f8; --hab-mid: #c7b3ea; }
@media (prefers-color-scheme: dark) { :root { --hab: #b9a0e8; --hab-soft: #2e2740; --hab-mid: #574a78; } }

.chips { display: flex; gap: 8px; }
.chip {
  width: 46px; height: 46px; border-radius: 14px; font-size: 1.45rem; line-height: 1;
  border: 1px solid var(--line); background: var(--bg); cursor: pointer;
  filter: grayscale(1); opacity: .55; transition: transform .12s, opacity .12s, filter .12s;
}
.chip.on { filter: none; opacity: 1; border-color: var(--hab); background: var(--hab-soft); transform: scale(1.06); }

.day-habits { margin: 10px 0 0; font-size: 1.05rem; letter-spacing: .02em; }

.habit-card { padding-bottom: 12px; }
.hc-head { display: flex; align-items: center; justify-content: space-between; }
.hc-emoji { font-size: 2rem; line-height: 1; }
.hc-today { color: var(--muted); font-size: .9rem; }
.hc-today b { color: var(--text); font-size: 1.1rem; }
.hc-streak { margin-top: 6px; color: var(--muted); }
.hc-big { font-size: 2.2rem; font-weight: 700; color: var(--hab); font-variant-numeric: tabular-nums; margin-right: 2px; }
.hc-sub { color: var(--muted); font-size: .85rem; margin-top: 4px; }
.spark { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: end; margin: 12px 0 10px; height: 72px; }
.sp { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 3px; height: 100%; }
.sp-n { font-size: .7rem; color: var(--muted); font-variant-numeric: tabular-nums; min-height: 1em; }
.sp-bar { width: 100%; max-width: 26px; border-radius: 6px; background: var(--line); }
.sp-bar.on { background: var(--hab); }
.sp-d { font-size: .65rem; color: var(--muted); }

.habit-tabs { display: flex; gap: 8px; margin-bottom: 10px; }
.habit-tabs button {
  flex: 1; padding: 8px 0; font-size: 1.3rem; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); cursor: pointer; filter: grayscale(.8); opacity: .6;
}
.habit-tabs button.on { filter: none; opacity: 1; border-color: var(--hab); background: var(--hab-soft); }
.cal .d { position: relative; }
.cal .d.lv1 { background: var(--hab-soft); color: var(--text); }
.cal .d.lv2 { background: var(--hab-mid); color: var(--text); }
.cal .d.lv3 { background: var(--hab); color: #fff; }
.cal .d.sel { box-shadow: 0 0 0 2px var(--hab) inset; }
.cal .d .cn { position: absolute; right: 3px; bottom: 1px; font-size: .55rem; opacity: .8; }

.hday { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.hday-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.hday-head span { color: var(--muted); font-size: .85rem; }
.hday-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: .9rem; }
.hday-add { margin-top: 10px; padding: 10px; }

.slot-row { display: grid; grid-template-columns: 64px 1fr; gap: 12px; align-items: end; margin-bottom: 10px; }
.slot-row label { font-weight: 600; font-size: .85rem; display: grid; gap: 6px; }
.emoji-in { text-align: center; font-size: 1.6rem !important; padding: 6px !important; height: 50px; }

/* ---------- kalori ve antrenman barları (v1.1) ---------- */
.meter { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.meter .bar { flex: 1; margin-top: 0; }
.meter-emoji { width: 1.5rem; text-align: center; font-size: 1rem; line-height: 1; flex: none; }
.meter-small { margin-top: 10px; }
.meter-small .bar { height: 6px; }
.meter-small .meter-emoji { font-size: .85rem; }
.bar-fill.workout { background: var(--hab); }
.meter-note { margin: 3px 0 0; text-align: right; color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.workout-kcal { display: grid; gap: 6px; margin-top: 12px; font-size: .9rem; font-weight: 600; }
.workout-kcal small { color: var(--muted); font-weight: 400; }

/* ---------- hakkında (v1.1) ---------- */
.about-link {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; font-weight: 600; cursor: pointer; text-align: left;
}
.about-head { display: flex; align-items: center; gap: 12px; padding: 0; }
.about { text-align: center; padding: 20px 20px 16px; }
.about-logo { display: block; width: min(64%, 230px); height: auto; margin: 0 auto 14px; border-radius: 18px; }
.about h2 { font-size: 1.5rem; margin: 0; }
.about-tagline { color: var(--muted); margin: 2px 0 0; }
.about h3 { font-size: 1.05rem; margin: 20px 0 6px; }
.about p { margin: 0 0 6px; }
.about-foot { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); font-size: .9rem; }
.about-foot a { color: var(--accent); }
.about-foot .version { margin: 4px 0 0; }

/* ---------- kaydetme ve kayıt durumları (v1.2) ---------- */
.save-row { display: flex; gap: 8px; align-items: stretch; }
.save-row input { flex: 1; min-width: 0; }
.save-btn { width: auto; flex: none; padding: 8px 14px; }
.manual-fix .save-btn { padding: 6px 12px; }
.manual-fix span { flex: 1; min-width: 80px; }
.manual-fix { flex-wrap: wrap; }
.badge.unclear { background: var(--warn-soft); color: var(--warn); margin-left: 0; }
.entry textarea[data-edit] { margin-top: 10px; }
.confirm-box { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); }
.confirm-box p { margin: 0; color: var(--warn); font-size: .85rem; font-weight: 600; }
.prior-note {
  display: block; width: 100%; margin-top: 10px; padding: 8px 12px; text-align: left;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  color: var(--text); font-size: .85rem; cursor: pointer;
}
.prior-note[hidden] { display: none; }
