/* ==========================================================================
   Studio

   Two layouts from one grid. On a desktop the tools are a rail down the
   left and the properties a column on the right. On a phone the tools
   become a bar along the bottom and the properties a sheet that slides up
   — the page itself keeps the room, because the page is the point.
   ========================================================================== */

/* ---------- Start screen ---------- */

.st-start { padding: var(--space-10) 0 var(--space-12); }
.st-start__title { margin: var(--space-2) 0 var(--space-3); font-size: var(--fs-3xl); letter-spacing: -0.03em; }
.st-start__sub { margin: 0 0 var(--space-8); max-width: 54ch; color: var(--text-dim); }

.st-drop {
  display: grid;
  place-items: center;
  gap: var(--space-2);
  padding: var(--space-10) var(--space-6);
  text-align: center;
  cursor: pointer;
  border: 2px dashed var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-2);
  transition: border-color .18s ease, background .18s ease;
}
.st-drop:hover, .st-drop.is-over { border-color: var(--accent); background: var(--accent-wash); }
.st-drop__icon { width: 34px; height: 34px; fill: var(--accent); }
.st-drop b { font-size: var(--fs-lg); }
.st-drop span { color: var(--text-mute); font-size: var(--fs-sm); }

.st-err {
  margin: var(--space-4) 0 0;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--bad) 12%, transparent);
  color: var(--bad);
  font-size: var(--fs-sm);
}
.st-err[hidden] { display: none; }

.st-progress { margin-top: var(--space-5); }
.st-progress[hidden] { display: none; }
.st-progress__bar {
  height: 4px; border-radius: 2px; overflow: hidden;
  background: var(--surface-3, var(--surface-2));
}
.st-progress__bar i {
  display: block; height: 100%; width: 40%;
  background: var(--accent);
  animation: st-slide 1.1s ease-in-out infinite;
}
@keyframes st-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}
.st-progress p { margin: var(--space-2) 0 0; color: var(--text-dim); font-size: var(--fs-sm); }

.st-recent__head { margin: var(--space-10) 0 var(--space-3); font-size: var(--fs-md); color: var(--text-dim); }
.st-recent { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); max-width: 44rem; }
.st-recent li { display: flex; gap: var(--space-2); align-items: center; }
.st-recent__item {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  text-align: left; cursor: pointer;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
}
.st-recent__item:hover { border-color: var(--accent); }
.st-recent__item svg { width: 20px; height: 20px; fill: var(--text-mute); flex: none; }
.st-recent__item b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-recent__item em { font-style: normal; color: var(--text-mute); font-size: var(--fs-xs); }
.st-recent__bin {
  width: 2.5rem; height: 2.5rem; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: var(--r-md);
  background: none; color: var(--text-mute); cursor: pointer;
}
.st-recent__bin:hover { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.st-recent__bin svg { width: 17px; height: 17px; fill: currentColor; }
.st-recent__note { margin-top: var(--space-3); color: var(--text-mute); font-size: var(--fs-xs); }

/* ---------- The editor ---------- */

/* While editing, the editor owns the viewport. The site header stays, so
   there is always a way out. */
body.st-editing { overflow: hidden; }

.st-app {
  position: fixed;
  inset: var(--header-h, 3.5rem) 0 0 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "top   top    top"
    "tools canvas props"
    "foot  foot   foot";
  background: var(--bg);
}
.st-app[hidden] { display: none; }

/* ---------- Top bar ---------- */

.st-top {
  grid-area: top;
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
  min-width: 0;
}

.st-name {
  flex: 1; min-width: 4rem;
  padding: var(--space-2) var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: none;
  color: var(--text);
  font: inherit; font-weight: 500;
  text-overflow: ellipsis;
}
.st-name:hover { border-color: var(--border); }
.st-name:focus { border-color: var(--accent); outline: none; background: var(--surface-2); }

.st-saved { color: var(--text-mute); font-size: var(--fs-xs); white-space: nowrap; }
.st-top__right { display: flex; gap: var(--space-2); align-items: center; }

.st-icon {
  width: 2.25rem; height: 2.25rem; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: var(--r-sm);
  background: none; color: var(--text-dim); cursor: pointer;
}
.st-icon:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.st-icon:disabled { opacity: .35; cursor: default; }
.st-icon svg { width: 18px; height: 18px; fill: currentColor; }
.st-icon--sm { width: 2rem; height: 2rem; }
.st-icon--sm svg { width: 15px; height: 15px; }

.st-export { white-space: nowrap; }

/* ---------- Tool rail ---------- */

.st-tools {
  grid-area: tools;
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--space-2);
  border-right: 1px solid var(--border);
  background: var(--surface-1);
  overflow-y: auto;
}

