/* Kagaz — warm paper, book-like Gurmukhi, one saffron accent. */

:root {
  --bg: #F7F2E9;
  --surface: #FFFDF8;
  --raise: #EDE5D7;
  --text: #211C16;
  --muted: #6E6253;
  --line: #E4DACB;
  --accent: #B4441A;
  --accent-ink: #FFFDF8;
  --accent-soft: #F3E2D5;
  --ok: #4F6B3A;
  --warn: #8F5200;
  --danger: #A8321C;
  --shadow: 0 18px 40px rgba(60, 40, 20, .16);
  --size: 22px;
  --serif: 'Tiro Gurmukhi', 'Noto Serif Gurmukhi', 'Raavi', serif;
  --sans: 'Mukta Mahee', 'Noto Sans Gurmukhi', system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1A1612;
    --surface: #241F19;
    --raise: #2F2821;
    --text: #EDE4D6;
    --muted: #A89A86;
    --line: #3A3128;
    --accent: #E8875A;
    --accent-ink: #1A1612;
    --accent-soft: #3B271C;
    --ok: #A3C585;
    --warn: #E9B464;
    --danger: #F08A6E;
    --shadow: 0 18px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1A1612;
  --surface: #241F19;
  --raise: #2F2821;
  --text: #EDE4D6;
  --muted: #A89A86;
  --line: #3A3128;
  --accent: #E8875A;
  --accent-ink: #1A1612;
  --accent-soft: #3B271C;
  --ok: #A3C585;
  --warn: #E9B464;
  --danger: #F08A6E;
  --shadow: 0 18px 40px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ico { width: 22px; height: 22px; flex: none; }
.ico.big { width: 44px; height: 44px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-weight: 500;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.big { width: 100%; min-height: 58px; border-radius: 16px; font-size: 18px; }
.btn:disabled { opacity: .5; cursor: default; }
.link { border: 0; background: none; color: var(--accent); padding: 10px; font-size: 16px; }
.link.danger, .danger { color: var(--danger); }
.icon-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--raise); }
.field {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

/* ---- sign in ---- */
.login {
  min-height: 100dvh;
  max-width: 400px;
  margin: 0 auto;
  padding: 18vh 28px calc(36px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 48px;
}
.login-top { text-align: center; }
.logo {
  width: 84px;
  height: 84px;
  margin: 0 auto;
  border-radius: 24px;
  background: var(--text);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-size: 46px;
  line-height: 1;
}
.login h1 { margin: 28px 0 6px; font-family: var(--serif); font-weight: 400; font-size: 34px; }
.login-top p { margin: 0; color: var(--muted); font-size: 17px; }
.login-bottom { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.password-form { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.password-form input {
  width: 100%;
  min-height: 56px;
  padding: 0 18px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 18px;
}
.password-form input:focus { border-color: var(--accent); outline: none; }
.error { color: var(--danger); min-height: 1.4em; margin: 4px 0 0; text-align: center; }
.fine { color: var(--muted); font-size: 13px; margin: 8px 0 0; text-align: center; }

/* ---- writing screen ---- */
.app { display: flex; flex-direction: column; height: 100dvh; }
.bar {
  flex: none;
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 24px;
}
.bar-left { display: flex; align-items: center; gap: 4px; min-width: 0; flex: 1; }
.switcher {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  max-width: 420px;
  height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
}
.switcher:hover { background: var(--raise); }
.switcher-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--serif);
  font-size: 17px;
}
.switcher .chevron { width: 18px; height: 18px; color: var(--muted); margin-left: -4px; }
.bar-right { display: flex; align-items: center; gap: 6px; flex: none; }
.only-narrow { display: none !important; }
.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  font-size: 15px;
  white-space: nowrap;
}
.status .ico { width: 20px; height: 20px; }
.status.ok { color: var(--ok); }
.status.busy { color: var(--muted); }
.status.warn { color: var(--warn); }
.mode { display: flex; background: var(--raise); border-radius: 999px; padding: 4px; margin: 0 6px; }
.mode button {
  border: 0;
  border-radius: 999px;
  padding: 6px 16px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
}
.mode button.pa { font-family: var(--serif); font-size: 16px; }
.mode button.active { background: var(--text); color: var(--bg); }

.scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.sheet { max-width: 768px; margin: 0 auto; padding: 24px 24px 40vh; }
.date { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 12px; }
.title {
  display: block;
  width: 100%;
  margin: 0 0 22px;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: var(--serif);
  font-size: calc(var(--size) * 1.8);
  line-height: 1.4;
}
.editor {
  display: block;
  width: 100%;
  min-height: 50vh;
  margin: 0;
  padding: 0;
  border: 0;
  outline: none;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: var(--text);
  font-family: var(--serif);
  font-size: var(--size);
  line-height: 1.9;
}
.title::placeholder, .editor::placeholder { color: var(--muted); opacity: .6; }
body[data-mode="en"] .editor { caret-color: var(--accent); }
.foot {
  flex: none;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 24px calc(env(safe-area-inset-bottom));
  font-size: 13px;
  color: var(--muted);
}

/* ---- suggestion list (quiet) ---- */
.ime-popup {
  position: fixed;
  z-index: 50;
  min-width: 170px;
  max-width: 300px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 28px rgba(60, 40, 20, .12);
  font-family: var(--serif);
  user-select: none;
  -webkit-user-select: none;
}
.ime-head { font-family: var(--sans); font-size: 12px; color: var(--muted); padding: 3px 10px 1px; }
.ime-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 2px 12px;
  border-radius: 9px;
  font-size: 19px;
  color: var(--text);
  cursor: pointer;
}
.ime-item:hover { background: var(--raise); }
.ime-item.sel { background: var(--accent-soft); color: var(--accent); }
.ime-num { font-family: var(--sans); font-size: 12px; color: var(--muted); width: 10px; text-align: right; }
.ime-item.english .ime-text { font-family: var(--sans); font-size: 16px; color: var(--muted); }
.ime-loading { padding: 4px 12px; font-size: 19px; color: var(--muted); }
.ime-foot { font-family: var(--sans); font-size: 11px; color: var(--muted); padding: 4px 10px 2px; }

