/* Scratchpad PWA — standalone stylesheet.
   Design tokens match the dashboard (index.html) so the two feel like one product. */

:root {
  --bg: #0b0914;
  --surface: #110f24;
  --card-bg: rgba(255, 255, 255, 0.045);
  --card-hover: rgba(255, 255, 255, 0.085);
  --text: #f1f1f7;
  --text-muted: #aaa8c0;
  --accent: #818cf8;
  --accent-strong: #4f46e5;
  --accent-glow: rgba(129, 140, 248, 0.24);
  --border: rgba(255, 255, 255, 0.1);
  --tag-bg: rgba(129, 140, 248, 0.13);
  --danger: #f87171;
  --success: #34d399;
  --radius: 14px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f9;
    --surface: #ffffff;
    --card-bg: rgba(30, 27, 75, 0.035);
    --card-hover: rgba(79, 70, 229, 0.08);
    --text: #1e1b4b;
    --text-muted: #5f647c;
    --accent: #4f46e5;
    --accent-glow: rgba(79, 70, 229, 0.18);
    --border: rgba(30, 27, 75, 0.12);
    --tag-bg: rgba(79, 70, 229, 0.1);
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(2rem, env(safe-area-inset-bottom));
}
button, input, summary { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.hidden { display: none !important; }

.app-header {
  max-width: 980px;
  margin: 0 auto .9rem;
  display: flex;
  align-items: center;
  gap: .7rem;
  flex-wrap: wrap;
}
.embed-banner {
  max-width: 980px;
  margin: 0 auto .75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .8rem;
  flex-wrap: wrap;
  background: var(--tag-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .5rem .8rem;
  font-size: .8rem;
  color: var(--text-muted);
}
.embed-banner a { color: var(--accent); font-weight: 700; text-decoration: none; white-space: nowrap; }
body.is-embedded { padding-top: .6rem; }
body.is-embedded .app-header .brand { font-size: .95rem; }
.brand { font-weight: 800; font-size: 1.05rem; display: inline-flex; align-items: center; gap: .45rem; }
.brand a { color: var(--text); text-decoration: none; }
.app-header .spacer { flex: 1 1 auto; }
.header-link {
  color: var(--text-muted);
  font-size: .82rem;
  text-decoration: none;
  border: 1px solid var(--border);
  padding: .4rem .7rem;
  border-radius: 8px;
}
.header-link:hover { border-color: var(--accent); color: var(--text); }

.shell {
  max-width: 980px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .9rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .25);
}
h1 { margin: 0; font-size: 1.2rem; font-weight: 750; }
.subtitle { margin: -.4rem 0 0; color: var(--text-muted); font-size: .82rem; }

.form-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .6rem .8rem;
  color: var(--text);
  font-size: .88rem;
  width: 100%;
}
.form-input:focus { border-color: var(--accent); outline: none; }
.form-label { display: flex; flex-direction: column; gap: .35rem; font-size: .82rem; font-weight: 650; color: var(--text-muted); }

.modal-actions { display: flex; gap: .55rem; flex-wrap: wrap; align-items: center; }
.modal-btn {
  padding: .55rem 1rem;
  border-radius: 8px;
  font-size: .84rem;
  font-weight: 700;
  border: 1px solid transparent;
}
.modal-btn.cancel { background: transparent; color: var(--text-muted); border-color: var(--border); }
.modal-btn.submit { background: var(--accent); color: #fff; }
.modal-btn:hover { filter: brightness(1.1); }
.modal-btn:disabled { opacity: .55; cursor: default; }
.modal-hint { margin: 0; color: var(--text-muted); font-size: .8rem; line-height: 1.5; }
.modal-hint a, .gh-sync-repo-help a { color: var(--accent); }
.modal-hint code { background: var(--tag-bg); padding: .08rem .3rem; border-radius: 5px; font-size: .78rem; }
.status-msg { margin: 0; font-size: .82rem; color: var(--text-muted); min-height: 1.1rem; }
.status-msg.is-error { color: var(--danger); }
.status-msg.is-success { color: var(--success); }
.token-row { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; }
.checkbox-row { display: flex; align-items: center; gap: .5rem; font-size: .82rem; font-weight: 650; color: var(--text-muted); }
.checkbox-row input { accent-color: var(--accent); }
.path-row { display: flex; gap: .4rem; align-items: stretch; min-width: 0; }
.path-row .form-input { flex: 1 1 auto; min-width: 0; }
.path-row .modal-btn { white-space: nowrap; }

/* Note switcher: today's reusable note vs a brand-new dated note */
.note-switcher { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.note-current {
  font-family: var(--mono); font-size: .76rem; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1 1 12rem;
}

/* Markdown toolbar + emoji picker */
.md-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; }
.md-toolbar-group { display: flex; gap: .25rem; padding-right: .35rem; border-right: 1px solid var(--border); }
.md-toolbar-group:last-child { border-right: 0; padding-right: 0; }
.md-toolbar-spacer { flex: 1 1 0; min-width: 0; }
.md-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .2rem;
  min-height: 32px; min-width: 32px; padding: .3rem .5rem; border-radius: 7px;
  border: 1px solid var(--border); background: var(--card-bg); color: var(--text);
  font-size: .8rem; font-weight: 700; line-height: 1; white-space: nowrap;
}
.md-btn:hover { border-color: var(--accent); }
.md-btn:active { transform: translateY(1px); }
.md-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.md-strike { text-decoration: line-through; }

