/* Colours come from Telegram themeParams (app.js sets --bg, --text, ... on <html>).
   The values below are only the fallback for a plain browser. */
:root {
  --bg: #f6f4fb;
  --card: #ffffff;
  --text: #1d1b26;
  --hint: #6f6a80;
  --link: #5b47c7;
  --btn: #5b47c7;
  --btn-text: #ffffff;
  --accent: #5b47c7;
  --danger: #d0384b;
  --line: rgba(120, 110, 150, 0.18);
  --radius: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12111c;
    --card: #1d1b2b;
    --text: #ecebf5;
    --hint: #9a96b0;
    --link: #b3a6ff;
    --btn: #7a66e8;
    --btn-text: #ffffff;
    --accent: #c9b8ff;
    --danger: #ff6b7d;
    --line: rgba(200, 190, 255, 0.14);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button, textarea, a { font: inherit; color: inherit; }
button { cursor: pointer; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px calc(24px + env(safe-area-inset-bottom));
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0 12px; }
.brand { display: flex; align-items: center; gap: 10px; }
.moon { width: 34px; height: 34px; fill: var(--accent); flex: none; }
h1 { font-size: 21px; line-height: 1.15; margin: 0; letter-spacing: 0.2px; }
.sub { margin: 0; color: var(--hint); font-size: 13px; }
.lang { display: flex; background: var(--card); border-radius: 10px; padding: 3px; border: 1px solid var(--line); }
.lang button { border: 0; background: transparent; padding: 5px 10px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--hint); }
.lang button[aria-pressed="true"] { background: var(--btn); color: var(--btn-text); }

/* tabs */
.tabs { display: flex; gap: 6px; background: var(--card); border-radius: 12px; padding: 4px; margin-bottom: 14px; border: 1px solid var(--line); }
.tab { flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 9px; font-weight: 600; font-size: 15px; color: var(--hint); display: inline-flex; justify-content: center; align-items: center; gap: 6px; }
.tab.active { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.count { background: var(--btn); color: var(--btn-text); border-radius: 999px; font-size: 12px; padding: 0 7px; line-height: 19px; min-width: 19px; }

/* write */
textarea {
  width: 100%;
  min-height: 170px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  padding: 14px;
  font-size: 16px; /* >=16px: iOS does not zoom on focus */
  line-height: 1.5;
  outline: none;
}
textarea:focus { border-color: var(--btn); }
textarea::placeholder { color: var(--hint); }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 6px 2px 12px; min-height: 20px; }
.hint { color: var(--hint); font-size: 13px; margin: 0; }
.hint.small { font-size: 12px; opacity: 0.85; }
.warn { color: var(--danger); }
.privacy { margin-top: 12px; text-align: center; }

.primary, .secondary {
  display: flex; align-items: center; justify-content: center; text-align: center;
  width: 100%; min-height: 48px; border-radius: 12px; border: 0;
  font-weight: 600; font-size: 16px; text-decoration: none; padding: 10px 14px;
}
.primary { background: var(--btn); color: var(--btn-text); }
.primary:disabled { opacity: 0.6; }
.secondary { background: var(--card); color: var(--link); border: 1px solid var(--line); }
.actions { display: grid; gap: 10px; margin-top: 16px; }
.link { background: none; border: 0; color: var(--link); padding: 8px 0; font-size: 14px; }
.link.danger { color: var(--danger); display: block; margin: 18px auto 0; }

/* reading */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; border: 1px solid var(--line); }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); margin: 0 0 10px; font-weight: 700; }
.sym { padding: 10px 0; border-top: 1px solid var(--line); }
.sym:first-of-type { border-top: 0; padding-top: 0; }
.sym-title { font-weight: 700; margin: 0 0 4px; }
.sym-long { margin: 0; }
.note { margin: 12px 0 0; padding: 12px; border-radius: 12px; background: var(--bg); font-size: 15px; }
.mood { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--bg); color: var(--hint); }
.note .mood { padding: 0; background: none; }
.mood.dark { color: #c06b2a; }
.mood.light { color: #2f9a63; }
.more { margin: 12px 0 0; color: var(--hint); font-size: 15px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; padding: 0; list-style: none; }
.chip { background: var(--bg); border-radius: 999px; padding: 3px 10px; font-size: 13px; }
.chip b { color: var(--accent); }
.status { color: var(--hint); font-size: 13px; text-align: center; margin: 10px 0 0; min-height: 1em; }
.status.warn { color: var(--danger); }

/* diary */
.entry { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; border: 1px solid var(--line); }
.entry-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.entry-date { font-size: 13px; color: var(--hint); }
.entry-text { margin: 8px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.entry.open .entry-text { display: block; -webkit-line-clamp: unset; }
.entry-toggle { border: 0; background: none; padding: 0; width: 100%; text-align: left; color: inherit; }
.entry-reading { margin-top: 12px; }
.entry-reading .card { background: var(--bg); border: 0; }
.entry-actions { display: flex; justify-content: flex-end; }
.empty { text-align: center; color: var(--hint); padding: 32px 12px; }
.empty svg { width: 48px; height: 48px; fill: var(--accent); opacity: 0.6; }

/* footer */
.foot { text-align: center; margin-top: 26px; display: grid; gap: 8px; }
.support { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px; padding: 9px 18px; font-weight: 600; font-size: 15px; margin: 0 auto; }
.support svg { width: 18px; height: 18px; fill: #f2b631; }

/* bottom sheet */
.sheet-wrap { position: fixed; inset: 0; background: rgba(10, 8, 20, 0.45); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet { background: var(--card); color: var(--text); width: 100%; max-width: 560px; border-radius: 20px 20px 0 0; padding: 22px 18px calc(22px + env(safe-area-inset-bottom)); }
.sheet h2 { margin: 0 0 8px; font-size: 19px; }
.sheet p { margin: 0 0 18px; }
.noscript { padding: 20px; text-align: center; }