/* phones: one row of suggestions right above the keyboard */
.ime-popup.strip {
  left: 0;
  width: 100vw;
  max-width: none;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-width: 1px 0 0;
  border-radius: 0;
  box-shadow: 0 -4px 16px rgba(60, 40, 20, .06);
  overflow-x: auto;
  scrollbar-width: none;
}
.ime-popup.strip::-webkit-scrollbar { display: none; }
.ime-popup.strip .ime-item {
  flex: none;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 12px;
  background: var(--bg);
  font-size: 20px;
}
.ime-popup.strip .ime-item.sel { background: var(--accent-soft); }
.ime-popup.strip .ime-num { display: none; }
.ime-popup.strip .ime-head, .ime-popup.strip .ime-foot { flex: none; padding: 0 4px; }

/* ---- menus & dialogs ---- */
.menu {
  position: fixed;
  z-index: 40;
  min-width: 210px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.menu button {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 9px;
  background: none;
  text-align: left;
  font-size: 16px;
}
.menu button:hover { background: var(--raise); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }

dialog {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 0;
}
dialog::backdrop { background: rgba(33, 28, 22, .35); }

.drawer {
  margin: 0;
  height: 100dvh;
  max-height: 100dvh;
  width: min(340px, 88vw);
  border-width: 0 1px 0 0;
  border-radius: 0 20px 20px 0;
  padding: 16px 16px calc(12px + env(safe-area-inset-bottom));
}
.drawer[open] { display: flex; flex-direction: column; gap: 12px; }
.drawer-head, .dialog-head { display: flex; align-items: center; justify-content: space-between; }
.drawer-head h2, .dialog-head h2 { margin: 0; font-size: 20px; font-weight: 600; }
.drawer .btn.primary { width: 100%; }
.doc-list { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; }
.doc-list .empty { color: var(--muted); padding: 12px 8px; }
.doc-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: none;
  text-align: left;
}
.doc-item:hover { background: var(--raise); }
.doc-item.active { background: var(--accent-soft); }
.doc-name { font-family: var(--serif); font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-date { font-size: 13px; color: var(--muted); }
.drawer .link { align-self: flex-start; color: var(--muted); }

.sheet-dialog {
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100dvh - 40px);
  border-radius: 20px;
  padding: 18px 22px 22px;
}
.sheet-dialog.wide { width: min(880px, calc(100vw - 32px)); }
.sheet-dialog.center { text-align: center; padding: 32px 26px 22px; }
.sheet-dialog.center h2 { margin: 18px 0 8px; font-size: 26px; }
.sheet-dialog.center p { margin: 0 0 26px; line-height: 1.5; font-size: 17px; }
.sheet-dialog.center .link { margin-top: 6px; color: var(--muted); }
.offer-icon {
  width: 84px;
  height: 84px;
  margin: 0 auto;
  border-radius: 26px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  border-bottom: 1px solid var(--line);
}
.seg { display: flex; background: var(--raise); border-radius: 12px; padding: 3px; }
.seg button { border: 0; border-radius: 9px; background: none; padding: 7px 14px; font-size: 15px; color: var(--muted); }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.switch {
  appearance: none;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--raise);
  position: relative;
  cursor: pointer;
  transition: background .15s;
  flex: none;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .15s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }
