:root {
  --paper: #fefdfc;
  --ink: rgb(42, 38, 36);
  --ink-soft: rgba(42, 38, 36, .55);
  --red: #ad2619;
  --ui: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", sans-serif;
  --mono: "Courier Prime", "Courier New", Courier, monospace;
  --ease: cubic-bezier(.2, .85, .25, 1);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); overflow: hidden; overscroll-behavior: none; }
body { font-family: var(--ui); -webkit-font-smoothing: antialiased; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; }

#paper { position: fixed; inset: 0; touch-action: none; cursor: default; }
#keys {
  position: fixed; left: 50%; top: 40%; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0;
  font-size: 16px; resize: none; caret-color: transparent; background: transparent; color: transparent; pointer-events: none;
}

/* ── chrome: quiet icons that fade while typing ── */
.chrome {
  position: fixed; z-index: 5; width: 36px; height: 36px; border: 0; border-radius: 10px; background: transparent;
  color: rgba(42, 38, 36, .32); display: grid; place-items: center; cursor: pointer; transition: opacity .6s, color .2s, background .2s;
}
.chrome:hover { color: rgba(42, 38, 36, .7); background: rgba(42, 38, 36, .05); }
#ov-btn { left: calc(14px + env(safe-area-inset-left)); bottom: calc(14px + env(safe-area-inset-bottom)); }
#menu-btn { right: calc(14px + env(safe-area-inset-right)); top: calc(12px + env(safe-area-inset-top)); }
body.typing .chrome { opacity: 0; transition: opacity 1.2s; }
body:not(.open) .chrome, body:not(.open) #knob { display: none; }

