/* Bidadari Note - system fonts, no external assets. Brand tokens match the Bidadari family (violet). */
:root {
  --accent: #6d4fd8;
  --accent-hover: #5a3dc2;
  --accent-contrast: #ffffff;
  --accent-grad: linear-gradient(135deg, #7c5ce6, #6240d0);
  --accent-soft: #f0ecff;
  --bg: #faf9ff;
  --surface: #ffffff;
  --text: #1d1830;
  --muted: #5f5a75;
  --border: #e3defa;
  --danger: #b42318;
  --ok: #1a7f4b;
  --warn-bg: #fff6e5;
  --warn-border: #f0d9a8;
  --err-bg: #fdecec;
  --err-border: #f1c0c0;
  --focus: #3b2fb8;
  --radius: 16px;
  --shadow: 0 1px 2px rgb(29 24 48 / 6%), 0 12px 32px rgb(109 79 216 / 10%);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent: #b79cff;
    --accent-hover: #cbb8ff;
    --accent-contrast: #14102a;
    --accent-grad: linear-gradient(135deg, #c4b5fd, #a78bfa);
    --accent-soft: #231c3d;
    --bg: #09070f;
    --surface: #14111f;
    --text: #f1eefc;
    --muted: #aaa4c4;
    --border: #2b2542;
    --danger: #ff8d8d;
    --ok: #6fd69c;
    --warn-bg: #2e2514;
    --warn-border: #5a4824;
    --err-bg: #331b1d;
    --err-border: #6b3236;
    --focus: #c4b5fd;
    --shadow: 0 1px 2px rgb(0 0 0 / 50%), 0 12px 32px rgb(0 0 0 / 45%);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 1rem/1.6 var(--font); }
a { color: var(--accent); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 14px; border-radius: 8px; z-index: 20; }
.skip-link:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; opacity: 0; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.subtle { color: var(--muted); font-size: .85rem; margin: 12px 0 0; }
h1, h2 { text-wrap: balance; }
.icon { width: 18px; height: 18px; flex: none; }
.icon-lg { width: 40px; height: 40px; color: var(--accent); }

/* ---- Brand ---- */
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; min-height: 44px; flex: none; }
.brand .wordmark { height: 14px; width: auto; color: var(--text); flex: none; }
.brand-sub { font-size: .7rem; font-weight: 700; letter-spacing: .3em; text-transform: uppercase; color: var(--accent); padding-left: 10px; border-left: 1.5px solid var(--border); line-height: 1; }

/* ---- Buttons and chips ---- */
.btn { text-align: center; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 650; min-height: 48px; padding: 12px 20px; border-radius: 12px; border: 1.5px solid transparent; cursor: pointer; text-decoration: none; transition: background .15s, transform .1s; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-compact { min-height: 44px; padding: 8px 14px; font-size: .95rem; }
.btn-small { min-height: 44px; padding: 8px 14px; font-size: .92rem; }
.btn-icon { padding: 8px 12px; min-width: 44px; }
.btn-primary { background: var(--accent-grad); color: var(--accent-contrast); }
.btn-primary:hover:not([disabled]) { background: var(--accent-hover); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--err-bg); }
.btn-quiet { background: transparent; color: var(--text); border-color: var(--border); }
.btn-quiet:hover { background: var(--accent-soft); }
.link-button { background: none; border: 0; padding: 10px 12px; min-height: 44px; font: inherit; color: var(--muted); cursor: pointer; border-radius: 10px; }
.link-button:hover { color: var(--text); background: var(--accent-soft); }

.chip-select { position: relative; display: inline-flex; align-items: center; }
.chip-select .icon { position: absolute; left: 14px; color: var(--muted); pointer-events: none; }
select { font: inherit; color: var(--text); background-color: var(--surface); border: 1.5px solid var(--border); border-radius: 12px; min-height: 48px; padding: 8px 40px 8px 14px; appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9' fill='none'%3E%3Cpath d='M1.5 1.75 7 7.25l5.5-5.5' stroke='%237a7498' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 14px 9px; }
.chip-select select { min-height: 44px; border-radius: 999px; padding: 8px 38px 8px 38px; font-size: .95rem; }
.chip { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 16px; border: 1.5px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); cursor: pointer; font-size: .95rem; position: relative; white-space: nowrap; }
.chip .icon { color: var(--muted); }
.chip-input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; width: 100%; height: 100%; }
.chip:has(.chip-input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.chip:has(.chip-input:checked) .icon { color: var(--accent); }
.chip:has(:focus-visible), .chip-select:has(:focus-visible) { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent); }
select:focus-visible, .chip-input:focus-visible { outline: none; border-color: var(--accent); }

