:root {
  --bg: #2b2f36;
  --panel: #1f2329;
  --panel-2: #272c33;
  --line: #3a4049;
  --text: #e7eaee;
  --muted: #9aa3ad;
  --accent: #4f7cff;
  --accent-press: #3a63d8;
  --page-shadow: rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

body { display: flex; flex-direction: column; touch-action: manipulation; }

/* ---------- toolbar ---------- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.sep { width: 1px; align-self: stretch; background: var(--line); }
.spacer { flex: 1 1 auto; }

.group { display: flex; align-items: center; gap: 6px; }

.tools { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.hamburger, .menu-close { display: none; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: #4a525d; background: #2d333b; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--file { display: inline-flex; align-items: center; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--accent-press); border-color: var(--accent-press); }
.btn--danger { color: #ff9a9a; border-color: #5a3a3f; }
.btn--danger:hover:not(:disabled) { background: #3a2a2e; border-color: #7a4a50; }

/* data-confirm: the armed state, shown as a solid red "Confirm" button */
.btn.is-confirming,
.btn.is-confirming:hover { background: #c0392b; border-color: #c0392b; color: #fff; }

.field { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.field span { font-size: 12px; }
.field input[type="color"] {
  width: 30px; height: 28px; padding: 0;
  /*border: 1px solid var(--line); border-radius: 6px; background: none; cursor: pointer;*/
}
.field input[type="range"] { width: 110px; }

.swatches { display: inline-flex; align-items: center; gap: 7px; }
.swatch {
  width: 22px; height: 22px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .25);
  border-radius: 50%;
  cursor: pointer;
  appearance: none;
}
.swatch.is-selected { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--text); }

/* nib: 4 size dots sitting above the 4-step size slider (diameter = nib size) */
.nib { display: inline-flex; flex-direction: column; gap: 3px; width: 124px; }
.nib__icons { display: flex; justify-content: space-between; align-items: center; height: 16px; pointer-events: none; }
.nib__stroke { width: var(--d); height: var(--d); border-radius: 50%; background: var(--muted); }
.nib__stroke.is-active { background: var(--text); }
.nib input[type="range"] { width: 100%; margin: 0; }

.status { color: var(--muted); font-size: 12px; min-width: 60px; margin-left: auto; }

/* ---------- viewer ---------- */
.viewer {
  flex: 1 1 auto;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding: 24px 16px 80px;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  max-width: 420px;
}
.empty p { margin: 6px 0; }
.empty__hint { font-size: 12px; opacity: .8; }

.page {
  position: relative;
  width: min(900px, 100%);
  background: #fff;
  box-shadow: 0 10px 30px var(--page-shadow);
  border-radius: 2px;
}

.page .backdrop {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 2px;
  user-select: none;
  -webkit-user-drag: none;
}

.page .ink {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;        /* let us capture the stylus/finger as ink */
  cursor: crosshair;
}

.page__num {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 2px 8px;
  font-size: 11px;
  color: #fff;
  background: rgba(0, 0, 0, .55);
  border-radius: 10px;
  pointer-events: none;
}

/* ---------- busy overlay ---------- */
.overlay {
  position: fixed; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .45);
  z-index: 100;
}
body.busy .overlay { display: flex; }
.overlay__box {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 14px 22px;
  border-radius: 10px;
}

/* ---------- mobile: collapse the toolbar into a hamburger + full-screen menu ---------- */
@media (max-width: 640px) {
  .hamburger {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 42px;
    height: 38px;
    padding: 0 10px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
  }
  .hamburger span { display: block; height: 2px; background: var(--text); border-radius: 2px; }

  /* the toolbar shows only the hamburger + status until the menu opens */
  .tools { display: none; }

  body.menu-open { overflow: hidden; }
  body.menu-open .tools {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: var(--panel);
    padding: 60px 22px calc(28px + env(safe-area-inset-bottom));
    overflow: auto;
  }
  /* grouped controls flow as individual full-width menu rows */
  body.menu-open .tools .group { display: contents; }

  .menu-close {
    display: block;
    position: absolute;
    top: 12px;
    right: 14px;
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    color: var(--text);
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
  }

  /* buttons become big left-aligned text links */
  body.menu-open .tools .btn {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    padding: 18px 4px;
    font-size: 18px;
    color: var(--text);
    white-space: normal;
  }
  body.menu-open .tools .btn--primary { color: #9db8ff; }
  body.menu-open .tools .btn--danger { color: #ff9a9a; }
  body.menu-open .tools .btn:disabled { opacity: .4; }
  /* keep the armed "Confirm" state as a red pill, overriding the link look */
  body.menu-open .tools .btn.is-confirming {
    background: #c0392b;
    color: #fff;
    border: none;
    border-radius: 8px;
    margin: 6px 0;
    text-align: center;
  }

  /* colour + size as labelled rows */
  body.menu-open .tools .field {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 16px 4px;
    border-bottom: 1px solid var(--line);
    color: var(--text);
  }
  body.menu-open .tools .field span { font-size: 18px; }
  body.menu-open .tools .nib { width: 58%; }
  body.menu-open .tools .field input[type="color"] { width: 48px; height: 34px; }
  body.menu-open .tools .swatches { gap: 14px; }
  body.menu-open .tools .swatch { width: 30px; height: 30px; }
}