.st-tool {
  width: 4.25rem;
  display: grid; place-items: center; gap: 3px;
  padding: var(--space-2) 2px;
  border: 0; border-radius: var(--r-sm);
  background: none; color: var(--text-dim);
  cursor: pointer;
}
.st-tool svg { width: 20px; height: 20px; fill: currentColor; }
.st-tool i { font-style: normal; font-size: 10.5px; letter-spacing: .01em; }
.st-tool:hover { background: var(--surface-2); color: var(--text); }
.st-tool.is-on { background: var(--accent); color: var(--accent-contrast); }

/* ---------- Canvas ---------- */

.st-canvas {
  grid-area: canvas;
  overflow: auto;
  background: var(--bg);
  padding: var(--space-5) var(--space-4) var(--space-8);
  -webkit-overflow-scrolling: touch;
}

.st-pages { display: grid; justify-content: center; gap: var(--space-5); }

.st-page {
  position: relative;
  background: #fff;
  box-shadow: var(--shadow-lg);
  /* The page is the work surface; its own scrollbars would be nonsense. */
  overflow: hidden;
  flex: none;
}

.st-page__bg {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  user-select: none; -webkit-user-select: none;
  pointer-events: none;
}

.st-layer { position: absolute; inset: 0; }

/* The cursor says what a click will do. */
.st-pages[data-tool="text"] .st-page { cursor: text; }
.st-pages[data-tool="draw"] .st-page,
.st-pages[data-tool="line"] .st-page { cursor: crosshair; }
.st-pages[data-tool="cover"] .st-page,
.st-pages[data-tool="highlight"] .st-page,
.st-pages[data-tool="rect"] .st-page,
.st-pages[data-tool="ellipse"] .st-page { cursor: crosshair; }

/* ---------- Objects ---------- */

.st-obj { position: absolute; }
.st-pages[data-tool="select"] .st-obj { cursor: move; }
/* While a drawing tool is active, objects must not swallow the drag that
   is meant to create something on top of them. */
.st-pages:not([data-tool="select"]) .st-obj { pointer-events: none; }

.st-fillbox { position: absolute; inset: 0; box-sizing: border-box; }
.st-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.st-img { width: 100%; height: 100%; object-fit: fill; display: block; }

.st-text {
  width: 100%;
  min-height: 1em;
  outline: none;
  /* Matches Helvetica, which is what the exported PDF draws with, so the
     lines measured here are the lines that print. */
  font-family: Arial, Helvetica, sans-serif;
  white-space: pre-wrap;
  word-wrap: break-word;
  cursor: text;
}

.st-obj.is-sel { outline: 2px solid var(--accent); outline-offset: 1px; }
.st-obj.is-editing { outline-style: dashed; }

.st-h {
  position: absolute;
  width: 11px; height: 11px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.st-h--nw { left: 0; top: 0; cursor: nwse-resize; }
.st-h--ne { left: 100%; top: 0; cursor: nesw-resize; }
.st-h--se { left: 100%; top: 100%; cursor: nwse-resize; }
.st-h--sw { left: 0; top: 100%; cursor: nesw-resize; }
.st-h--a, .st-h--b { cursor: move; }

/* Fingers need a bigger grab area than the dot looks. */
@media (hover: none) {
  .st-h { width: 15px; height: 15px; margin: -8px 0 0 -8px; }
}

.st-ghost {
  position: absolute;
  border: 1.5px dashed var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  pointer-events: none;
}

/* ---------- Properties ---------- */

.st-props {
  grid-area: props;
  width: 15rem;
  padding: var(--space-4);
  border-left: 1px solid var(--border);
  background: var(--surface-1);
  overflow-y: auto;
}
.st-props[hidden] { display: none; }

.st-props__head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-4);
}
.st-props__head b { font-size: var(--fs-md); }

.st-prop { margin-bottom: var(--space-5); }
.st-prop[hidden] { display: none; }
.st-prop > label {
  display: block; margin-bottom: var(--space-2);
  color: var(--text-mute); font-size: var(--fs-xs);
  text-transform: uppercase; letter-spacing: .06em;
}

.st-swatches { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--space-2); }
.st-sw {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: 0 0 0 1px var(--border) inset;
  cursor: pointer;
}
.st-sw[aria-pressed="true"] { border-color: var(--accent); transform: scale(1.1); }
.st-sw.is-light { box-shadow: 0 0 0 1px var(--border-strong) inset; }

