:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --text: #1d1f1c;
  --muted: #6b6f68;
  --line: #e3e0d8;
  --accent: #2f6b55;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --chip: #ebe8df;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161816;
    --card: #20231f;
    --text: #eceee9;
    --muted: #9ba196;
    --line: #333731;
    --accent: #6cc19f;
    --accent-text: #0d1a14;
    --danger: #f2b8b5;
    --chip: #2c302b;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
main { max-width: 720px; margin: 0 auto; padding: 12px 16px 120px; }
h1 { font-size: 1.5rem; margin: 8px 0 4px; line-height: 1.25; overflow-wrap: anywhere; }
h2 { font-size: 1.1rem; margin: 24px 0 8px; }
a { color: var(--accent); }
.muted { color: var(--muted); font-size: .9rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

button, .btn {
  font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 9px 16px; cursor: pointer; text-decoration: none; display: inline-flex;
  align-items: center; gap: 6px; min-height: 44px;
}
button.primary, .btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
button.icon { padding: 0; width: 44px; justify-content: center; border-radius: 50%; }
button:disabled { opacity: .5; }
button.link { border: 0; background: none; padding: 0; min-height: 0; color: var(--accent); }

input, textarea, select {
  font: inherit; width: 100%; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
}
textarea { min-height: 180px; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: block; font-size: .9rem; color: var(--muted); margin: 14px 0 6px; }

.top { display: flex; gap: 8px; align-items: center; position: sticky; top: 0; background: var(--bg); padding: 8px 0; z-index: 2; }
.top input[type=search] { border-radius: 999px; }
.brand { font-weight: 700; font-size: 1.2rem; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 6px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 0; background: var(--chip); border-radius: 999px; padding: 6px 12px; font-size: .9rem; white-space: nowrap; min-height: 34px; }
.chip.on { background: var(--accent); color: var(--accent-text); }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.card {
  display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; color: inherit; text-decoration: none;
}
.card .t { font-weight: 600; overflow-wrap: anywhere; }
.card .p { color: var(--muted); font-size: .92rem; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.kind { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.body { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; }
.body:dir(rtl), [dir=rtl].body { font-size: 1.35rem; line-height: 2; }
.preview { max-width: 100%; border-radius: var(--radius); border: 1px solid var(--line); display: block; margin: 12px 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

.seg { display: flex; background: var(--chip); border-radius: 999px; padding: 3px; gap: 3px; margin: 8px 0; }
.seg button { flex: 1; border: 0; background: none; min-height: 38px; justify-content: center; }
.seg button.on { background: var(--card); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }

.fab {
  position: fixed; right: max(16px, calc(50% - 344px)); bottom: calc(20px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 50%; font-size: 30px; justify-content: center;
  background: var(--accent); color: var(--accent-text); border: 0; box-shadow: 0 4px 14px rgba(0,0,0,.25);
}

.center { min-height: 70vh; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 14px; }
.logo { width: 84px; height: 84px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.error { color: var(--danger); }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: .95rem; z-index: 10; max-width: calc(100% - 32px);
}
.box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 8px 0; overflow-wrap: anywhere; }
.narrow { width: 100%; max-width: 320px; text-align: left; }
body.cover main, body.cover #toast { visibility: hidden; }
