:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --ink: #1c2420;
  --ink2: #5d6a63;
  --ink3: #98a39d;
  --line: #e6e1d6;
  --accent: #0f6b58;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe8;
  --gold: #c9962e;
  --gold-soft: #fbf0d6;
  --danger: #c2412d;
  --danger-soft: #fbe3de;
  --ring: #d9472b;
  --shadow: 0 1px 2px rgba(40, 35, 20, .06), 0 4px 14px rgba(40, 35, 20, .05);
  --r: 18px;
  --kb: 0px;
  --tabs-h: calc(62px + env(safe-area-inset-bottom));
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --card: #1c221f;
    --ink: #eaf0ec;
    --ink2: #a7b4ad;
    --ink3: #6c7a73;
    --line: #2b3430;
    --accent: #3fb391;
    --accent-ink: #08241c;
    --accent-soft: #1d3a31;
    --gold: #e2b65a;
    --gold-soft: #3a3020;
    --danger: #f07a63;
    --danger-soft: #3d221d;
    --ring: #ff7a5c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  padding-bottom: calc(var(--tabs-h) + 90px);
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.top-row { display: flex; align-items: center; gap: 10px; }
.top h1 { font-size: 30px; letter-spacing: -.02em; margin: 0; flex: 1; font-weight: 750; }
.sync { width: 9px; height: 9px; border-radius: 50%; background: var(--ink3); transition: background .3s; }
.sync.ok { background: var(--accent); }
.sync.busy { background: var(--gold); }
.sync.err { background: var(--danger); }

.seg { display: flex; background: color-mix(in srgb, var(--ink) 7%, transparent); border-radius: 12px; padding: 3px; margin-top: 10px; }
.seg button { flex: 1; padding: 7px 0; border-radius: 9px; font-weight: 600; font-size: 15px; color: var(--ink2); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

main { padding: 6px 16px 0; max-width: 680px; margin: 0 auto; }

/* ---------- ringing strip ---------- */
.ringing { background: var(--danger-soft); border-radius: var(--r); padding: 10px 12px; margin: 6px 0 14px; }
.ringing h3 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ring); display: flex; align-items: center; gap: 6px; }
.ring-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid color-mix(in srgb, var(--ring) 18%, transparent); }
.ring-row:first-of-type { border-top: 0; }
.ring-row .t { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini { padding: 6px 11px; border-radius: 999px; font-size: 14px; font-weight: 600; background: var(--card); }
.mini.go { background: var(--accent); color: var(--accent-ink); }

/* ---------- heading cards ---------- */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); margin-bottom: 14px; overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 4px; padding: 12px 8px 6px 6px; }
.chev { width: 34px; height: 34px; display: grid; place-items: center; color: var(--ink3); transition: transform .2s; }
.card.closed .chev { transform: rotate(-90deg); }
.card-head h2 { flex: 1; margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -.01em; cursor: text; min-width: 0; overflow-wrap: anywhere; }
.count { font-size: 13px; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 2px 9px; }
.count:empty { display: none; }
.icon { width: 38px; height: 38px; display: grid; place-items: center; color: var(--ink2); border-radius: 10px; }
.icon svg, .tabs svg, .bell svg, .chev svg { fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.card.closed .items, .card.closed .add-row, .card.closed .done-wrap { display: none; }

.items { list-style: none; margin: 0; padding: 0; min-height: 6px; }
.item { position: relative; overflow: hidden; }
.item .del-bg { position: absolute; inset: 0; background: var(--danger); color: #fff; display: flex; align-items: center; justify-content: flex-end; padding-right: 20px; font-weight: 700; }
.row { position: relative; display: flex; align-items: flex-start; gap: 10px; padding: 9px 6px 9px 12px; background: var(--card); touch-action: pan-y; }
.item + .item .row { border-top: 1px solid var(--line); }
.check {
  flex: none; width: 25px; height: 25px; margin-top: 1px; border-radius: 50%;
  border: 2px solid var(--ink3); display: grid; place-items: center; transition: all .15s;
}
.check svg { opacity: 0; stroke: var(--accent-ink); stroke-width: 3; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.item.done .check { background: var(--accent); border-color: var(--accent); }
.item.done .check svg { opacity: 1; }
.item.done .t { color: var(--ink3); text-decoration: line-through; }
.txt { flex: 1; min-width: 0; padding-top: 2px; cursor: pointer; }
.txt .t { overflow-wrap: anywhere; white-space: pre-wrap; }
.meta { font-size: 13px; color: var(--ink2); margin-top: 2px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.meta .rem { color: var(--accent); font-weight: 600; }
.meta .rem.hot { color: var(--ring); }
.meta .note { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.bell { flex: none; width: 36px; height: 32px; display: grid; place-items: center; color: var(--ink3); border-radius: 9px; }
.bell.on { color: var(--accent); }
.bell.hot { color: var(--ring); animation: wiggle 1.4s ease-in-out infinite; }
@keyframes wiggle { 0%, 70%, 100% { transform: rotate(0) } 76% { transform: rotate(14deg) } 84% { transform: rotate(-12deg) } 92% { transform: rotate(6deg) } }
.item.flash .row { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { background: var(--gold-soft) } 100% { background: var(--card) } }
.sortable-ghost .row { background: var(--accent-soft); }
.sortable-chosen .row { box-shadow: 0 8px 24px rgba(0,0,0,.15); }

.add-row { display: flex; align-items: center; gap: 10px; padding: 6px 10px 10px 13px; border-top: 1px solid var(--line); }
.add-row .plus { width: 23px; height: 23px; flex: none; color: var(--accent); }
.add-row input { flex: 1; border: 0; outline: 0; background: none; padding: 8px 0; font-size: 16px; }
.add-row input::placeholder { color: var(--ink3); }

.done-wrap { border-top: 1px solid var(--line); }
.done-toggle { display: flex; width: 100%; align-items: center; justify-content: space-between; padding: 9px 14px; font-size: 14px; color: var(--ink2); font-weight: 600; }
.done-toggle .clear { color: var(--danger); font-weight: 600; }

.new-heading { width: 100%; padding: 15px; border-radius: var(--r); border: 2px dashed var(--line); color: var(--ink2); font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px; }
.heading-input { width: 100%; border: 0; outline: 0; background: none; font-size: 19px; font-weight: 700; padding: 14px 16px; }

.empty { text-align: center; color: var(--ink2); padding: 40px 20px; }
.empty .big { font-size: 46px; margin-bottom: 8px; }
.placeholder { background: var(--card); border-radius: var(--r); padding: 28px 22px; text-align: center; box-shadow: var(--shadow); color: var(--ink2); }
.placeholder h2 { color: var(--ink); margin: 6px 0 8px; font-size: 21px; }
.placeholder .big { font-size: 44px; }

/* ---------- FAB + tabs ---------- */
.fab {
  position: fixed; right: 18px; bottom: calc(var(--tabs-h) + 16px); z-index: 25;
  width: 60px; height: 60px; border-radius: 20px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 45%, transparent);
  transition: transform .15s;
}
.fab:active { transform: scale(.93); }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex;
  height: var(--tabs-h); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 90%, transparent); border-top: 1px solid var(--line);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
}
.tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--ink3); font-size: 11px; font-weight: 600; }
.tabs button svg { width: 25px; height: 25px; }
.tabs button.on { color: var(--accent); }