.emoji-anchor { position: relative; display: inline-flex; }
.emoji-popover {
  position: absolute; z-index: 8; top: calc(100% + .35rem); right: 0;
  width: min(22rem, calc(100vw - 3rem));
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .45); padding: .55rem;
  display: flex; flex-direction: column; gap: .45rem;
}
.emoji-popover[hidden] { display: none; }
.emoji-search { width: 100%; }
.emoji-scroll { max-height: 13rem; overflow-y: auto; display: flex; flex-direction: column; gap: .35rem; overscroll-behavior: contain; }
.emoji-category { font-size: .68rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); margin: .2rem 0 0; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(2rem, 1fr)); gap: .15rem; }
.emoji-btn {
  border: 1px solid transparent; background: transparent; border-radius: 7px;
  font-size: 1.05rem; line-height: 1; padding: .32rem 0; min-height: 32px;
}
.emoji-btn:hover, .emoji-btn:focus-visible { background: var(--card-bg); border-color: var(--accent); outline: none; }
.emoji-empty { font-size: .8rem; color: var(--text-muted); padding: .4rem .2rem; }
.emoji-hint { font-size: .72rem; color: var(--text-muted); margin: 0; }

/* File target bar */
.scratch-filebar {
  display: flex; align-items: center; gap: .4rem; flex-wrap: wrap;
  padding: .45rem .65rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--card-bg); font-size: .78rem; line-height: 1.4; min-width: 0;
}
.scratch-filebar-icon { flex: 0 0 auto; }
.scratch-filebar-repo { font-weight: 750; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 45%; }
.scratch-filebar-sep { color: var(--text-muted); flex: 0 0 auto; }
.scratch-filebar-file {
  color: var(--text); font-family: var(--mono);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1 1 8rem;
}
.scratch-filebar-state { margin-left: auto; color: var(--text-muted); font-size: .74rem; font-weight: 650; white-space: nowrap; }
.scratch-filebar-state.is-saved { color: var(--success); }
.scratch-filebar-state.is-error { color: var(--danger); }

/* Editor + preview */
.scratch-editor { display: flex; gap: .75rem; align-items: stretch; min-width: 0; }
.scratch-textarea {
  font-family: var(--mono);
  resize: vertical;
  line-height: 1.5;
  min-height: 38dvh;
  flex: 1 1 58%;
  min-width: 0;
}
.md-preview {
  flex: 1 1 42%; min-width: 0; min-height: 38dvh; max-height: 60dvh; overflow-y: auto;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: .8rem .9rem; font-size: .9rem; line-height: 1.6; overflow-wrap: anywhere;
}
.md-preview[hidden] { display: none; }
.md-preview:empty::before { content: "Nothing to preview yet — start typing on the left."; color: var(--text-muted); font-size: .82rem; }
.md-preview h1, .md-preview h2, .md-preview h3 { margin: .2rem 0 .5rem; line-height: 1.25; }
.md-preview h1 { font-size: 1.35rem; }
.md-preview h2 { font-size: 1.15rem; }
.md-preview h3 { font-size: 1rem; }
.md-preview p { margin: .35rem 0; }
.md-preview ul, .md-preview ol { margin: .35rem 0; padding-left: 1.3rem; }
.md-preview li { margin: .15rem 0; }
.md-preview li.md-task { display: flex; align-items: flex-start; gap: .45rem; list-style: none; margin-left: -1rem; }
.md-preview li.md-task input[type="checkbox"] { margin-top: .35rem; accent-color: var(--accent); }
.md-preview hr { border: 0; border-top: 1px solid var(--border); margin: .8rem 0; }
.md-preview blockquote { margin: .5rem 0; padding-left: .7rem; border-left: 3px solid var(--accent); color: var(--text-muted); }
.md-preview code { background: var(--tag-bg); padding: .08rem .3rem; border-radius: 5px; font-size: .82em; }
.md-preview pre { background: var(--tag-bg); padding: .6rem .7rem; border-radius: 8px; overflow-x: auto; }
.md-preview pre code { background: none; padding: 0; }
.md-preview a { color: var(--accent); }
.md-preview del { color: var(--text-muted); }
/* Markdown tables: readable at any width, scrollable rather than squeezed. */
.md-table { overflow-x: auto; margin: .6rem 0; border-radius: 10px; border: 1px solid var(--border); }
.md-preview table { border-collapse: collapse; width: 100%; font-size: .84rem; }
.md-preview th, .md-preview td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); padding: .4rem .6rem; text-align: left; vertical-align: top; }
.md-preview th:last-child, .md-preview td:last-child { border-right: 0; }
.md-preview tbody tr:last-child td { border-bottom: 0; }
.md-preview thead th { background: var(--tag-bg); font-weight: 750; color: var(--text); white-space: nowrap; }
.md-preview tbody tr:nth-child(even) { background: rgba(255, 255, 255, .022); }

