:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #2b2f2e;
  --muted: #6b706d;
  --line: #e2ddd2;
  --primary: #8b5e3c;
  --primary-dark: #6e4a2e;
  --primary-soft: #f3ece4;
  --gold: #c4a046;
  --gold-soft: #f6efdc;
  --green: #3f8f7a;
  --green-soft: #e4f1ec;
  --danger: #b0543e;
  --warn: #c47a20;
  --warn-soft: #fdf0dc;
  --radius: 16px;
  --nav-h: 72px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { font-size: 19px; -webkit-text-size-adjust: 100%; }
@media (min-width: 420px) { html { font-size: 20px; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
input, select, textarea { touch-action: manipulation; }
[hidden] { display: none !important; }

/* Üst bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 14px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: rgba(255,255,255,.96);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--primary-dark); min-width: 0; }
.brand-icon { font-size: 1.8rem; line-height: 1; }
.brand-text { font-weight: 700; font-size: 1rem; line-height: 1.1; }
.brand-text small { font-weight: 400; font-size: .62em; color: #a9b3ae; letter-spacing: .02em; }
.user-chip {
  border: 1.5px solid var(--primary); background: var(--primary-soft); color: var(--primary-dark);
  border-radius: 999px; padding: 6px 14px; font-weight: 600; font-size: .9rem;
  max-width: 48vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Ana alan */
.app {
  max-width: 640px; margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 24px);
  min-height: 100vh; min-height: 100dvh;
}
.app.has-actions { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 110px); }
body.typing .app.has-actions { padding-bottom: 140px; }
.loading { text-align: center; padding: 60px 0; color: var(--muted); }

h1 { font-size: 1.5rem; margin: 6px 0 6px; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 26px 0 10px; }
.lead { font-size: 1.05rem; color: var(--muted); margin: 0 0 18px; }
.muted { color: var(--muted); }
.center { text-align: center; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}

/* Butonlar */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 60px; padding: 12px 18px;
  border-radius: 14px; border: 2px solid var(--line); background: #fff;
  font-size: 1.1rem; font-weight: 600; text-decoration: none; color: var(--ink);
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-soft { background: var(--primary-soft); border-color: transparent; color: var(--primary-dark); }
.btn-green { background: var(--green); border-color: var(--green); color: #fff; }
.btn-ghost { background: transparent; border-style: dashed; color: var(--muted); }
.btn-danger { color: var(--danger); border-color: #ecd2ca; }
.btn-danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { min-height: 46px; font-size: 1rem; padding: 8px 14px; width: auto; }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* Kullanıcı seçimi */
.user-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.user-btn {
  min-height: 90px; border-radius: 18px; border: 2.5px solid var(--line); background: #fff;
  font-size: 1.2rem; font-weight: 700; padding: 12px;
  user-select: none; -webkit-user-select: none;
}
.user-btn.placeholder { color: #bdb8ae; font-weight: 400; border-style: dashed; font-size: 1rem; }
.user-btn.current { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); }

/* Tarih çubuğu */
.datebar {
  display: flex; align-items: center; gap: 8px; margin-bottom: 14px;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 6px;
}
.datebar .arrow {
  flex: none; width: 52px; height: 52px; border-radius: 12px; border: none; background: var(--bg);
  font-size: 1.4rem; color: var(--primary-dark);
}
.datebar .arrow:disabled { opacity: .3; }
.datebar label { flex: 1; text-align: center; position: relative; cursor: pointer; }
.datebar .date-main { font-weight: 700; font-size: 1.1rem; display: block; }
.datebar .date-sub { font-size: .85rem; color: var(--muted); display: block; }
.datebar .date-sub.today { color: var(--primary); font-weight: 600; }
.datebar input[type=date] { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; }

/* Giriş formu */
.form-section { margin-bottom: 22px; }
.form-label { display: block; font-weight: 700; font-size: 1.05rem; margin-bottom: 10px; color: var(--ink); }
.form-label .sub { font-weight: 400; font-size: .85rem; color: var(--muted); margin-left: 8px; }

.code-input-wrap { position: relative; }
.code-input {
  width: 100%; height: 80px; border-radius: 14px; border: 2.5px solid #cfc9bc; background: #fff;
  text-align: center; font-size: 2.4rem; font-weight: 800; letter-spacing: .25em;
  padding: 0 14px;
}
.code-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.code-input::placeholder { letter-spacing: normal; font-size: 1rem; font-weight: 400; color: #c5c0b8; }

.code-warn {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--warn-soft); border: 1.5px solid #e8c070; border-radius: 12px;
  padding: 12px 14px; margin-top: 8px; font-size: .95rem;
}
.code-warn .ic { font-size: 1.2rem; flex: none; margin-top: 1px; }
.code-warn b { display: block; font-size: 1rem; color: var(--warn); }

.nb-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.nb-btn {
  min-height: 76px; border-radius: 16px; border: 2.5px solid var(--line); background: #fff;
  font-size: 1.1rem; font-weight: 700; padding: 12px; text-align: center; line-height: 1.25;
  user-select: none; -webkit-user-select: none;
}
.nb-btn.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); box-shadow: 0 0 0 3px var(--primary-soft); }