/* ---- Application shell ---- */
body.app { height: 100vh; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); border-bottom: 1px solid var(--border); background: var(--surface); }
.bar-editor { display: flex; align-items: center; gap: 8px; min-width: 0; margin-left: 8px; }
.bar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.stage { min-height: 0; display: flex; flex-direction: column; padding: 12px 16px 0; width: 100%; max-width: 980px; margin: 0 auto; }
.view-editor { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#note { flex: 1; min-height: 0; width: 100%; resize: none; font: 1.05rem/1.65 var(--font); color: var(--text); background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 18px 20px; tab-size: 4; transition: border-color .15s, box-shadow .15s; }
#note:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent); }
#note[readonly] { opacity: .85; }
.first-use { margin: 8px 4px 0; font-size: .82rem; color: var(--muted); }

.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; margin: 0 0 10px; background: var(--warn-bg); border-color: var(--warn-border); font-size: .95rem; }
.banner[data-kind="dead"], .banner[data-kind="toolarge"], .banner[data-kind="conflict"] { background: var(--err-bg); border-color: var(--err-border); }
.banner p { margin: 0; }
.banner-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.statusbar { display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; padding: 6px 16px; padding-bottom: max(6px, env(safe-area-inset-bottom)); font-size: .85rem; color: var(--muted); }
.status-left, .status-links { display: flex; align-items: center; gap: 4px 14px; flex-wrap: wrap; }
.status-item { display: inline-flex; align-items: center; gap: 6px; }
.status-item:empty { display: none; }
.status-item .icon { width: 14px; height: 14px; }
#st-save[data-state="saved"] { color: var(--ok); }
#st-save[data-state="error"], #st-save[data-state="offline"], #st-save[data-state="expired"], #st-save[data-state="conflict"], #st-save[data-state="toolarge"], #st-size.over { color: var(--danger); font-weight: 600; }
.status-links a { color: var(--muted); text-decoration: none; padding: 10px 6px; min-height: 44px; display: inline-flex; align-items: center; }
.status-links a:hover { color: var(--text); }

/* ---- Reader and states ---- */
.view-reader, .view-state { flex: 1; min-height: 0; overflow: auto; padding-bottom: 12px; }
.reader-gate, .view-state { text-align: center; max-width: 560px; margin: 8vh auto 0; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.view-state { margin-top: 10vh; }
.reader-gate h1, .view-state h1 { font-size: 1.5rem; margin: 6px 0 0; line-height: 1.25; }
.view-state h1:focus { outline: none; }
.reader-body { max-width: 780px; margin: 0 auto; }
.reader-meta { display: flex; align-items: center; gap: 10px; margin: 4px 0 10px; font-size: .9rem; }
.badge { display: inline-block; border: 1px solid var(--border); background: var(--accent-soft); color: var(--accent); font-weight: 650; font-size: .78rem; letter-spacing: .04em; text-transform: uppercase; padding: 2px 10px; border-radius: 999px; }
.reader-text { margin: 0; padding: 18px 20px; background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); font: 1.02rem/1.65 var(--font); white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; max-height: calc(100dvh - 240px); overflow: auto; tab-size: 4; }
.reader-text:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent); }

