/* Scrawl — visual system.
   Dark, quiet chrome around a light page; translucent bars; one accent.
   Radii: 10 (controls) · 14 (cards, popovers) · 20 (sheets) · 999 (pills). */

:root {
  --bg: #121317;
  --bar: rgba(30, 31, 38, 0.86);
  --panel: #1c1d24;
  --panel-2: #26272f;
  --raised: #2f3039;
  --hairline: rgba(255, 255, 255, 0.08);
  --text: #f5f5f7;
  --muted: #8e8e93;
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.18);
  --danger: #ff453a;
  --warm: #ffd60a;
  --paper: #f6f4ee;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.35), 0 24px 64px rgba(0, 0, 0, 0.5);
  --ease: 180ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, "SF Pro Text", "SF Pro Display", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased; letter-spacing: -0.01em;
  overscroll-behavior: none; -webkit-user-select: none; user-select: none;
  position: fixed; inset: 0; overflow: hidden;
  touch-action: none; -webkit-touch-callout: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; letter-spacing: inherit; }
button:disabled { opacity: 0.35; cursor: default; }
button, input, select, textarea { touch-action: manipulation; }
select { font: inherit; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; touch-action: none; }
.screen[hidden] { display: none; }
.muted { color: var(--muted); font-size: 13px; }
.danger { color: var(--danger); }
.link { color: var(--accent); padding: 8px 10px; border-radius: 10px; font-weight: 500; }
.link:active { background: var(--accent-soft); }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.primary {
  background: var(--accent); color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 600;
  transition: transform var(--ease), filter var(--ease);
}
.primary:active { transform: scale(0.97); filter: brightness(1.08); }
.secondary {
  background: var(--panel-2); color: var(--text); padding: 10px 16px; border-radius: 999px; font-weight: 600;
  transition: transform var(--ease), background var(--ease);
}
.secondary:active { transform: scale(0.97); background: var(--raised); }
.wide { width: 100%; padding: 13px; margin-top: 8px; }

/* Icon buttons */
.tb {
  width: 38px; height: 38px; border-radius: 11px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--text); transition: background var(--ease), transform var(--ease), color var(--ease);
}
.tb svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tb:active { background: var(--raised); transform: scale(0.94); }
.tb.active { background: var(--raised); }
.tb.tool.active { background: var(--accent); color: #fff; box-shadow: 0 2px 10px rgba(10, 132, 255, 0.35); }

/* ── Library ─────────────────────────────────────────────────────────── */
.lib-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: calc(var(--top) + 22px) 28px 10px;
}
.lib-head h1 { margin: 0; font-size: 34px; font-weight: 700; letter-spacing: -0.03em; line-height: 1; }
.lib-actions { display: flex; align-items: center; gap: 10px; }
.lib-actions .tb.active { color: var(--accent); background: var(--accent-soft); }
.lib-tools { padding: 8px 28px 16px; display: flex; flex-direction: column; gap: 12px; }
#searchInput {
  width: 100%; max-width: 440px; background: var(--panel-2); color: var(--text); border: 0; border-radius: 12px;
  padding: 10px 14px; font-size: 16px; outline: none; -webkit-appearance: none; appearance: none;
}
#searchInput::placeholder { color: var(--muted); }
#searchInput:focus { box-shadow: 0 0 0 2px var(--accent-soft), 0 0 0 1px var(--accent); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { padding: 7px 14px; border-radius: 999px; background: var(--panel-2); font-size: 13px; font-weight: 600; transition: background var(--ease), color var(--ease); }
.chip.active { background: var(--text); color: var(--bg); }
.chip.ghost { background: transparent; color: var(--muted); box-shadow: inset 0 0 0 1px var(--hairline); }
.note-grid {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 26px 22px;
  padding: 6px 28px calc(var(--bottom) + 40px); align-content: start;
}
.note-card { text-align: left; -webkit-touch-callout: none; touch-action: pan-y; transition: transform var(--ease); }
.note-card:active { transform: scale(0.97); }
.note-card .thumb {
  position: relative; aspect-ratio: 3 / 4; background: var(--paper); border-radius: 14px; overflow: hidden;
  box-shadow: var(--shadow-1), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}
