:root { font-family: system-ui, sans-serif; color: #303a35; background: #f4f1e9; --bar-height: 80px; --bottom-bar-height: 80px; }
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; }
body { user-select: none; -webkit-user-select: none; }
.symbols { position: absolute; width: 0; height: 0; }
.toolbar { position: fixed; z-index: 2; top: 0; left: 0; right: 0; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 18px; padding: max(12px, env(safe-area-inset-top)) 12px 12px; background: #f4f1e9; border-bottom: 1px solid #dedfd6; }
.toolbar.bottom-toolbar { top: auto; bottom: 0; border-bottom: 0; border-top: 1px solid #dedfd6; padding: 12px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
.toolbar.bottom-toolbar { container-type: inline-size; flex-wrap: nowrap; gap: 6px; }
.bottom-toolbar .colors { display: grid; flex: 1; max-width: 688px; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 0; }
.bottom-toolbar .colors button { justify-self: center; width: 100%; max-width: 50px; padding: 0; }
.bottom-toolbar .tools { flex: none; gap: 4px; }
.bottom-toolbar .tools button { width: clamp(44px, 6.8cqw, 50px); }
.bottom-toolbar .color span { width: clamp(24px, 3.8cqw, 30px); height: clamp(24px, 3.8cqw, 30px); }
#color-picker { display: none; }
#color-picker span { width: 28px; height: 28px; border-radius: 50%; border: 1px solid #0004; background: var(--color, #292d32); }
@container (max-width: 647px) {
  #color-picker { display: grid; }
  .bottom-toolbar .divider { display: none; }
  #palette { display: none; }
  #color-picker[aria-expanded="true"] + #palette { display: grid; position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); width: min(300px, 96%); padding: 8px; grid-template-columns: repeat(6, 1fr); gap: 2px; background: #f9faf5; border: 1px solid #bcc8b9; border-radius: 14px; box-shadow: 0 4px 16px #26382b26; }
}
.pages { display: flex; align-items: center; gap: 2px; }
#pressure-monitor { position: absolute; top: calc(100% + 4px); right: max(8px, env(safe-area-inset-right)); width: min(270px, calc(100% - 16px)); box-sizing: border-box; display: grid; gap: 8px; padding: 12px; border: 1px solid #bdc9bd; border-radius: 12px; background: #fff; font-size: 13px; color: #526052; font-variant-numeric: tabular-nums; }
#pressure-monitor[hidden] { display: none; }
#pressure-monitor button { width: auto; height: auto; min-height: 36px; border: 1px solid #bdc9bd; }
.pressure-heading { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
#pressure-monitor meter { display: block; width: 100%; height: 10px; accent-color: #526b57; }
.notebook-picker { position: relative; display: flex; align-items: center; color: #405d46; }
.notebook-picker > svg { position: absolute; left: 12px; width: 22px; height: 22px; pointer-events: none; }
.notebook-picker > .dropdown-arrow { left: auto; right: 10px; width: 18px; }
#notebook-select { appearance: none; -webkit-appearance: none; width: 176px; min-height: 50px; padding: 10px 32px 10px 42px; border: 1px solid #b7c3b5; border-radius: 14px; background: #e8ede3; color: inherit; font: inherit; font-size: 14px; cursor: pointer; touch-action: manipulation; }
#notebook-select:focus-visible { outline: 3px solid #3265b0; outline-offset: 3px; }
#notebook-select:disabled { opacity: .5; cursor: default; }
#paper[data-notebook="dotted"] { background-image: radial-gradient(circle at center, #8b979e var(--dot-radius, 1px), transparent var(--dot-edge, 1.3px)); background-size: var(--dot-spacing, 24px) var(--dot-spacing, 24px); background-position: 0 0; }
#page-count { min-width: 48px; text-align: center; font-size: 14px; font-variant-numeric: tabular-nums; }
.toolbar button:disabled { opacity: .3; cursor: default; }
.colors, .tools { display: flex; gap: 8px; align-items: center; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; font: inherit; }
.toolbar button { position: relative; display: grid; place-items: center; flex: 0 0 auto; width: 50px; height: 50px; border-radius: 14px; border: 2px solid transparent; background: transparent; color: #4f5c54; padding: 10px; }
.toolbar button[aria-pressed="true"] { background: #dfe8dd; border-color: #526b57; }
.toolbar .color { padding: 7px; border-radius: 50%; }
.color span { width: 30px; height: 30px; border-radius: 50%; background: var(--color); border: 1px solid #0002; }
.toolbar .color[aria-pressed="true"] { background: transparent; border-color: #38463c; }
.color[aria-pressed="true"]::after { content: ''; position: absolute; width: 8px; height: 8px; background: white; border-radius: 50%; box-shadow: 0 0 0 1px #0005; }
button:focus-visible { outline: 3px solid #3265b0; outline-offset: 3px; }
svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.divider { height: 28px; width: 1px; background: #d2d8cf; }
.slash { display: none; stroke-width: 2.5; }
#touch-button[aria-pressed="false"] .slash { display: block; }
#workspace { position: fixed; top: var(--bar-height); bottom: var(--bottom-bar-height); left: 0; right: 0; overflow: hidden; background: #c9ccca; touch-action: none; }
#paper { position: absolute; inset: 0; overflow: hidden; background: white; }
#activity-background { position: absolute; top: 0; left: 0; pointer-events: none; }
#activity-background > svg { display: block; width: 100%; height: 100%; stroke-width: 6; }
#paper canvas { position: relative; }
#ruled-background { display: none; position: absolute; inset: 0; pointer-events: none; }
#paper[data-notebook="ruled"] #ruled-background { display: block; }
#ruled-header { position: absolute; top: 0; left: 0; right: 0; height: var(--ruled-header-height); }
#ruled-header svg, .ruled-lines svg { display: block; width: 100%; height: 100%; }
#ruled-header text { stroke: none; font-weight: 400; }
.ruled-lines { position: absolute; inset: 0; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
canvas.stylus-hover { cursor: none; }
#hover-marker { position: absolute; pointer-events: none; transform: translate(-50%, -50%); border-radius: 50%; background: transparent; box-shadow: inset 0 0 0 .75px #303a35; }
#status { position: fixed; z-index: 3; bottom: calc(var(--bottom-bar-height) + 12px); left: 12px; right: 12px; margin: 0; padding: 12px; background: #fff4da; border: 1px solid #b89e65; font-size: 14px; }
#pen-panel, #eraser-panel { position: fixed; z-index: 4; right: 12px; bottom: calc(var(--bottom-bar-height) + 10px); width: min(296px, calc(100vw - 24px)); max-height: calc(100dvh - var(--bottom-bar-height) - var(--bar-height) - 20px); overflow-y: auto; padding: 16px; border: 1px solid #bcc8b9; border-radius: 18px; background: #f9faf5; box-shadow: 0 6px 24px #26382b26; }
.pen-panel-heading { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
#pen-width-value, #eraser-width-value { font-variant-numeric: tabular-nums; }
.width-presets { display: flex; gap: 6px; margin: 12px 0 4px; }
.width-presets button { width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid #c8d2c4; border-radius: 10px; background: white; }
.width-presets button[aria-pressed="true"] { background: #dfe8dd; border: 2px solid #526b57; }
.width-presets span { display: block; width: var(--size); height: var(--size); border-radius: 50%; background: #303a35; }
#pen-width, #eraser-width { width: 100%; height: 36px; margin: 4px 0; accent-color: #526b57; touch-action: none; }
.pressure-option { display: flex; align-items: center; gap: 8px; min-height: 44px; font-size: 14px; cursor: pointer; }
.pressure-option input { width: 22px; height: 22px; accent-color: #526b57; }
#pen-panel p, #eraser-panel p { margin: 4px 0 0; font-size: 12px; line-height: 1.4; color: #606c62; }
dialog { max-width: min(420px, 90vw); border: 1px solid #cbd4c8; border-radius: 20px; padding: 24px; color: inherit; }
dialog::backdrop { background: #24312766; }
dialog h1 { font-size: 22px; margin-top: 0; }
dialog p { line-height: 1.5; }
dialog form { display: flex; gap: 10px; flex-wrap: wrap; }
dialog button { padding: 12px 16px; min-height: 48px; background: white; border: 1px solid #b7c3b5; border-radius: 10px; }
dialog .confirm { background: #405d46; color: white; }
@media (max-width: 650px) { .toolbar { gap: 6px; padding-inline: 6px; flex-wrap: wrap; } .colors, .tools { gap: 2px; } .toolbar button { width: 44px; height: 44px; padding: 8px; } .divider { margin: 0 2px; } }
@media (max-width: 470px) { .divider { display: none; } .tools { justify-content: center; } }

#calibration { width: min(360px, 92vw); max-height: 88dvh; overflow: auto; }
#calibration h2 { margin: 0; font-size: 20px; }
#cal-pad { display: grid; place-items: center; height: clamp(76px, 21vh, 150px); border: 1px dashed #779281; border-radius: 12px; background: #f3f6ef; color: #536658; touch-action: none; user-select: none; }
#cal-meter { width: 100%; }
#cal-values { font-variant-numeric: tabular-nums; font-size: 13px; min-height: 1.5em; }
.cal-actions { display: flex; flex-wrap: wrap; gap: 6px; }

#account-form { display: grid; margin-bottom: 12px; }
#account-form label { display: grid; gap: 4px; }
#account-dialog [hidden] { display: none; }
#account-form input { padding: 10px; border: 1px solid #a8b6a9; border-radius: 8px; font: inherit; }
#account-error { color: #923329; }
#account-button[data-sync]::after { content: ''; position: absolute; right: 5px; bottom: 5px; width: 8px; height: 8px; border-radius: 50%; background: #b87f32; }
#account-button[data-sync="synced"]::after { background: #448051; }

#notebook-select { display:flex; gap:.45em; width:auto; max-width:min(36vw,230px); padding:0 12px; border:1px solid #bdc9bd; background:#eaf0e6; }
#notebook-select span { white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
#quick-back[hidden], #library-panel [hidden], #library-panel[hidden], #library-shade[hidden] { display:none; }
#library-shade { position:fixed; inset:var(--bar-height) 0 0; background:#24312744; z-index:5; }
#library-panel { position:fixed; top:var(--bar-height); bottom:0; left:0; width:50vw; box-sizing:border-box; overflow:auto; overscroll-behavior:contain; z-index:6; padding:16px; background:#faf9f5; color:#304036; box-shadow:3px 0 16px #22352722; }
#library-panel header,.library-row { display:flex; align-items:center; gap:6px; }
#library-panel header { justify-content:space-between; }
#library-panel h2 { margin:0; font-size:1.2rem; }
#library-panel button { min-height:42px; border:0; border-radius:8px; background:transparent; color:inherit; padding:6px 10px; text-align:left; font:inherit; }
#library-panel button:hover,#library-panel button:focus-visible { background:#e8eee5; }
#library-panel input,#library-panel select,#library-panel textarea { box-sizing:border-box; font:inherit; width:100%; padding:9px; border:1px solid #bcc7bc; border-radius:8px; background:white; }
#library-search { margin:12px 0; }
.library-row > :first-child { flex:1; overflow-wrap:anywhere; }
.library-row.book { padding-left:20px; }
.library-row [aria-current="true"] { background:#dfe9de; font-weight:600 !important; }
#library-form label { display:grid; gap:4px; margin:10px 0; }
#library-form input[type=color] { padding:2px; max-width:70px; }
#library-actions { display:grid; gap:10px; padding-bottom:16px; margin-bottom:8px; border-bottom:1px solid #c6cec6; }
#library-actions button { display:flex; align-items:center; gap:12px; min-height:52px; padding:7px 12px; border:2px solid #496350; border-radius:10px; background:white; color:#294634; box-shadow:0 2px 0 #536658; font-weight:650; }
#library-actions #new-folder { background:#375941; color:white; border-color:#2c4934; }
#library-actions svg { box-sizing:content-box; width:24px; height:24px; padding:4px; flex:none; border-radius:6px; background:#e3ebe3; color:#294634; stroke-width:2; }
#library-actions #new-folder svg { background:white; }
#library-actions button:active { transform:translateY(2px); box-shadow:none; }
#library-panel h2 { overflow-wrap:anywhere; }
@media(max-width:540px){ #library-panel { width:92vw; } }