.group { padding-top: 16px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.group h3 { margin: 0; font-size: 16px; }
.group p { margin: 0 0 6px; }
.group .link { padding-left: 0; }
.passkey-list { list-style: none; margin: 0 0 8px; padding: 0; width: 100%; }
.passkey-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.passkey-list small { display: block; color: var(--muted); }
.passkey-list .link { color: var(--danger); font-size: 14px; }

.history { display: grid; grid-template-columns: 260px 1fr; gap: 14px; height: 56vh; margin-top: 14px; }
.history-list, .trash-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.history-list .empty, .trash-list .empty { color: var(--muted); padding: 10px 4px; }
.history-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 12px;
  background: none;
  text-align: left;
}
.history-item:hover { background: var(--raise); }
.history-item.active { background: var(--accent-soft); }
.history-item small { color: var(--muted); }
.history-item span { font-family: var(--serif); font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-preview {
  overflow-y: auto;
  padding: 16px 20px;
  border-radius: 14px;
  background: var(--bg);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.8;
  white-space: pre-wrap;
}
.history-preview h3 { margin: 0 0 8px; font-weight: 400; font-size: 24px; }
.dialog-foot { display: flex; justify-content: flex-end; margin-top: 14px; }
.trash-list { margin-top: 10px; max-height: 60vh; }
.trash-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.trash-list span { font-family: var(--serif); font-size: 17px; }
.trash-list small { display: block; font-family: var(--sans); color: var(--muted); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 100;
  max-width: calc(100vw - 32px);
  padding: 12px 20px;
  border-radius: 14px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  box-shadow: var(--shadow);
}

/* ---- phones ---- */
@media (max-width: 640px) {
  :root { --size: 20px; }
  .only-wide { display: none !important; }
  .only-narrow { display: block !important; }
  .menu hr.only-narrow { display: block !important; }
  .bar {
    height: 58px;
    padding: 0 6px 0 4px;
    border-bottom: 1px solid var(--line);
    background: var(--bg);
  }
  .switcher { padding: 0 6px; gap: 8px; }
  .switcher-name { font-size: 17px; }
  .status { padding: 0 6px; }
  .status span { display: none; }
  .mode { margin: 0; }
  .mode button { padding: 6px 12px; font-size: 14px; }
  .mode button.pa { font-size: 15px; }
  .sheet { padding: 22px 22px 45vh; }
  .date { font-size: 12px; margin-bottom: 8px; }
  .title { font-size: 28px; margin-bottom: 14px; }
  .editor { line-height: 1.85; }
  .foot { display: none; }
  .drawer { width: min(360px, 92vw); }
  .sheet-dialog:not(.wide), .sheet-dialog.center {
    width: 100vw;
    max-width: 100vw;
    margin: auto 0 0;
    border-radius: 22px 22px 0 0;
    border-width: 1px 0 0;
    padding-bottom: calc(22px + env(safe-area-inset-bottom));
  }
  .history { grid-template-columns: 1fr; grid-template-rows: 170px 1fr; height: 66vh; }
}
.row b { font-family: var(--serif); font-weight: 400; }
