/* ===== Inkly, design tokens ===== */
:root {
  --desk:      #16181f;   /* dark desk surface */
  --desk-2:    #1d2029;   /* raised panels */
  --desk-3:    #262a35;   /* inputs, controls */
  --line:      #333845;   /* hairline borders */
  --paper:     #fbfaf4;   /* the sheet */
  --ink:       #3f63e8;   /* fountain pen blue accent */
  --ink-soft:  #6f8cf0;
  --red:       #d2493c;   /* red pen, used sparingly */
  --text:      #e9eaef;   /* primary text on desk */
  --muted:     #9aa0b0;   /* secondary text */
  --faint:     #6c7283;

  --mono: "Space Mono", ui-monospace, monospace;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
  --hand: "Caveat", cursive;

  --radius: 14px;
  --shadow: 0 24px 60px -18px rgba(0,0,0,.6), 0 8px 24px -12px rgba(0,0,0,.5);
  --topbar-h: 57px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(1200px 700px at 78% -10%, rgba(63,99,232,.10), transparent 60%),
    var(--desk);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body { display: flex; flex-direction: column; }

button, input, textarea, select { font: inherit; color: inherit; }

/* ===== Access gate ===== */
.gate {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 600px at 50% -10%, rgba(63,99,232,.16), transparent 60%),
    var(--desk);
}
html.authed .gate { display: none; }
.gate__card {
  width: min(380px, 100%);
  background: var(--desk-2); border: 1px solid var(--line);
  border-radius: 18px; padding: 36px 32px; text-align: center;
  box-shadow: var(--shadow);
}
.gate__brand { font-family: var(--hand); font-size: 52px; line-height: 1; font-weight: 700; }
.gate__tag {
  font-family: var(--mono); font-size: 11px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--muted); margin: 8px 0 24px;
}
.gate form { display: flex; flex-direction: column; gap: 10px; }
.gate input {
  width: 100%; background: var(--desk-3); border: 1px solid var(--line);
  border-radius: 10px; padding: 13px; text-align: center; outline: none;
  letter-spacing: .1em;
}
.gate input:focus { border-color: var(--ink); }
.gate__err { color: var(--red); font-size: 13px; margin: 14px 0 0; }

/* ===== Topbar ===== */
.topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--desk) 86%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand__mark { align-self: center; display: inline-flex; }
.brand__name { font-family: var(--hand); font-size: 32px; line-height: 1; font-weight: 700; letter-spacing: .5px; }

/* ===== Layout: two independently scrolling columns ===== */
.layout {
  flex: 1 1 auto; min-height: 0;
  display: grid;
  grid-template-columns: minmax(320px, 380px) 1fr;
  gap: clamp(16px, 2.4vw, 34px);
  padding: clamp(16px, 2.4vw, 30px);
  max-width: 1500px; width: 100%; margin: 0 auto;
}

/* ===== Controls panel (scrolls on its own) ===== */
.panel {
  height: 100%; min-height: 0; overflow-y: auto;
  background: var(--desk-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 14px 24px 20px;
  -webkit-overflow-scrolling: touch;
}

/* clean, minimal scrollbars on the scroll containers */
.panel, .stage__paperwrap { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.panel::-webkit-scrollbar,
.stage__paperwrap::-webkit-scrollbar { width: 10px; height: 10px; }
.panel::-webkit-scrollbar-track,
.stage__paperwrap::-webkit-scrollbar-track { background: transparent; }
.panel::-webkit-scrollbar-thumb,
.stage__paperwrap::-webkit-scrollbar-thumb {
  background: var(--line); border-radius: 999px;
  border: 3px solid transparent; background-clip: padding-box;
}
.panel::-webkit-scrollbar-thumb:hover,
.stage__paperwrap::-webkit-scrollbar-thumb:hover {
  background: var(--faint); background-clip: padding-box;
}
.panel::-webkit-scrollbar-button,
.stage__paperwrap::-webkit-scrollbar-button { display: none; width: 0; height: 0; }

/* grouped sections */
.group {
  display: flex; flex-direction: column; gap: 14px;
  padding-top: 20px; margin-top: 20px;
  border-top: 1px solid var(--line);
}
.panel > .group:first-child { padding-top: 14px; margin-top: 0; border-top: 0; }
.group__title {
  font-family: var(--mono); font-size: 11px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--text);
}
/* collapsible groups via <details> */
details.group > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; }
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary::after {
  content: ""; width: 7px; height: 7px; margin-right: 2px;
  border-right: 2px solid var(--faint); border-bottom: 2px solid var(--faint);
  transform: rotate(-45deg); transition: transform .15s;
}
details.group[open] > summary::after { transform: rotate(45deg); }

.field { display: flex; flex-direction: column; gap: 11px; }
.field__label {
  font-family: var(--mono); font-size: 11px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--muted);
}

.textinput {
  width: 100%; resize: vertical; min-height: 96px;
  background: var(--desk-3); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 13px; line-height: 1.5;
  color: var(--text); outline: none; transition: border-color .15s;
}
.textinput:focus { border-color: var(--ink); }

