/* ===== ידיים — style ===== */
:root {
  --radius: 16px;
  --radius-sm: 10px;
  --gap: 14px;
  --nav-h: 64px;
  --header-h: 56px;
  --font: 'Heebo', 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
}
body[data-theme="dark"] {
  --bg: #1a1b26;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, #252a41 0%, #1a1b26 55%);
  --surface: #232637;
  --surface-2: #2b2f45;
  --surface-3: #343955;
  --text: #e6e9f5;
  --muted: #a7aecb;
  --accent: #7aa2f7;
  --accent-strong: #5d84e8;
  --good: #9ece6a;
  --good-deep: #4d6b2f;
  --warn: #e0af68;
  --bad: #f7768e;
  --purple: #bb9af7;
  --line: #3a3f5c;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
}
body[data-theme="light"] {
  --bg: #f3f5fb;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, #e6ebf9 0%, #f3f5fb 55%);
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --surface-3: #e2e7f2;
  --text: #1f2335;
  --muted: #5b6280;
  --accent: #3d59a1;
  --accent-strong: #2e4a8f;
  --good: #4c7a2e;
  --good-deep: #3a5d22;
  --warn: #9a6a1a;
  --bad: #c2405a;
  --purple: #7a52b3;
  --line: #d7dcea;
  --shadow: 0 6px 24px rgba(31,35,53,.10);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 12px);
  transition: background .25s, color .25s;
}