.toast { position: fixed; left: 50%; bottom: calc(56px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: .92rem; z-index: 30; max-width: calc(100vw - 32px); text-align: center; box-shadow: var(--shadow); }

.notice { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin: 14px 0; font-size: .95rem; }
.notice-error { background: var(--err-bg); border-color: var(--err-border); }
.field-error { color: var(--danger); font-size: .92rem; margin: 6px 0 0; font-weight: 500; }

/* ---- Dialogs (centered on desktop, bottom sheets on phones) ---- */
dialog.sheet { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 22px; width: min(460px, calc(100% - 32px)); box-shadow: var(--shadow); }
dialog.sheet::backdrop { background: rgb(9 7 15 / 55%); }
dialog.sheet h2 { margin: 0 0 8px; font-size: 1.25rem; }
dialog.sheet h3 { margin: 0 0 2px; font-size: 1rem; }
dialog.sheet p { margin: 6px 0 10px; }
dialog.sheet textarea { width: 100%; font-family: var(--mono); font-size: .88rem; word-break: break-all; color: var(--text); background: var(--bg); border: 1.5px solid var(--border); border-radius: 12px; padding: 10px 12px; resize: none; }
.sheet-block { padding: 12px 0; border-top: 1px solid var(--border); }
.sheet-block:first-of-type { border-top: 0; }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.sheet-actions .btn { flex: 1 1 140px; }
.check { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.check input { margin: 5px 0 0; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.check small { display: block; color: var(--muted); font-size: .85rem; margin-top: 2px; }
.radio-group { border: 0; padding: 0; margin: 8px 0; display: grid; gap: 8px; }
.radio { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 12px; cursor: pointer; min-height: 44px; }
.radio input { accent-color: var(--accent); width: 18px; height: 18px; flex: none; margin: 0; }
.radio:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

/* ---- Info pages (privacy, terms, security, 404) ---- */
.site-header, .site-footer { width: 100%; max-width: 780px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.site-header nav, .site-footer nav { display: flex; gap: 4px; flex-wrap: wrap; }
.site-header nav a, .site-footer nav a { color: var(--muted); text-decoration: none; padding: 10px 12px; border-radius: 10px; min-height: 44px; display: inline-flex; align-items: center; }
.site-header nav a:hover, .site-footer nav a:hover { color: var(--text); background: var(--accent-soft); }
.site-footer { border-top: 1px solid var(--border); font-size: .9rem; margin-top: 24px; }
.site-footer p { margin: 0; }
body.doc { min-height: 100vh; display: flex; flex-direction: column; }
body.doc .container { flex: 1; width: 100%; max-width: 780px; margin: 0 auto; padding: 8px 16px 24px; }
.prose { padding-top: 12px; }
.prose h1 { font-size: 2rem; margin: 0 0 8px; }
.prose h2 { margin-top: 28px; font-size: 1.25rem; }
.prose .lede { color: var(--muted); font-size: 1.08rem; margin: 0 0 8px; }
.prose ul { padding-left: 1.2em; }
.prose li { margin: 8px 0; }
code { font-family: var(--mono); background: var(--accent-soft); padding: 1px 6px; border-radius: 6px; font-size: .9em; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ---- Phones: compact toolbar, icon-only secondary actions ---- */
@media (max-width: 640px) {
  .topbar { gap: 6px; padding-left: 10px; padding-right: 10px; flex-wrap: wrap; }
  .brand .wordmark { display: none; }
  .brand-sub { border-left: 0; padding-left: 0; letter-spacing: .2em; }
  .bar-editor { order: 3; width: 100%; margin-left: 0; }
  .bar-actions { gap: 6px; }
  .bar-actions .btn-compact:not(#btn-share) .btn-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .bar-actions .btn-compact:not(#btn-share) { padding: 8px 12px; min-width: 44px; }
  .stage { padding: 8px 10px 0; }
  #note { padding: 14px 14px; font-size: 1rem; }
  .reader-text { max-height: calc(100dvh - 300px); }
  dialog.sheet { margin: auto 0 0 0; width: 100%; max-width: none; border-radius: 18px 18px 0 0; padding-bottom: max(22px, env(safe-area-inset-bottom)); }
  .statusbar { padding-left: 10px; padding-right: 10px; }
}
@media (max-width: 380px) {
  .chip-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .chip { padding: 8px 12px; }
}