.text-input {
  width: 100%; min-height: 58px; border-radius: 12px; border: 2px solid #cfc9bc; background: #fff;
  padding: 10px 14px; font-size: 1.15rem;
}
.text-input:focus { outline: none; border-color: var(--primary); }
.text-input::placeholder { color: #c5c0b8; }

.amount-wrap { position: relative; }
.amount-prefix {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  font-size: 1.5rem; font-weight: 700; color: var(--gold); pointer-events: none;
}
.amount-input {
  width: 100%; height: 70px; border-radius: 14px; border: 2.5px solid #cfc9bc; background: #fff;
  padding: 0 14px 0 44px; font-size: 1.9rem; font-weight: 800; text-align: right;
}
.amount-input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 4px var(--gold-soft); }
.amount-input::placeholder { font-size: 1.1rem; font-weight: 400; color: #c5c0b8; text-align: right; }

/* Kaydet butonu (sabit alt) */
.actions {
  position: fixed; left: 0; right: 0; z-index: 15;
  bottom: calc(var(--nav-h) + var(--safe-b));
  padding: 10px 16px; background: rgba(246,244,239,.97); border-top: 1px solid var(--line);
}
.actions-inner { max-width: 640px; margin: 0 auto; display: flex; gap: 10px; }
.actions .btn { min-height: 64px; font-size: 1.15rem; }
body.typing .bottomnav { display: none; }
body.typing .actions { bottom: 0; padding-bottom: calc(10px + var(--safe-b)); }

/* Alt menü */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: #fff; border-top: 1px solid var(--line);
}
.bottomnav button {
  flex: 1; border: none; background: none; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; font-size: .78rem; font-weight: 600; color: var(--muted);
}
.bottomnav .ic { font-size: 1.45rem; line-height: 1; }
.bottomnav button.on { color: var(--primary-dark); }
.bottomnav button.on .ic { background: var(--primary-soft); border-radius: 999px; padding: 3px 16px; }

/* Başarı banner */
.saved-banner {
  display: flex; align-items: flex-start; gap: 14px; padding: 18px 16px; border-radius: var(--radius);
  background: var(--green-soft); border: 1.5px solid #a8d8c8; color: #1a5244; font-weight: 600; font-size: 1rem; margin-bottom: 18px;
}
.saved-banner .ok { width: 48px; height: 48px; border-radius: 50%; background: var(--green); color: #fff;
  display: grid; place-items: center; font-size: 1.5rem; flex: none; }