/* ---- premium chrome: themed scrollbars, the clock, the ⋯ menu, the sheets ------------------------- */
/* Scrollbars that belong to the theme instead of the OS default. */
* { scrollbar-width: thin; scrollbar-color: rgba(129, 140, 248, .65) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  border-radius: 99px; border: 2px solid transparent; background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: linear-gradient(180deg, #a5b4fc, var(--accent)); background-clip: padding-box; border: 2px solid transparent; }
::-webkit-scrollbar-corner { background: transparent; }

/* Day, date and time — always visible, quietly authoritative. */
.scratch-clock {
  margin-left: .5rem; padding: .12rem .5rem; border-radius: 99px; white-space: nowrap;
  font-size: .72rem; font-weight: 750; letter-spacing: .01em; color: var(--accent);
  background: var(--tag-bg); border: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

/* Action bar: the GitHub launcher plus a single ⋯ menu instead of a row of buttons. */
.scratch-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.scratch-tip {
  margin: .55rem 0 0;
  padding: .5rem .7rem .5rem .8rem;
  border-left: 3px solid transparent;
  border-image: linear-gradient(180deg, var(--accent), #a855f7) 1;
  background: linear-gradient(90deg, rgba(99, 102, 241, .10), rgba(168, 85, 247, .04));
  border-radius: 0 8px 8px 0;
  color: var(--text-muted);
  font-size: .76rem;
  line-height: 1.55;
}
.scratch-tip strong { color: var(--text); font-weight: 600; }
.scratch-tip code {
  background: var(--tag-bg); padding: .05rem .28rem; border-radius: 5px;
  font-size: .72rem; color: var(--text);
}
.scratch-gh-launch { display: inline-flex; align-items: center; gap: .4rem; }
.scratch-gh-launch .gh-sync-badge { font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.scratch-gh-launch .gh-sync-badge.is-connected { color: #052e1b; background: var(--success); border-radius: 99px; padding: .05rem .4rem; }
.scratch-menu-wrap { position: relative; margin-left: auto; }
.scratch-menu {
  position: fixed; z-index: 60; min-width: 12.5rem;
  display: flex; flex-direction: column; gap: .1rem; padding: .35rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .45);
}
.scratch-menu[hidden] { display: none; }
.scratch-menu button {
  display: flex; align-items: center; gap: .5rem; width: 100%; text-align: left;
  background: transparent; border: 0; border-radius: 8px; padding: .5rem .6rem;
  color: var(--text); font-size: .84rem; font-weight: 650;
}
.scratch-menu button:hover, .scratch-menu button:focus-visible { background: var(--card-hover); outline: none; }
.scratch-menu button.is-danger { color: var(--danger); }
.scratch-menu hr { border: 0; border-top: 1px solid var(--border); margin: .25rem .1rem; }

/* The GitHub settings live in their own sheet now, not in a disclosure. */
.sheet-modal {
  border: 0; padding: 0; background: transparent; color: var(--text);
  max-width: min(42rem, 94vw); max-height: 92dvh; width: 100%;
}
.sheet-modal::backdrop { background: rgba(6, 5, 16, .62); backdrop-filter: blur(3px); }
.sheet-card {
  display: flex; flex-direction: column; gap: .75rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 1.1rem 1.15rem; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}
.sheet-head { display: flex; align-items: center; gap: .75rem; }
.sheet-title { margin: 0; font-size: 1.05rem; font-weight: 800; flex: 1 1 auto; }
.sheet-head .modal-btn { flex: 0 0 auto; }
.sheet-card .gh-sync-body { margin-top: 0; }

/* New file / new folder */
.gh-create { display: flex; flex-direction: column; gap: .5rem; border-top: 1px dashed var(--border); padding-top: .6rem; }
.gh-create-row { display: flex; gap: .5rem; }
.gh-create .path-row .form-input { min-width: 0; }
.gh-create select.form-input { flex: 0 0 auto; width: auto; padding-right: .4rem; }
#scratchpad-gh-create-hint { font-size: .74rem; }

@media (max-width: 640px) {
  .sheet-modal { max-width: 100vw; max-height: 100dvh; height: 100%; }
  .sheet-card { border-radius: 0; height: 100%; max-height: 100dvh; padding-bottom: max(1rem, env(safe-area-inset-bottom)); }
  .gh-create-row .path-row { flex-wrap: wrap; }
  .scratch-menu-wrap { margin-left: 0; }
}

/* GitHub sync panel */
.gh-sync-body { display: flex; flex-direction: column; gap: .6rem; }
.gh-sync-body .token-row { align-items: flex-end; }
.gh-sync-badge { font-size: .78rem; font-weight: 700; color: var(--text-muted); }
.gh-sync-badge.is-connected { color: var(--success); }
.gh-sync-badge:empty { display: none; }
.gh-sync-details { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .6rem; }
.gh-sync-advanced { border-top: 1px dashed var(--border); padding-top: .7rem; margin-top: .2rem; }
.gh-sync-advanced > summary { cursor: pointer; font-size: .8rem; font-weight: 700; color: var(--text-muted); }
.gh-sync-advanced[open] > summary { color: var(--text); }
.gh-sync-repo-help { font-size: .8rem; line-height: 1.5; color: var(--text-muted); border: 1px dashed var(--border); border-radius: 8px; padding: .55rem .7rem; }
.gh-sync-repo-help[hidden] { display: none; }
/* Reconnect kit: the "keep a copy of this key" nudge, and the numbered recovery steps. */
.gh-keep { border: 1px dashed var(--accent); border-radius: 8px; padding: .55rem .7rem; }
.gh-keep[hidden] { display: none; }
.gh-restore-steps { margin: 0 0 .2rem; padding-left: 1.15rem; font-size: .8rem; line-height: 1.55; color: var(--text-muted); }
.gh-restore-steps code { font-size: .95em; }
.gh-restore-steps a { color: var(--accent); }
.gh-restore-steps li + li { margin-top: .3rem; }
.gh-sync-body input[type="file"] { padding: .35rem; font-size: .78rem; }
.gh-sync-body .modal-actions { margin-top: 0; }

/* Outbox badge + install/update chrome */
#outbox-count {
  font-size: .72rem; font-weight: 800; color: var(--danger);
  border: 1px solid var(--danger); border-radius: 99px; padding: .12rem .55rem;
}
#scratchpad-sync-now.has-pending { border-color: var(--accent); color: var(--text); }
#install-app { background: var(--accent); color: #fff; }
#ios-hint, #fs-unsupported {
  font-size: .78rem; color: var(--text-muted); background: var(--card-bg);
  border: 1px solid var(--border); border-radius: 8px; padding: .5rem .7rem; margin: 0;
}
#sw-update-toast {
  position: fixed; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex; align-items: center; gap: .8rem;
  background: var(--surface); border: 1px solid var(--accent); border-radius: 10px;
  padding: .7rem 1rem; box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
  font-size: .85rem; z-index: 50;
}

@media (max-width: 900px) {
  .scratch-editor { flex-direction: column; }
  .scratch-textarea { min-height: 30dvh; }
  .md-preview { min-height: 24dvh; max-height: 44dvh; }
}
@media (max-width: 640px) {
  body { padding: .8rem .7rem max(1.2rem, env(safe-area-inset-bottom)); }
  .shell { padding: .9rem; gap: .7rem; border-radius: 10px; }
  .md-toolbar { gap: .25rem; }
  .md-toolbar-group { border-right: 0; padding-right: 0; }
  .md-toolbar-spacer { display: none; }
  .md-btn { min-height: 36px; min-width: 36px; padding: .35rem .55rem; font-size: .82rem; }
  .gh-sync-details { grid-template-columns: 1fr; }
  .path-row { flex-wrap: wrap; }
  .path-row .modal-btn { flex: 1 1 auto; }
  .emoji-popover {
    position: fixed; inset-inline: .6rem; right: auto; left: .6rem; width: auto;
    top: auto; bottom: .6rem; padding-bottom: max(.6rem, env(safe-area-inset-bottom));
  }
  .emoji-scroll { max-height: 32dvh; }
}