.note-card .thumb.dark { background: #1c1c21; }
.note-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.note-card .name { margin-top: 10px; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-card .date { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.empty { color: var(--muted); text-align: center; margin-top: 28vh; }

/* ── Editor chrome ───────────────────────────────────────────────────── */
.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(var(--top) + 6px) 10px 6px; min-height: calc(var(--top) + 52px);
  background: var(--bar); backdrop-filter: blur(24px) saturate(160%); -webkit-backdrop-filter: blur(24px) saturate(160%);
  border-bottom: 1px solid var(--hairline); flex-wrap: wrap; z-index: 8;
}
.toolbar.compact { flex-wrap: nowrap; }
.tb-group { display: flex; align-items: center; gap: 2px; }
.tb-group.tools {
  flex-wrap: wrap; justify-content: center; gap: 2px; padding: 3px; border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
}
.sep { width: 1px; height: 22px; background: var(--hairline); margin: 0 5px; }
.title {
  color: var(--text); font-size: 17px; font-weight: 600; max-width: 220px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; text-align: left; padding: 7px 10px; border-radius: 10px; transition: background var(--ease);
}
.title:active { background: var(--raised); }
.swatches, .sizes { display: flex; gap: 5px; align-items: center; padding: 0 2px; }
.swatches[hidden], .sizes[hidden] { display: none; }
.swatch { width: 24px; height: 24px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12); transition: transform var(--ease), box-shadow var(--ease); }
.swatch.active { transform: scale(1.12); box-shadow: 0 0 0 2px var(--bar), 0 0 0 4px var(--text); }
.swatch.add { background: var(--raised); color: var(--text); font-size: 17px; line-height: 24px; text-align: center; font-weight: 500; }
.size { width: 30px; height: 30px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; transition: background var(--ease); }
.size i { display: block; border-radius: 50%; background: var(--text); }
.size.active { background: var(--raised); }
.seg { display: flex; background: rgba(255, 255, 255, 0.06); border-radius: 9px; padding: 2px; gap: 2px; }
.seg[hidden] { display: none; }
.seg button { padding: 5px 11px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--muted); transition: background var(--ease), color var(--ease); }
.seg button.active { background: var(--raised); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); }
.rec { width: auto; padding: 0 12px 0 10px; gap: 7px; font-size: 13px; font-weight: 600; border-radius: 999px; }
.rec .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); }
.rec.on { background: var(--danger); color: #fff; }
.rec.on .dot { background: #fff; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.25; } }

.editor-body { flex: 1; display: flex; min-height: 0; }
.canvas-wrap { flex: 1; position: relative; overflow: hidden; background: #232430; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

/* Pages sidebar */
.pages { width: 172px; background: var(--panel); border-right: 1px solid var(--hairline); display: flex; flex-direction: column; }
.pages[hidden] { display: none; }
.pages-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 6px 6px 14px; font-size: 13px; color: var(--muted); }
.pages-head label { display: flex; align-items: center; gap: 6px; }
.pages-list { flex: 1; overflow-y: auto; touch-action: pan-y; padding: 4px 14px calc(var(--bottom) + 14px); display: flex; flex-direction: column; gap: 14px; }
.page-item { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.page-thumb { width: 120px; border-radius: 8px; overflow: hidden; box-shadow: var(--shadow-1); background: var(--paper); display: block; transition: transform var(--ease), box-shadow var(--ease); }
.page-thumb.current { box-shadow: 0 0 0 2px var(--accent), var(--shadow-1); }
.page-thumb:active { transform: scale(0.97); }
.page-thumb img { display: block; width: 100%; }
.page-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.star { color: var(--muted); font-size: 16px; padding: 2px 6px; }
.star.on { color: var(--warm); }
#pagesEmpty { text-align: center; padding: 0 12px; }

/* Playback bar */
.playbar {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px calc(var(--bottom) + 8px);
  background: var(--bar); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px); border-top: 1px solid var(--hairline);
}
.playbar[hidden] { display: none; }
.playbar input[type=range] { flex: 1; accent-color: var(--accent); }
.playbar span { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; min-width: 90px; }
.playbar select { background: var(--panel-2); color: var(--text); border: 0; border-radius: 10px; padding: 7px 10px; }
.playbar .tb.active { background: var(--accent); color: #fff; }

/* ── Popovers & menus ────────────────────────────────────────────────── */
.menu {
  position: absolute; right: 10px; top: calc(var(--toolbar-h, 58px) + 6px); z-index: 10;
  background: rgba(38, 39, 47, 0.94); backdrop-filter: blur(30px) saturate(160%); -webkit-backdrop-filter: blur(30px) saturate(160%);
  border-radius: 16px; padding: 8px; width: 300px; box-shadow: var(--shadow-2), inset 0 0 0 1px var(--hairline);
  display: flex; flex-direction: column; gap: 4px;
  transform-origin: top right; animation: pop var(--ease) both;
}
.menu[hidden] { display: none; }
@keyframes pop { from { opacity: 0; transform: scale(0.96) translateY(-4px); } to { opacity: 1; transform: none; } }
.pop-left { right: auto; left: 50%; transform: translateX(-50%); width: 280px; transform-origin: top center; animation: none; }
.menu-title { color: var(--muted); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; padding: 8px 10px 4px; }
.menu-row { display: flex; gap: 4px; padding: 0 2px; }
.menu-row + .menu-row { margin-top: 4px; }
.menu-row button { flex: 1; padding: 8px 0; border-radius: 9px; background: rgba(255, 255, 255, 0.05); font-weight: 500; transition: background var(--ease); }
.menu-row button.active { background: var(--accent); color: #fff; }
.menu-toggle { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; }
.menu-toggle.sub { padding-left: 34px; color: var(--muted); font-size: 13px; }
.menu-toggle input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.menu-toggle select { margin-left: auto; background: var(--raised); color: var(--text); border: 0; border-radius: 9px; padding: 6px 10px; max-width: 160px; }
.menu-item { text-align: left; padding: 10px 10px; border-radius: 10px; font-weight: 500; transition: background var(--ease); }
.menu-item:active { background: var(--raised); }
.menu-item:disabled { opacity: 0.4; }
.menu-col { display: flex; flex-direction: column; gap: 2px; }
.menu-col button { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 10px; text-align: left; font-weight: 500; transition: background var(--ease); }
.menu-col button span { margin-left: auto; color: var(--muted); font-size: 12px; font-weight: 400; }
.menu-col button.active { background: var(--accent); color: #fff; }
.menu-col button.active span { color: rgba(255, 255, 255, 0.75); }
.pen-prev { width: 34px; height: 6px; border-radius: 3px; background: currentColor; display: inline-block; flex: none; }
.pen-prev.ballpoint { height: 3px; }
.pen-prev.fountain { height: 6px; clip-path: polygon(0 40%, 100% 0, 100% 100%, 0 60%); }
.pen-prev.felt { height: 9px; }
.pen-prev.pencil { height: 4px; opacity: 0.6; }
.pen-prev.monoline { height: 4px; }
.pen-prev.calligraphy { height: 8px; clip-path: polygon(0 20%, 30% 0, 100% 60%, 100% 100%, 70% 100%, 0 45%); }
.pen-prev.dashed { height: 3px; background: repeating-linear-gradient(90deg, currentColor 0 7px, transparent 7px 12px); }
.pen-prev.dotted { height: 4px; background: repeating-radial-gradient(circle at 2px 2px, currentColor 0 1.6px, transparent 1.8px 7px); }
.color-pick { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; }
.color-pick input { width: 44px; height: 32px; border: 0; background: none; padding: 0; border-radius: 8px; }
.custom-list { display: flex; flex-direction: column; gap: 2px; }
.custom-row { display: flex; align-items: center; gap: 10px; padding: 5px 10px; border-radius: 10px; }
.custom-row i { width: 24px; height: 24px; border-radius: 50%; display: block; box-shadow: inset 0 0 0 1px var(--hairline); }
.custom-row span { flex: 1; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.custom-row button { color: var(--muted); padding: 4px 8px; }

/* Sheets */
.sheet-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; z-index: 20; animation: fade var(--ease) both; }
.sheet-bg[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  background: var(--panel-2); border-radius: 22px; padding: 20px 20px calc(20px + var(--bottom)); width: min(440px, 92vw);
  box-shadow: var(--shadow-2), inset 0 0 0 1px var(--hairline); animation: rise var(--ease) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.sheet h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.sheet p { margin: 10px 0; }
.sheet .menu-item { width: 100%; font-size: 16px; padding: 12px 12px; }
.sheet .menu-toggle { padding: 10px 12px; font-size: 16px; }
.status { font-weight: 600; }
.phrase-row { display: flex; gap: 8px; align-items: center; margin: 14px 0; }
.phrase-row input {
  flex: 1; background: var(--panel); color: var(--text); border: 0; border-radius: 12px; padding: 12px 14px; font-size: 16px; outline: none;
}
.phrase-row input:focus { box-shadow: 0 0 0 2px var(--accent-soft), 0 0 0 1px var(--accent); }

/* Floating things over the page */
.selbar {
  position: absolute; z-index: 5; display: flex; gap: 2px; padding: 4px; border-radius: 14px;
  background: rgba(38, 39, 47, 0.94); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-1), inset 0 0 0 1px var(--hairline);
}
.selbar[hidden] { display: none; }
.selbar button { padding: 8px 13px; border-radius: 10px; font-weight: 600; font-size: 13px; }
.selbar button:active { background: var(--raised); }

.island {
  position: absolute; z-index: 6; display: flex; align-items: center; gap: 2px; padding: 6px 8px 6px 4px;
  background: rgba(38, 39, 47, 0.92); backdrop-filter: blur(24px) saturate(160%); -webkit-backdrop-filter: blur(24px) saturate(160%);
  border-radius: 20px; box-shadow: var(--shadow-2), inset 0 0 0 1px var(--hairline); max-width: calc(100% - 16px);
}
.island[hidden] { display: none; }
.island { max-height: calc(100% - 16px); overflow: auto; cursor: grab; }
.island .sep { flex: none; }
.island-grip { color: var(--muted); font-size: 16px; padding: 6px 5px; cursor: grab; touch-action: none; letter-spacing: -3px; }
.island .tb-group.tools { background: none; padding: 0; flex-wrap: wrap; justify-content: flex-start; }
.island.vertical { flex-direction: column; padding: 6px 6px 8px; max-width: 64px; }
.island.vertical .tb-group.tools { width: 100%; align-items: center; }
.island.vertical .swatches, .island.vertical .sizes { padding: 2px 0; }
.island.vertical .island-grip { letter-spacing: 0; padding: 2px 6px 6px; transform: rotate(90deg); }
.island.vertical .tb-group.tools { flex-direction: column; }
.island.vertical .sep { width: 22px; height: 1px; margin: 5px 0; }
.island.vertical .swatches, .island.vertical .sizes { flex-direction: column; }
.island.vertical .seg { flex-direction: column; }
.toolbar.compact { justify-content: space-between; }

.text-edit {
  position: absolute; z-index: 4; margin: 0; padding: 0; border: 1.5px dashed var(--accent); border-radius: 4px; background: rgba(10, 132, 255, 0.05);
  resize: none; overflow: hidden; outline: none; font-family: -apple-system, "SF Pro Text", system-ui, sans-serif; box-sizing: content-box;
}
.text-edit[hidden] { display: none; }