.saved-banner .ok-code { font-size: 1.7rem; font-weight: 800; letter-spacing: .12em; }
.saved-banner .ok-detail { font-size: .95rem; color: #2d7060; margin-top: 3px; }
.saved-banner .ok-next { font-size: .88rem; color: #4a9a84; margin-top: 6px; font-weight: 500; }

/* İstatistik kartları */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-width: 0; }
.stat .v { font-size: 1.6rem; font-weight: 800; line-height: 1.1; }
.stat .l { font-size: .92rem; color: var(--muted); font-weight: 600; }
.stat.total { background: var(--primary); border-color: var(--primary); color: #fff; }
.stat.total .l { color: rgba(255,255,255,.85); }
.stat.gold { background: var(--gold); border-color: var(--gold); color: #fff; }
.stat.gold .l { color: rgba(255,255,255,.85); }

/* Liste satırları */
.day-group { margin-bottom: 14px; }
.day-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.day-head h3 { margin: 0; font-size: 1.05rem; }
.row-item { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.row-item:first-child { border-top: none; }
.row-item .main { flex: 1; min-width: 0; }
.row-item .main b { display: block; }
.row-item .main small { color: var(--muted); font-size: .9rem; }
.row-item .amount { font-size: 1.25rem; font-weight: 800; color: var(--gold); min-width: 72px; text-align: right; }
.code-tag {
  display: inline-block; background: #ebe7de; border-radius: 8px; padding: 2px 10px;
  font-size: .9rem; font-weight: 800; letter-spacing: .1em; color: var(--ink);
}
.icon-btn { width: 48px; height: 48px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; font-size: 1.15rem; }

/* Sekmeler */
.seg { display: flex; background: #ebe7de; border-radius: 14px; padding: 4px; gap: 4px; margin-bottom: 12px; }
.seg button { flex: 1; min-height: 50px; border: none; border-radius: 11px; background: none; font-weight: 600; font-size: 1.02rem; color: var(--muted); }
.seg button.on { background: #fff; color: var(--primary-dark); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* Yatay çubuklar */
.hbar + .hbar { margin-top: 14px; }
.hbar-top { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.hbar-top b { font-size: 1.1rem; }
.hbar-track { display: flex; height: 14px; background: #efebe3; border-radius: 7px; overflow: hidden; margin-top: 4px; }
.hbar-track span { display: block; height: 100%; background: var(--primary); }
.hbar-sub { font-size: .85rem; color: var(--muted); margin-top: 3px; }
.chart svg { display: block; width: 100%; height: auto; }
.empty { text-align: center; color: var(--muted); padding: 22px 8px; }

/* Ayarlar */
.setting-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.setting-row:first-of-type { border-top: none; }
.setting-row .main { flex: 1; min-width: 0; }
.setting-row.off .main { color: var(--muted); text-decoration: line-through; }
details.admin { margin-top: 26px; }
details.admin > summary { cursor: pointer; font-weight: 700; padding: 14px 0; color: var(--muted); }

/* Form alanları (modal) */
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-weight: 600; margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 58px; border-radius: 12px; border: 2px solid #cfc9bc; background: #fff; padding: 8px 14px; font-size: 1.15rem;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); }
.field textarea { min-height: 80px; resize: vertical; }

/* Bildirim ve pencere */
.toast {
  position: fixed; left: 50%; top: 80px; transform: translate(-50%, -20px); z-index: 60;
  background: var(--ink); color: #fff; padding: 14px 22px; border-radius: 14px; font-weight: 600; font-size: 1.05rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); }

.modal {
  position: fixed; inset: 0; z-index: 50; background: rgba(30,35,33,.45);
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
}
.modal-box {
  background: #fff; width: 100%; max-width: 560px; border-radius: 22px 22px 0 0;
  padding: 22px 18px calc(18px + var(--safe-b)); max-height: 92vh; overflow: auto;
  -webkit-overflow-scrolling: touch;
}
@media (min-width: 600px) { .modal { align-items: center; } .modal-box { border-radius: 22px; } }
.modal-box h3 { margin: 0 0 8px; font-size: 1.3rem; }
.modal-box p { margin: 0 0 14px; color: var(--muted); }
.modal-box .btn-row { margin-top: 16px; }

/* Dönem gezgini */
.period-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.period-nav .arrow {
  flex: none; width: 52px; height: 52px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff;
  font-size: 1.4rem; color: var(--primary-dark);
}
.period-nav .period-label { flex: 1; text-align: center; font-weight: 700; font-size: 1.1rem; }

/* Hint */
.hint { font-size: .95rem; color: var(--muted); text-align: center; margin: 8px 0 0; }

/* Tanıtım turu */
.intro { display: flex; flex-direction: column; min-height: calc(100vh - 120px); min-height: calc(100dvh - 120px); }
.intro-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.intro-count { color: var(--muted); font-weight: 600; font-size: 1rem; }
.intro-skip { border: 1.5px solid var(--line); background: #fff; border-radius: 999px; padding: 10px 18px; font-weight: 600; color: var(--muted); font-size: 1rem; }
.intro-icon {
  flex: none; display: flex; align-items: center; justify-content: center;
  font-size: 5.5rem; line-height: 1; margin: 10px 0 20px;
  background: var(--primary-soft); border-radius: 28px; padding: 24px; width: 140px; align-self: center;
}
.intro h1 { text-align: center; font-size: 1.7rem; color: var(--primary-dark); margin-bottom: 12px; }
.intro-text { text-align: center; font-size: 1.15rem; line-height: 1.6; margin: 0 0 16px; }
.intro-dots { display: flex; justify-content: center; gap: 8px; margin-bottom: 18px; }
.intro-dots span { width: 10px; height: 10px; border-radius: 50%; background: #d6d1c5; }
.intro-dots span.on { background: var(--primary); width: 28px; border-radius: 6px; }
.intro .btn { min-height: 68px; font-size: 1.2rem; }
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: #ebe7de; color: var(--muted); vertical-align: 3px; }

/* Aile eşleştirme */
.match-list { display: grid; gap: 10px; margin-top: 10px; }
.match-card {
  display: block; width: 100%; text-align: left; border: 2.5px solid var(--line); background: #fff;
  border-radius: 14px; padding: 12px 14px; line-height: 1.35;
}
.match-card.on { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 3px var(--primary-soft); }
.match-card.warn { border-color: #e8c070; }
.match-card.warn.on { border-color: var(--primary); }
.match-card b { display: block; font-size: 1.05rem; }
.match-card small { display: block; color: var(--muted); font-size: .9rem; }
.match-card .hit { color: var(--warn); }
.match-new { border-style: dashed; color: var(--muted); font-weight: 600; text-align: center; }
.code-info { background: var(--primary-soft); border-radius: 12px; padding: 12px 14px; margin-top: 8px; font-size: .95rem; }
.code-info b { color: var(--primary-dark); }
.type-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.type-grid .nb-btn { min-height: 54px; flex: 1 1 calc(33% - 10px); font-size: 1rem; padding: 8px 10px; }
button.code-tag { border: none; cursor: pointer; text-decoration: underline; text-decoration-color: #bdb8ae; text-underline-offset: 3px; }
.link-btn { background: none; border: none; padding: 0; color: var(--primary); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.tree-links { display: grid; gap: 6px; }
.row-item.other { opacity: .7; }
.check-line { display: flex; align-items: center; gap: 10px; font-weight: 600; margin: 4px 0 6px; }
.check-line input { width: 22px; height: 22px; }
.setting-row .main small { display: block; color: var(--muted); font-size: .85rem; }