/* ===== Header ===== */
.app-header {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  max-width: 760px; margin: 0 auto; height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
}
.brand { display: flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.brand-mark { color: var(--accent); display: grid; place-items: center; }
.brand-name { font-weight: 800; font-size: 1.35rem; letter-spacing: .5px; }
.header-actions { display: flex; gap: 8px; }

.icon-btn {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  width: 40px; height: 40px; display: grid; place-items: center;
  cursor: pointer; transition: background .15s, transform .1s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(.95); }
.icon-btn.small { width: 30px; height: 30px; border-radius: 9px; font-size: .9rem; }
body[data-theme="dark"] .ic-sun { display: none; }
body[data-theme="light"] .ic-moon { display: none; }

/* ===== Layout ===== */
main { max-width: 760px; margin: 0 auto; padding: 18px 16px 8px; }
.view { display: flex; flex-direction: column; gap: var(--gap); animation: fadeUp .25s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px);} to { opacity: 1; transform: none; } }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 1.35rem; margin-bottom: 8px; }
.card h3 { font-size: 1.08rem; margin-bottom: 8px; }
.card p { line-height: 1.65; margin-bottom: 10px; }
.card p:last-child { margin-bottom: 0; }
.muted { color: var(--muted); }
.small-text { font-size: .85rem; }
.card-title-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.row { display: flex; align-items: center; }
.row.gap { gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.row.gap.col { flex-direction: column; align-items: stretch; }

/* ===== Buttons ===== */
.btn {
  font-family: var(--font); font-size: 1rem; font-weight: 600;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 12px 18px; cursor: pointer; color: var(--text);
  background: var(--surface-2);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .08s, background .15s, opacity .15s;
  min-height: 46px;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(.97); }
.btn.big { font-size: 1.1rem; padding: 15px 22px; width: 100%; }
.btn-primary { background: var(--accent); color: #fff; }
body[data-theme="light"] .btn-primary { color: #fff; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }

.quick-actions { display: flex; flex-direction: column; gap: 10px; }
.btn-urge {
  background: linear-gradient(135deg, var(--warn), #d4883e);
  color: #1d1405; font-size: 1.15rem; font-weight: 700; padding: 16px;
}
.btn-urge:hover { filter: brightness(1.06); background: linear-gradient(135deg, var(--warn), #d4883e); }
.btn-clean { background: var(--good-deep); color: #eaffd9; padding: 15px; font-size: 1.08rem; }
.btn-clean:hover { background: var(--good); color: #14270a; }
.btn-clean.done { background: var(--surface-2); color: var(--good); border-color: var(--good); cursor: default; }
.btn-slip { background: transparent; border-color: var(--line); color: var(--muted); }
.btn-slip:hover { color: var(--bad); border-color: var(--bad); background: color-mix(in srgb, var(--bad) 8%, transparent); }

/* ===== Streak hero ===== */
.streak-hero { text-align: center; padding: 26px 18px 20px; position: relative; overflow: hidden; }
.streak-label { color: var(--muted); font-weight: 600; letter-spacing: .4px; }
.streak-number {
  font-size: 4.6rem; font-weight: 800; line-height: 1.1;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.streak-sub { color: var(--muted); font-size: .92rem; margin-top: 2px; }
.streak-best { margin-top: 10px; display: inline-block; }
.chip {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 12px; font-size: .85rem; color: var(--muted);
}
.muted-chip { font-size: .78rem; }
.milestone-wrap { margin-top: 16px; text-align: right; }
.milestone-bar { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.milestone-fill { height: 100%; width: 0%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), var(--purple)); transition: width .6s ease; }
.milestone-text { font-size: .86rem; color: var(--muted); margin-top: 6px; }
.milestone-text b { color: var(--text); }

/* ===== Daily card / tips ===== */
.daily-quote { font-size: 1.12rem; line-height: 1.7; font-weight: 500; }
.tip-card p { color: var(--muted); line-height: 1.65; }

/* ===== Check lists ===== */
.check-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.check-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px 14px; cursor: pointer;
  transition: background .15s, border-color .15s; user-select: none;
}
.check-item:hover { background: var(--surface-3); }
.check-item .box {
  width: 22px; height: 22px; border-radius: 7px; flex-shrink: 0;
  border: 2px solid var(--muted); display: grid; place-items: center;
  color: transparent; transition: all .15s;
}
.check-item.on .box { background: var(--good); border-color: var(--good); color: #14270a; }
.check-item.on { border-color: color-mix(in srgb, var(--good) 55%, var(--line)); }
.check-item .txt { flex: 1; line-height: 1.45; }
.check-item.on .txt { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }

/* ===== Chips ===== */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip-btn {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 15px; font-size: .95rem; font-family: var(--font);
  cursor: pointer; transition: all .13s;
}
.chip-btn:hover { background: var(--surface-3); }
.chip-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ===== Segmented ===== */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; flex-wrap: wrap; }
.seg-btn {
  font-family: var(--font); border: none; background: transparent; color: var(--muted);
  padding: 9px 14px; border-radius: 9px; cursor: pointer; font-size: .95rem; font-weight: 500;
}
.seg-btn.on { background: var(--accent); color: #fff; font-weight: 700; }

/* ===== Form fields ===== */
.fld { display: block; margin: 14px 0; }
.fld > span { display: block; font-weight: 600; margin-bottom: 6px; font-size: .95rem; }
.fld input[type="text"], .fld input[type="time"], input[type="time"] {
  width: 100%; font-family: var(--font); font-size: 1rem; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; outline: none;
}
.fld input:focus { border-color: var(--accent); }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 34px; }

/* ===== SOS ===== */
.sos-hero h2 { font-size: 1.5rem; }
.sos-hero .btn { margin-top: 10px; }
.sos-steps { display: flex; gap: 6px; }
.sos-steps .dot { flex: 1; height: 5px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); }
.sos-steps .dot.on { background: var(--accent); border-color: var(--accent); }
.sos-step { text-align: center; }
.breath-stage { display: grid; place-items: center; padding: 22px 0 10px; }
.breath-circle {
  width: 170px; height: 170px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--accent) 55%, #fff 10%), var(--accent-strong));
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 1.15rem;
  box-shadow: 0 0 0 12px color-mix(in srgb, var(--accent) 15%, transparent), 0 0 60px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform 3.8s cubic-bezier(.4,.1,.4,1);
  transform: scale(.62);
}
.breath-circle.in { transform: scale(1); }
.breath-circle.out { transform: scale(.62); }
.breath-count { margin: 8px 0 4px; }
.wave-stage { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); margin: 12px 0; overflow: hidden; }
.wave-stage canvas { width: 100%; height: 110px; display: block; }
.wave-timer, .cr-timer {
  font-size: 2.6rem; font-weight: 800; text-align: center; color: var(--accent);
  font-variant-numeric: tabular-nums; margin: 6px 0;
}
.cr-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
@media (max-width: 420px) {
  .cr-options { grid-template-columns: 1fr; }
  .heatmap { grid-template-rows: repeat(7, 15px); grid-auto-columns: 15px; }
  .hm-cell { width: 15px; height: 15px; border-radius: 3px; }
}
.cr-opt {
  background: var(--surface-2); border: 2px solid var(--line); border-radius: var(--radius-sm);
  padding: 14px 12px; cursor: pointer; text-align: center; font-family: var(--font);
  color: var(--text); font-size: .98rem; transition: all .13s; line-height: 1.45;
}
.cr-opt:hover { background: var(--surface-3); }
.cr-opt.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--surface-2)); font-weight: 700; }
.distraction-card {
  background: var(--surface-2); border: 1px dashed var(--line); border-radius: var(--radius-sm);
  padding: 26px 16px; text-align: center; font-size: 1.12rem; line-height: 1.6; margin: 12px 0;
  min-height: 84px; display: grid; place-items: center;
}
.sos-win { text-align: center; }
.sos-win h3 { font-size: 1.4rem; color: var(--good); }

/* ===== Diary ===== */
.entries-list { display: flex; flex-direction: column; gap: 8px; }
.entry-row {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 11px 13px;
}
.entry-row .e-ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; font-size: 1.05rem; }
.entry-row .e-ic.resisted { background: color-mix(in srgb, var(--good) 22%, transparent); }
.entry-row .e-ic.slip { background: color-mix(in srgb, var(--bad) 20%, transparent); }
.entry-row .e-ic.awareness { background: color-mix(in srgb, var(--accent) 20%, transparent); }
.entry-row .e-body { flex: 1; min-width: 0; }
.entry-row .e-title { font-weight: 600; font-size: .97rem; }
.entry-row .e-meta { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.entry-row .e-note { color: var(--muted); font-size: .9rem; margin-top: 4px; line-height: 1.5; }
.entry-row .e-del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 4px; }
.entry-row .e-del:hover { color: var(--bad); }
.insights { display: flex; flex-direction: column; gap: 12px; }
.insight-block h4 { font-size: .92rem; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.insight-line { display: flex; align-items: center; gap: 8px; margin: 4px 0; font-size: .93rem; }
.insight-line .bar { height: 8px; border-radius: 99px; background: var(--accent); min-width: 4px; }
.hour-hist { display: flex; align-items: flex-end; gap: 3px; height: 60px; }
.hour-hist .hh { flex: 1; background: var(--surface-3); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.hour-hist .hh.hot { background: var(--warn); }

/* ===== Progress ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)); gap: 10px; }
.stat-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 10px; text-align: center; box-shadow: var(--shadow); }
.stat-box .v { font-size: 1.7rem; font-weight: 800; color: var(--accent); }
.stat-box .l { font-size: .82rem; color: var(--muted); margin-top: 2px; }
.heatmap { display: grid; grid-template-rows: repeat(7, 20px); grid-auto-columns: 20px; grid-auto-flow: column; gap: 4px; justify-content: center; margin: 12px 0; overflow-x: auto; padding-bottom: 4px; }
.hm-cell { width: 20px; height: 20px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--line); }
.hm-cell.clean { background: var(--good); border-color: var(--good); }
.hm-cell.urge { background: var(--warn); border-color: var(--warn); }
.hm-cell.slip { background: var(--bad); border-color: var(--bad); }
.hm-cell.future { opacity: .25; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: .82rem; color: var(--muted); }
.legend .lg { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-left: 5px; vertical-align: -1px; }
.lg-clean { background: var(--good); } .lg-urge { background: var(--warn); } .lg-slip { background: var(--bad); } .lg-none { background: var(--surface-2); border: 1px solid var(--line); }
.bars { display: flex; align-items: flex-end; gap: 5px; height: 120px; margin-top: 12px; }
.bars .b-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bars .b { width: 100%; max-width: 34px; border-radius: 6px 6px 0 0; background: var(--accent); min-height: 3px; position: relative; }
.bars .b.res { background: var(--good); }
.bars .b-l { font-size: .68rem; color: var(--muted); }
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 10px; }
.ach {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 13px 12px; text-align: center;
}
.ach.locked { opacity: .45; }
.ach .a-ic { font-size: 1.5rem; }
.ach .a-name { font-weight: 700; font-size: .92rem; margin-top: 4px; }
.ach .a-desc { color: var(--muted); font-size: .78rem; margin-top: 3px; line-height: 1.4; }
.ach .a-prog { height: 5px; background: var(--surface-3); border-radius: 99px; margin-top: 8px; overflow: hidden; }
.ach .a-prog i { display: block; height: 100%; background: var(--good); border-radius: 99px; }

/* ===== Learn ===== */
.learn-item { overflow: hidden; padding: 0; }
.learn-head {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: none; border: none; color: var(--text); font-family: var(--font);
  padding: 16px 18px; cursor: pointer; text-align: right;
}
.learn-head h3 { margin: 0; font-size: 1.05rem; }
.learn-head .chev { transition: transform .2s; color: var(--muted); flex-shrink: 0; }
.learn-item.open .learn-head .chev { transform: rotate(180deg); }
.learn-body { padding: 0 18px 18px; display: none; }
.learn-item.open .learn-body { display: block; }
.learn-body p, .learn-body li { line-height: 1.75; }
.learn-body ul, .learn-body ol { padding-right: 20px; margin: 8px 0; }
.learn-body li { margin: 5px 0; }
.learn-body .src { font-size: .83rem; color: var(--muted); margin-top: 10px; }
.learn-body a { color: var(--accent); word-break: break-all; }
.learn-body .step-box { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; margin: 8px 0; }
.learn-body .step-box b { color: var(--accent); }

/* ===== Bottom nav ===== */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; align-items: stretch;
}
.nav-btn {
  flex: 1; background: none; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-family: var(--font); font-size: .72rem; cursor: pointer; padding: 6px 2px;
  border-top: 2px solid transparent;
}
.nav-btn span { font-weight: 600; }
.nav-btn.on { color: var(--accent); }
.nav-btn.nav-sos.on { color: var(--warn); }

/* ===== Modals ===== */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(8,10,18,.6); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 18px;
  animation: fadeIn .18s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-card { width: 100%; max-width: 440px; max-height: 86vh; overflow-y: auto; }
.onboard-card h2 { margin-bottom: 10px; }
.onboard-card .btn.big { margin-top: 16px; }
.settings-list { display: flex; flex-direction: column; gap: 16px; margin-top: 8px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.settings-row.col { flex-direction: column; align-items: stretch; }
.settings-row > span { font-weight: 500; }

/* ===== Toast ===== */
#toast {
  position: fixed; bottom: calc(var(--nav-h) + 16px); left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--surface-3); color: var(--text); border: 1px solid var(--line);
  padding: 12px 20px; border-radius: 999px; font-weight: 600; font-size: .95rem;
  opacity: 0; pointer-events: none; transition: all .25s; z-index: 200; box-shadow: var(--shadow);
  max-width: 88vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== Confetti ===== */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 300; }

/* ===== Desktop ===== */
@media (min-width: 720px) {
  main { padding-top: 26px; }
  .streak-number { font-size: 5.4rem; }
  .quick-actions { flex-direction: row; }
  .quick-actions .btn { flex: 1; }
  .quick-actions .btn-slip { flex: .6; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