.st-prop input[type="color"] {
  width: 100%; height: 2rem;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: none; cursor: pointer;
}
.st-prop input[type="range"] { width: 100%; }
.st-prop output { display: inline-block; margin-top: 2px; color: var(--text-dim); font-size: var(--fs-xs); }

.st-seg { display: flex; gap: 2px; margin-bottom: var(--space-2); }
.st-seg button {
  flex: 1;
  min-height: 2.25rem;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-dim);
  font: inherit; font-size: var(--fs-sm);
  cursor: pointer;
}
.st-seg button svg { width: 15px; height: 15px; fill: currentColor; }
.st-seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.st-seg button:hover:not([aria-pressed="true"]) { color: var(--text); }
.st-seg--wide { flex-wrap: wrap; }
.st-seg--wide button { flex: 1 1 42%; }
.st-seg button.is-danger:hover { background: var(--bad); color: #fff; border-color: var(--bad); }

/* ---------- Footer ---------- */

.st-foot {
  grid-area: foot;
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--border);
  background: var(--surface-1);
}

.st-pagebar { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.st-pagebar::-webkit-scrollbar { display: none; }
.st-pagechip {
  min-width: 1.9rem; height: 1.9rem;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--text-dim);
  font: inherit; font-size: var(--fs-xs); cursor: pointer;
}
.st-pagechip:hover { border-color: var(--accent); color: var(--text); }

.st-zoom { display: flex; align-items: center; gap: var(--space-2); }
.st-zoom span { color: var(--text-dim); font-size: var(--fs-xs); min-width: 3rem; text-align: center; }

/* ==========================================================================
   Phones and small tablets
   ========================================================================== */

@media (max-width: 52rem) {
  .st-app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto auto;
    grid-template-areas:
      "top"
      "canvas"
      "foot"
      "tools";
  }

  /* Tools along the bottom, where a thumb already is. */
  .st-tools {
    flex-direction: row;
    gap: 0;
    border-right: 0;
    border-top: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
    padding: var(--space-2) var(--space-2) calc(var(--space-2) + env(safe-area-inset-bottom));
  }
  .st-tools::-webkit-scrollbar { display: none; }
  .st-tool { width: auto; min-width: 3.9rem; flex: none; }

  /* Properties become a sheet over the page rather than a column beside
     it — there is no room beside it. */
  .st-props {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 40;
    width: auto;
    max-height: 56vh;
    border-left: 0;
    border-top: 1px solid var(--border);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    box-shadow: var(--shadow-lg);
    padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  }

  .st-canvas { padding: var(--space-3) var(--space-2) var(--space-5); }
  .st-name { font-size: var(--fs-sm); }
  .st-saved { display: none; }
  .st-export { padding-left: var(--space-3); padding-right: var(--space-3); }
}

/* Very narrow: the top bar earns its space back. */
@media (max-width: 26rem) {
  .st-tool i { display: none; }
  .st-tool { min-width: 3rem; }
  .st-export { font-size: var(--fs-sm); }
}

@media (prefers-reduced-motion: reduce) {
  .st-progress__bar i { animation: none; width: 100%; }
}

/* ==========================================================================
   Unlock banner
   ========================================================================== */

.st-unlock {
  display: flex; flex-wrap: wrap; gap: var(--space-3);
  align-items: center; justify-content: space-between;
  max-width: 54rem;
  margin: 0 auto var(--space-5);
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--accent-line, var(--border));
  border-radius: var(--r-md);
  background: var(--accent-wash);
}
.st-unlock[hidden] { display: none; }
.st-unlock__text b { display: block; margin-bottom: 2px; }
.st-unlock__text span { color: var(--text-dim); font-size: var(--fs-sm); }
.st-unlock__acts { display: flex; gap: var(--space-2); flex: none; }

/* Lifted pieces read as part of the page until you touch them, so the page
   still looks like the page. */
.st-obj[data-from-page="1"]:not(.is-sel) { outline: none; }
.st-pages[data-tool="select"] .st-obj[data-from-page="1"]:hover {
  outline: 1px dashed var(--accent);
  outline-offset: 1px;
}

@media (max-width: 52rem) {
  .st-unlock { margin-bottom: var(--space-4); padding: var(--space-3) var(--space-4); }
  .st-unlock__acts { width: 100%; }
  .st-unlock__acts .btn { flex: 1; justify-content: center; }

  /* The properties sheet sat on top of the tool bar, which put the tools
     out of reach exactly when something was selected. Lift it clear. */
  .st-props { bottom: 4.6rem; }
}

@media (max-width: 26rem) {
  .st-props { bottom: 4.1rem; }
}