/* ---------- sheets ---------- */
#sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-bg { position: absolute; inset: 0; background: rgba(10, 14, 12, .38); opacity: 0; transition: opacity .22s; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: var(--kb); max-width: 680px; margin: 0 auto;
  max-height: calc(100% - var(--kb) - env(safe-area-inset-top) - 24px); overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--card); border-radius: 22px 22px 0 0; padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .26s cubic-bezier(.2, .8, .2, 1), bottom .15s;
}
#sheet.open .sheet-bg { opacity: 1; }
#sheet.open .sheet-panel { transform: none; }
.grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-head b { font-size: 17px; }
.sheet-head button { color: var(--accent); font-weight: 600; padding: 8px 4px; font-size: 16px; }
.sheet-head button.primary { font-weight: 750; }
.field { width: 100%; border: 1.5px solid var(--line); background: var(--bg); border-radius: 12px; padding: 11px 12px; outline: 0; font-size: 16px; }
.field:focus { border-color: var(--accent); }
textarea.field { resize: none; min-height: 48px; }
.big-input { font-size: 19px; font-weight: 600; }
.lbl { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ink2); margin: 16px 0 8px; display: block; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip { padding: 8px 13px; border-radius: 999px; background: color-mix(in srgb, var(--ink) 7%, transparent); font-size: 15px; font-weight: 600; color: var(--ink); }
.chip.on { background: var(--accent); color: var(--accent-ink); }
.chip.add { color: var(--accent); background: var(--accent-soft); }
.hint { font-size: 13px; color: var(--ink2); margin-top: 8px; }
.row2 { display: flex; gap: 8px; align-items: center; }
.btn { display: block; width: 100%; padding: 14px; border-radius: 14px; font-weight: 700; font-size: 17px; text-align: center; background: color-mix(in srgb, var(--ink) 7%, transparent); }
.btn.go { background: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); background: var(--danger-soft); }
.btn + .btn { margin-top: 10px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; }
.toggle input { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 15px; background: var(--line); position: relative; transition: background .2s; flex: none; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.toggle input:checked { background: var(--accent); }
.toggle input:checked::after { transform: translateX(20px); }
.menu-btn { display: flex; width: 100%; align-items: center; gap: 12px; padding: 15px 6px; font-size: 17px; border-bottom: 1px solid var(--line); text-align: left; }
.menu-btn:last-child { border-bottom: 0; }
.menu-btn.danger { color: var(--danger); }

/* ring sheet */
.ring-hero { text-align: center; padding: 10px 0 6px; }
.ring-hero .bellbig { font-size: 50px; animation: wiggle 1.4s ease-in-out infinite; display: inline-block; }
.ring-hero h2 { margin: 8px 0 4px; font-size: 23px; overflow-wrap: anywhere; }
.ring-hero p { margin: 2px 0; color: var(--ink2); }

/* ---------- settings ---------- */
.set-card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 14px; }
.set-card h2 { font-size: 17px; margin: 0 0 6px; }
.set-card p { margin: 6px 0; color: var(--ink2); font-size: 15px; }
.status { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 15px; }
.status i { width: 9px; height: 9px; border-radius: 50%; background: var(--ink3); flex: none; }
.status.ok i { background: var(--accent); }
.status.bad i { background: var(--danger); }
.steps { margin: 6px 0; padding-left: 20px; color: var(--ink2); font-size: 15px; }
.steps li { margin: 4px 0; }
.time-in { width: 110px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 92px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: all .22s;
  background: var(--ink); color: var(--bg); border-radius: 14px; padding: 11px 14px 11px 16px;
  display: flex; align-items: center; gap: 14px; font-weight: 600; font-size: 15px; max-width: calc(100% - 32px); box-shadow: 0 8px 26px rgba(0,0,0,.25);
}
body.sheet-open #toast { bottom: auto; top: calc(env(safe-area-inset-top) + 12px); transform: translate(-50%, -20px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { color: var(--gold); font-weight: 800; }

@media (min-width: 700px) { .top h1 { font-size: 34px; } }