/* font picker */
.fontgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fontchip {
  text-align: left; cursor: pointer;
  background: var(--desk-3); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 11px; transition: border-color .15s, background .15s;
  display: flex; flex-direction: column; gap: 1px;
}
.fontchip:hover { border-color: var(--faint); }
.fontchip[aria-pressed="true"] { border-color: var(--ink); background: color-mix(in srgb, var(--ink) 14%, var(--desk-3)); }
.fontchip .sample { font-size: 21px; line-height: 1.1; color: var(--text); }
.fontchip .cap { font-family: var(--mono); font-size: 9px; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); }

/* colors */
.ink__row { display: flex; flex-direction: column; gap: 9px; }
.ink { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ink__swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; box-shadow: 0 0 0 1px var(--line) inset;
  padding: 0; transition: transform .12s;
}
.swatch:hover { transform: scale(1.08); }
.swatch[aria-pressed="true"] { border-color: var(--text); box-shadow: 0 0 0 2px var(--desk-2), 0 0 0 4px currentColor; }
.ink__custom { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); cursor: pointer; }
.ink__custom input[type="color"] { width: 28px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: none; cursor: pointer; }

/* segmented (paper) */
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; background: var(--desk-3); border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.seg button {
  cursor: pointer; border: 0; background: transparent; color: var(--muted);
  padding: 8px 4px; border-radius: 7px; font-size: 12.5px; transition: background .15s, color .15s;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }

/* sliders, now with numeric readouts */
.slider { display: flex; flex-direction: column; gap: 7px; }
.slider__head { display: flex; justify-content: space-between; align-items: baseline; }
.slider__head label { font-size: 12.5px; color: var(--muted); }
.slider__val { font-family: var(--mono); font-size: 12px; color: var(--text); letter-spacing: .04em; }
input[type="range"] {
  -webkit-appearance: none; appearance: none; height: 4px; border-radius: 3px;
  background: var(--desk-3); outline: none; width: 100%;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--ink); cursor: pointer; border: 2px solid var(--desk-2);
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; background: var(--ink);
  cursor: pointer; border: 2px solid var(--desk-2);
}

/* ===== Stage / preview (scrolls on its own; actions pinned) ===== */
.stage { height: 100%; min-height: 0; display: flex; flex-direction: column; min-width: 0; }
.stage__paperwrap {
  flex: 1 1 auto; min-height: 0; overflow: hidden;
  display: flex; justify-content: center; align-items: center;
  background: radial-gradient(900px 500px at 50% 0%, rgba(63,99,232,.07), transparent 60%);
  padding: clamp(10px, 2vw, 22px);
  border-radius: var(--radius);
}
/* scale the sheet so the whole A4 page is always visible */
.paper {
  width: auto; height: auto;
  max-width: min(720px, 100%); max-height: 100%;
  aspect-ratio: 1240 / 1754;
  background: var(--paper); border-radius: 4px;
  box-shadow: var(--shadow);
  touch-action: none;        /* let us handle pinch-zoom / pan ourselves */
  will-change: transform;
}

.stage__foot { flex: 0 0 auto; padding-top: 12px; }
.stage__bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
}
.pager { display: flex; align-items: center; gap: 10px; }
.pager[data-hidden="true"] { visibility: hidden; }
.pager__info { font-family: var(--mono); font-size: 12px; color: var(--muted); letter-spacing: .06em; }
.exports { display: flex; gap: 10px; margin-left: auto; }
/* ===== Buttons ===== */
.btn {
  cursor: pointer; border: 1px solid var(--line); background: var(--desk-3);
  color: var(--text); padding: 10px 16px; border-radius: 9px; font-size: 13.5px;
  font-weight: 500; transition: border-color .15s, background .15s, transform .08s;
}
.btn:hover { border-color: var(--faint); }
.btn:active { transform: translateY(1px); }
.btn--ghost { background: transparent; }
.btn--primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn--primary:hover { background: color-mix(in srgb, var(--ink) 86%, #fff); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

:focus-visible { outline: 2px solid var(--ink-soft); outline-offset: 2px; }

/* ===== Footer ===== */
.foot {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding: 14px clamp(16px, 3vw, 32px);
  border-top: 1px solid var(--line);
  font-family: var(--mono); font-size: 11px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--faint);
}
.foot nav { display: flex; gap: 18px; }
.foot a { color: var(--muted); text-decoration: none; }
.foot a:hover { color: var(--text); }

/* ===== Mobile / iPad: revert to natural page scroll ===== */
@media (max-width: 940px) {
  html, body { height: auto; }
  body { min-height: 100%; }
  .layout { grid-template-columns: 1fr; }
  .panel { height: auto; overflow: visible; }
  .stage { height: auto; }
  .stage__paperwrap { overflow: visible; }
  .paper { touch-action: pan-y; } /* restore native one-finger page scroll */
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
