:root {
  --bg: #f4f1ea; --panel: #ffffff; --text: #1f2a24; --muted: #6f7a72; --line: #e3ded2;
  --accent: #2f6f4e; --accent-ink: #ffffff; --danger: #b3261e; --chip: #e9e5da;
  --radius: 18px; --sat: env(safe-area-inset-top); --sab: env(safe-area-inset-bottom);
  --card-l: 90%; --card-s: 55%; --hero-l: 34%;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141a16; --panel: #1d2520; --text: #eef3ee; --muted: #9aa89e; --line: #2d3832;
    --accent: #6fcf9a; --accent-ink: #0f1a13; --danger: #f2827a; --chip: #26302a;
    --card-l: 22%; --card-s: 35%; --hero-l: 26%;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.45 ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, system-ui, sans-serif; }
button, input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- navegação ---------- */
.app { max-width: 1100px; margin: 0 auto; padding: 0 16px calc(90px + var(--sab)); }
.top { position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; align-items: center; background: var(--bg);
  padding: calc(12px + var(--sat)) 0 8px; }
.top h1 { margin: 0 8px 0 0; font-size: 26px; letter-spacing: -.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .sp { flex: 1; }
.top .search { max-width: 420px; }
.sync { color: var(--muted); font-size: 12px; padding: 0 4px 8px; min-height: 16px; }
.sync.err { color: var(--danger); }
#btnBack { font-size: 30px; line-height: 1; padding: 2px 10px; color: var(--accent); }
.search { flex: 1; min-width: 0; }
.search input { width: 100%; border: 0; background: var(--chip); border-radius: 14px; padding: 11px 14px; outline: none; }
.search input:focus { box-shadow: 0 0 0 2px var(--accent); }
.icon-btn { background: none; border: 0; font-size: 22px; padding: 6px 8px; border-radius: 10px; cursor: pointer; color: var(--muted); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 14px; padding: 11px 16px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.btn-secondary { background: var(--chip); border: 0; border-radius: 12px; padding: 11px 14px; cursor: pointer; font-weight: 600; }


/* ---------- categorias (tiles) ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.tile { text-align: left; border: 0; cursor: pointer; border-radius: var(--radius); padding: 16px; min-height: 120px; display: flex; flex-direction: column;
  background: hsl(var(--h) var(--card-s) var(--card-l)); color: var(--text); transition: transform .12s; }
.tile:active { transform: scale(.97); }
.t-ico { font-size: 30px; }
.t-name { font-weight: 800; font-size: 17px; line-height: 1.2; margin-top: auto; padding-top: 12px; letter-spacing: -.2px; }
.t-n { font-size: 13px; opacity: .65; margin-top: 2px; }
.sub { color: var(--muted); font-size: 13px; padding: 4px 4px 10px; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }

/* ---------- lista de receitas de uma categoria ---------- */
.cat-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-radius: var(--radius); margin-bottom: 12px;
  background: hsl(var(--h) var(--card-s) var(--card-l)); font-size: 20px; }
.cat-head span { font-size: 28px; }
.cat-head b { flex: 1; letter-spacing: -.3px; }
.cat-head em { font-style: normal; opacity: .6; font-size: 15px; }
.rows { display: flex; flex-direction: column; gap: 8px; }
.row-item { display: flex; flex-direction: column; gap: 3px; text-align: left; width: 100%; border: 0; cursor: pointer; background: var(--panel);
  border-radius: 14px; padding: 14px 16px; }
.row-item:active { transform: scale(.99); }
.ri-name { font-weight: 700; font-size: 17px; }
.ri-cat { font-size: 13px; color: var(--accent); font-weight: 600; }
.ri-note { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- leitura: nome, link e notas em texto corrido ---------- */
.read { max-width: 720px; margin: 0 auto; }
.crumb { display: inline-block; font-size: 14px; font-weight: 700; padding: 4px 12px; border-radius: 999px; background: hsl(var(--h) var(--card-s) var(--card-l)); }
.read h2 { font-size: 32px; line-height: 1.12; letter-spacing: -.7px; margin: 12px 0 14px; }
.linkcard { display: block; padding: 13px 16px; border-radius: 14px; background: var(--panel); color: var(--accent); text-decoration: none; margin-bottom: 16px;
  word-break: break-all; font-weight: 700; }
.notes { white-space: pre-wrap; font-size: 18px; line-height: 1.6; }
.notes a { color: var(--accent); font-weight: 600; word-break: break-all; }
.muted { color: var(--muted); }

/* ---------- editor / configurações ---------- */
dialog.sheet { border: 0; padding: 0; background: var(--panel); color: var(--text); width: min(640px, 100vw); max-width: 100vw;
  height: min(92dvh, 860px); border-radius: 22px; box-shadow: 0 20px 60px #0007; }
dialog.sheet.small { height: auto; max-height: 90dvh; }
dialog::backdrop { background: #0007; }
dialog form { display: flex; flex-direction: column; height: 100%; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px 8px; }
.link-btn.strong { color: var(--accent-ink); background: var(--accent); border-radius: 999px; font-weight: 800; padding: 7px 18px; }
.sheet-body { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; flex: 1; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.grow { flex: 1; min-height: 0; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.field input, .field textarea { border: 0; background: var(--chip); border-radius: 12px; padding: 12px 14px; outline: none; width: 100%; font-size: 16px; }
.field textarea { resize: none; flex: 1; min-height: 220px; line-height: 1.5; }
.field input:focus, .field textarea:focus { box-shadow: 0 0 0 2px var(--accent); }
#edName { font-size: 20px; font-weight: 700; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }
.seg { display: flex; background: var(--chip); border-radius: 14px; padding: 4px; }
.seg button { flex: 1; border: 0; background: none; padding: 9px; border-radius: 11px; cursor: pointer; font-weight: 600; }
.seg button.on { background: var(--panel); box-shadow: 0 1px 4px #0003; }
.pick { display: flex; flex-wrap: wrap; gap: 6px; }
.pick button { border: 0; background: var(--chip); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 14px; }
.pick button.on { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
code { background: var(--chip); padding: 0 4px; border-radius: 4px; }
.danger { background: none; border: 1px solid var(--danger); color: var(--danger); border-radius: 12px; padding: 11px; cursor: pointer; }

.toast { position: fixed; left: 50%; bottom: calc(24px + var(--sab)); transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 20px; font-size: 14px; z-index: 99; max-width: 90vw; }

/* ---------- celular ---------- */
@media (max-width: 700px) {
  .app { padding-left: 14px; padding-right: 14px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .hide-mobile { display: none; }
  .btn-primary { position: fixed; right: 18px; bottom: calc(18px + var(--sab)); z-index: 6; width: 60px; height: 60px; border-radius: 50%;
    font-size: 30px; padding: 0; box-shadow: 0 6px 20px #0005; }
  .top h1 { display: none; }
  dialog.sheet { width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .sheet-head { padding-top: calc(14px + var(--sat)); }
}