#menu {
  position: fixed; z-index: 20; right: calc(14px + env(safe-area-inset-right)); top: calc(52px + env(safe-area-inset-top));
  width: 260px; padding: 8px; border-radius: 14px; background: rgba(255, 254, 252, .92);
  backdrop-filter: blur(20px) saturate(1.4); -webkit-backdrop-filter: blur(20px) saturate(1.4);
  box-shadow: 0 10px 40px rgba(40, 34, 28, .16), 0 0 0 .5px rgba(40, 34, 28, .12); font-size: 13px;
  animation: pop .18s var(--ease);
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
#menu button { display: flex; align-items: center; width: 100%; text-align: left; padding: 9px 10px; border: 0; background: none; border-radius: 8px; cursor: pointer; }
#menu button:hover { background: rgba(42, 38, 36, .06); }
#menu kbd { margin-left: auto; font: 11px var(--ui); color: var(--ink-soft); }
#menu .toggle::before { content: ""; width: 14px; margin-right: 8px; text-align: center; }
#menu .toggle.on::before { content: "✓"; }
#menu hr { border: 0; height: .5px; background: rgba(42, 38, 36, .12); margin: 6px 4px; }
#menu .row { display: flex; gap: 4px; }
#menu .row button { justify-content: center; }
#menu .row button:not(#m-zoom0) { width: 44px; flex: none; font-size: 16px; }
@media (pointer: coarse) { #menu kbd { display: none; } #menu button { padding: 12px 10px; font-size: 15px; } }

/* the plastic housing at the right edge, level with the chrome rod */
#knob {
  position: fixed; z-index: 4; right: 0; top: var(--rod-y, 50%); transform: translateY(-50%);
  width: 26px; height: 46px; border: 0; padding: 0 0 0 9px; cursor: pointer;
  border-radius: 23px 0 0 23px; background: linear-gradient(#545250, #3d3c3a 45%, #2b2a29);
  box-shadow: -1px 2px 6px rgba(0, 0, 0, .28); display: flex; flex-direction: column; justify-content: center; gap: 5px;
}
#knob i { display: block; height: 1px; width: 12px; background: rgba(255, 255, 255, .14); border-radius: 1px; }
@media (pointer: coarse) { #knob { width: 32px; height: 56px; } }

#toast {
  position: fixed; z-index: 30; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: min(90vw, 460px); padding: 10px 16px; border-radius: 12px; font-size: 13px; text-align: center;
  background: rgba(42, 38, 36, .88); color: #fff; box-shadow: 0 6px 24px rgba(0, 0, 0, .2);
}

/* ── screens: sign in, create / open the diary ── */
#screen { position: fixed; inset: 0; z-index: 40; background: var(--paper); display: grid; place-items: center; padding: 24px; overflow: auto; transition: opacity .3s; }
#screen.fade { opacity: 0; }
.card { width: min(360px, 100%); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.card form { display: contents; }
.card.shake { animation: shake .4s; }
@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(4px); } }
.mark { width: 120px; height: 120px; margin: -10px 0 -6px; }
.card h1 { font-size: 21px; font-weight: 600; margin: 0; }
.card .sub { font-size: 13px; line-height: 1.5; color: var(--ink-soft); margin: 0; }
.card .fine { font-size: 11px; color: rgba(42, 38, 36, .4); margin: 6px 0 0; }
.card .fine a { color: inherit; }
.card input {
  width: 260px; max-width: 100%; padding: 11px 14px; font-size: 16px; text-align: center; border-radius: 10px;
  border: .5px solid rgba(42, 38, 36, .2); background: #fff; outline: none; user-select: text; -webkit-user-select: text;
}
.card input:focus { border-color: rgba(42, 38, 36, .45); box-shadow: 0 0 0 3px rgba(42, 38, 36, .06); }
.card .err { min-height: 16px; margin: -4px 0; font-size: 12px; color: var(--red); }
.card .primary {
  display: inline-flex; align-items: center; gap: 10px; padding: 11px 26px; border-radius: 22px; border: 0; cursor: pointer;
  background: var(--ink); color: #fff; font-size: 14px; font-weight: 500;
}
.card .primary:disabled { opacity: .5; }
.card .primary.google { background: #fff; color: var(--ink); box-shadow: 0 0 0 .5px rgba(42, 38, 36, .25), 0 2px 8px rgba(0, 0, 0, .06); }
.card .link { border: 0; background: none; color: var(--ink-soft); font-size: 12px; cursor: pointer; }
.card .code {
  font: 700 19px/1.6 var(--mono); letter-spacing: .04em; padding: 14px 18px; border-radius: 8px; background: #fff;
  border: .5px solid rgba(42, 38, 36, .15); user-select: all; -webkit-user-select: all; word-break: break-word;
}
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(42, 38, 36, .15); border-top-color: var(--ink); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── overview ── */
.ov { position: fixed; inset: 0; z-index: 25; background: var(--paper); display: grid; grid-template-rows: 1fr auto auto; transition: background .5s, opacity .3s; }
.ov.in { background: #edecea; }
.ov.fade { opacity: 0; }
.ov-stage { position: relative; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
.ov-spacer { position: absolute; left: 0; width: 1px; height: 1px; }
.ov-sheet, .ov-add { position: absolute; }
.ov-sheet { background: var(--paper); box-shadow: 0 5px 18px rgba(64, 56, 46, .14), 0 0 0 .5px rgba(64, 56, 46, .08); cursor: grab; touch-action: pan-y; }
.ov-sheet canvas { width: 100%; height: 100%; display: block; pointer-events: none; }
.ov-sheet.dragging, .ov-sheet.lifted { z-index: 10; box-shadow: 0 16px 40px rgba(64, 56, 46, .24); cursor: grabbing; }
.ov-sheet.selected { outline: 2.5px solid rgba(42, 38, 36, .75); outline-offset: 0; }
.ov-sheet.gone { transform: scale(.6); opacity: 0; transition: transform .25s, opacity .25s !important; }
.ov-label { position: absolute; left: 0; right: 0; top: 100%; margin-top: 8px; text-align: center; font-size: 11px; color: rgba(42, 38, 36, .4); }
.ov-label.current { color: rgba(42, 38, 36, .85); font-weight: 600; }
.ov-x, .ov-badge {
  position: absolute; width: 24px; height: 24px; border-radius: 12px; display: grid; place-items: center; font-size: 11px; font-weight: 700;
  color: #fff; background: rgba(76, 74, 72, .92); border: 0; box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
.ov-x { left: -10px; top: -10px; opacity: 0; transition: opacity .15s; cursor: pointer; }
.ov-sheet:hover .ov-x { opacity: 1; }
@media (pointer: coarse) { .ov-x { opacity: .9; } }
.ov-badge { right: -10px; top: -10px; opacity: 0; background: rgba(42, 38, 36, .9); }
.ov-sheet.selected .ov-badge { opacity: 1; }
.ov-add { border: 1.5px dashed rgba(42, 38, 36, .25); border-radius: 4px; display: grid; place-items: center; cursor: pointer; transition: opacity .3s; }
.ov-add span { font-size: 40px; font-weight: 200; color: rgba(42, 38, 36, .35); }
.ov-shelf-title { text-align: center; font-size: 9.5px; font-weight: 600; letter-spacing: .08em; color: rgba(42, 38, 36, .35); padding-top: 6px; }
.ov-shelf {
  display: flex; gap: 22px; padding: 10px max(24px, calc(50% - 300px)) calc(16px + env(safe-area-inset-bottom)); overflow-x: auto; justify-content: safe center;
  scrollbar-width: none;
}
.ov-shelf::-webkit-scrollbar { display: none; }
.ov-toolbar { position: fixed; top: calc(12px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: flex; gap: 10px; align-items: center; z-index: 3; }
.ov-btn { padding: 5px 12px; font-size: 12px; border-radius: 7px; border: .5px solid rgba(42, 38, 36, .22); background: #fff; cursor: pointer; }
.ov-btn:disabled { opacity: .45; }
.ov-btn.ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.ov-count { font-size: 12px; color: var(--ink-soft); }
.ov:not(.in) .ov-toolbar, .ov:not(.in) .ov-shelf, .ov:not(.in) .ov-shelf-title, .ov:not(.in) .ov-label, .ov:not(.in) .ov-add { opacity: 0; }
.ov-toolbar, .ov-shelf, .ov-shelf-title, .ov-label, .ov-add { transition: opacity .4s; }

/* notebooks on the shelf */
.nb { flex: none; width: 104px; padding: 8px 4px 6px; border-radius: 10px; text-align: center; cursor: pointer; position: relative; transition: transform .25s var(--ease), background .2s; touch-action: pan-x; }
.nb.current { background: rgba(42, 38, 36, .055); }
.nb.dragging { z-index: 5; cursor: grabbing; }
.nb.gone { opacity: 0; transform: scale(.6); transition: .25s; }
.nb-stack { position: relative; width: 50px; height: 71px; margin: 0 auto; }
.nb .p { position: absolute; inset: 0; background: var(--paper); border: .5px solid rgba(64, 56, 46, .14); box-shadow: 0 2px 4px rgba(64, 56, 46, .12); transform-origin: 50% 100%; transition: transform .28s var(--ease); }
.nb .p1 { transform: translate(6px, 6px); } .nb .p2 { transform: translate(3px, 3px); }
.nb.current .p1 { transform: rotate(-7deg); } .nb.current .p2 { transform: rotate(5deg); }
.nb.opening { transform: scale(1.08); }
.nb.opening .p1 { transform: rotate(-4deg); } .nb.opening .p2 { transform: rotate(6deg); }
.nb.opening .p3 { transform: rotate(-24deg) translate(-3px, -4px); }
.nb .p3 i { display: block; height: 1px; margin: 5px 9px 0 7px; background: rgba(42, 38, 36, .35); }
.nb .p3 i:first-child { margin-top: 10px; } .nb .p3 i.s { margin-right: 22px; }
.nb-dash { position: absolute; inset: 0; border: 1.2px dashed rgba(42, 38, 36, .3); border-radius: 3px; display: grid; place-items: center; font-size: 24px; font-weight: 200; color: rgba(42, 38, 36, .4); transition: transform .28s var(--ease); }
.nb.new.opening .nb-dash { transform: scale(1.08); }
.nb-name { margin-top: 10px; font-size: 11px; font-weight: 500; color: rgba(42, 38, 36, .72); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: text; }
.nb.new .nb-name { cursor: pointer; }
.nb.current .nb-name { font-weight: 600; color: rgba(42, 38, 36, .95); text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 4px; text-decoration-color: rgba(42, 38, 36, .6); }
.nb-count { font-size: 9.5px; color: rgba(42, 38, 36, .4); margin-top: 2px; }
.nb-x { position: absolute; left: 14px; top: 1px; width: 20px; height: 20px; border-radius: 10px; border: 0; background: rgba(76, 74, 72, .92); color: #fff; font-size: 9px; font-weight: 700; opacity: 0; transition: opacity .15s; cursor: pointer; }
.nb:hover .nb-x { opacity: 1; }
.nb.current .nb-x { display: none; }
.nb-rename { width: 100%; margin-top: 8px; font-size: 11px; font-weight: 600; text-align: center; border: .5px solid rgba(42, 38, 36, .3); border-radius: 5px; padding: 2px 4px; outline: none; user-select: text; -webkit-user-select: text; }

/* privacy torch controls */
#torch {
  position: fixed; z-index: 6; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; gap: 22px; padding: 10px 18px; border-radius: 14px; background: rgba(28, 26, 24, .72); color: rgba(255, 245, 230, .75);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); font-size: 11px; transition: opacity .6s;
}
#torch label { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
#torch input { width: 120px; accent-color: #e9c48a; }
body.typing #torch { opacity: 0; transition: opacity 1.2s; }
body.privacy .chrome { color: rgba(255, 245, 230, .35); }
body.privacy .chrome:hover { color: rgba(255, 245, 230, .8); background: rgba(255, 255, 255, .06); }
body.privacy #knob { filter: brightness(.35); }
body.privacy .ov-sheet canvas { filter: blur(5px) brightness(.25); }
body.privacy .ov.in { background: #151413; }
body.privacy .ov-label, body.privacy .ov-shelf-title, body.privacy .nb-name, body.privacy .nb-count, body.privacy .ov-count { color: rgba(255, 245, 230, .5); }
@media (max-width: 600px) { #torch { flex-direction: column; gap: 8px; } #torch input { width: 150px; } }
