/* Settings panel. Tokens, font and buttons live in theme.css. */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.ghost {
  border: 0; background: none; color: var(--accent); cursor: pointer;
  padding: 4px 6px; border-radius: var(--radius-sm); font-weight: 550;
}
.ghost:hover { background: var(--accent-soft); }

/* ---------- scrolling settings ---------- */
.controls {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 var(--gutter);
}
.section { padding: 16px 0; border-bottom: 1px solid var(--line); }
.section:last-child { border-bottom: 0; }
h2 {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 12px; font-size: 15.5px; font-weight: 700; letter-spacing: -.01em;
}
h2 .seg.mini { margin-left: auto; }
h2 .reset-btn:not([hidden]) + .seg.mini { margin-left: 0; }
.reset-btn {
  margin-left: auto; height: 28px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--text); font: 500 12.5px var(--font); cursor: pointer;
}
.reset-btn:hover:not(:disabled) { border-color: var(--muted); }
.step { /* small numbered tag, outlined rather than filled */
  display: inline-grid; place-items: center;
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 6px;
  border: 1.5px solid var(--accent); color: var(--accent);
  font-size: 11.5px; font-weight: 700;
}

/* fields: label above control, controls bottom-aligned across a row */
.fields { display: grid; gap: 12px; }
.fields.two { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 10px; }
.field { display: flex; flex-direction: column; justify-content: flex-end; gap: 3px; min-width: 0; }
.span2 { grid-column: 1 / -1; }
.field-label { font-size: 13.5px; line-height: 1.3; font-weight: 500; color: var(--muted); }

select, input[type=number] {
  width: 100%; height: var(--control-h);
  padding: 0 10px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); font: 500 14.5px var(--font);
}
select {
  appearance: none; -webkit-appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%237a6e63' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 12px;
  text-overflow: ellipsis;
}
/* ---------- stepper ---------- */
.stepper {
  display: flex; align-items: stretch; width: 100%; height: var(--control-h);
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); overflow: hidden;
}
.stepper:hover { border-color: var(--muted); }
.stepper:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.stepper input[type=number] {
  flex: 1; min-width: 0; height: auto; padding: 0 2px; border: 0; border-radius: 0; background: transparent;
  text-align: center; font-variant-numeric: tabular-nums;
  appearance: textfield; -moz-appearance: textfield;
}
.stepper input[type=number]:focus { outline: none; box-shadow: none; }
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.stepper .suffix { align-self: center; padding-right: 6px; color: var(--muted); font-size: 12.5px; }
.step-btn {
  flex: none; width: 32px; border: 0; background: none; color: var(--text);
  font: 500 17px/1 var(--font); cursor: pointer; user-select: none; touch-action: manipulation;
}
.step-btn:first-child { border-right: 1px solid var(--line); }
.step-btn:last-child { border-left: 1px solid var(--line); }
.step-btn:hover:not(:disabled) { background: var(--surface); }
.step-btn:active:not(:disabled) { background: var(--line); }
.step-btn:disabled { color: var(--line); cursor: default; }
.with-presets { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.with-presets .stepper { width: 150px; flex: none; }
.with-presets .chips { flex: 1; min-width: 0; }
.pages-field .stepper { width: 108px; }
.pages-field { width: auto; }

select:hover, input[type=number]:hover { border-color: var(--muted); }
select:focus, input[type=number]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.check {
  display: flex; align-items: center; gap: 8px; min-height: var(--control-h); cursor: pointer;
}
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }

/* segmented control: soft track, the selected option is a raised card */
.seg {
  display: flex; height: var(--control-h); padding: 3px; gap: 3px;
  background: var(--surface); border-radius: var(--radius); border: 0;
}
.seg label { position: relative; flex: 1; display: flex; min-width: 0; }
.seg input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.seg span {
  flex: 1; display: flex; align-items: center; justify-content: center;
  min-width: 0; padding: 0 6px; border-radius: 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--muted); font-weight: 500; cursor: pointer; user-select: none;
  transition: background-color .15s, color .15s, box-shadow .15s;
}
.seg label:hover span { color: var(--text); }
.seg input:checked + span { background: var(--card); color: var(--text); font-weight: 600; box-shadow: var(--shadow-thumb); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.seg.mini { height: 28px; padding: 2px; font-size: 12.5px; font-weight: 400; }
.seg.mini span { padding: 0 9px; border-radius: 6px; }

/* grid types: text buttons with a small icon, most popular first (large, high-contrast labels) */
.type-grid { display: flex; flex-wrap: wrap; gap: 5px; }
.type-tile {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 10px 0 8px; min-width: 0; letter-spacing: -.01em;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card);
  color: var(--text); cursor: pointer; font: 500 15px/1 var(--font); white-space: nowrap;
  transition: border-color .15s, background-color .15s, color .15s;
}
.type-tile:hover { border-color: var(--muted); }
/* icons stay brown whatever paper color is chosen */
.type-tile svg { width: 18px; height: 18px; flex: none; color: var(--icon); }
.type-tile[aria-checked="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.type-tile[aria-checked="true"] svg { color: var(--accent-ink); }
.type-tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.more-types {
  display: block; width: 100%; margin-top: 5px; height: 30px;
  border: 1px dashed var(--line); border-radius: var(--radius); background: none;
  color: var(--accent); font: 600 13px var(--font); cursor: pointer;
}
.more-types:hover { border-color: var(--accent); background: var(--accent-soft); }

/* "more below" hint: first row of the pinned footer, so it never covers a control */
.scroll-hint {
  grid-column: 1 / -1; justify-self: center;
  display: flex; align-items: center; gap: 4px; margin: -4px 0 0;
  height: 22px; padding: 0 10px; border: 0; border-radius: 999px; background: none;
  color: var(--accent); font: 600 12.5px var(--font); cursor: pointer;
}
.scroll-hint { background: var(--accent-soft); height: 24px; padding: 0 12px; max-width: 100%; }
.scroll-hint span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scroll-hint:hover { background: var(--accent); color: #fff; }
.scroll-hint svg { flex: none; animation: hint-bob 1.2s cubic-bezier(.45,0,.55,1) infinite; }
@keyframes hint-bob { 0%, 100% { transform: translateY(-2px); } 50% { transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) { .scroll-hint svg { animation: none; } }

/* size preset chips under a spacing field */
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  height: 26px; padding: 0 9px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg); color: var(--muted); cursor: pointer; font: 500 13px var(--font);
}
.chip:hover { border-color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--graphite); border-color: var(--graphite); color: var(--graphite-ink); }

/* color swatches — the last one is the custom picker */
.swatches { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.swatch {
  position: relative; flex: none;
  width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15);
}
.swatch[aria-checked="true"] { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--graphite); }
.swatch-custom {
  background: conic-gradient(#ff4d4d, #ffc93c, #6ee26e, #3cd3e0, #4d6bff, #d24dff, #ff4d4d);
}
.swatch-custom::after { /* centre dot shows the picked color once custom is active */
  content: ""; position: absolute; inset: 8px; border-radius: 50%;
  background: var(--custom, transparent); box-shadow: 0 0 0 2px #fff; opacity: 0;
}
.swatch-custom[aria-checked="true"]::after { opacity: 1; }
.swatch-custom[aria-expanded="true"] { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--muted); }
.swatch-custom[aria-checked="true"][aria-expanded="true"] { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--graphite); }

.color-popover {
  margin: -4px 0 14px; padding: 10px;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--card);
  box-shadow: var(--shadow-card);
}
.palette { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 4px; }
.palette button {
  aspect-ratio: 1; width: 100%; padding: 0; border: 0; border-radius: 4px; cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
}
.palette button:hover { transform: scale(1.12); }
.palette button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--accent); }
.popover-row { display: flex; align-items: flex-end; gap: 8px; margin-top: 10px; }
.hex-field { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.hex-field input {
  height: var(--control-h); padding: 0 8px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); font: 500 13px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.hex-field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.more-colors[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }
.spectrum { display: grid; gap: 12px; margin-top: 10px; padding-bottom: 4px; }
.sv-area {
  --hue: 0;
  /* square hit area (rounded corners would swallow clicks at the extremes) */
  position: relative; height: 120px; cursor: crosshair; touch-action: none;
}
.sv-area::before {
  content: ""; position: absolute; inset: 0; border-radius: var(--radius-sm);
  background:
    linear-gradient(to top, #000, rgba(0, 0, 0, 0)),
    linear-gradient(to right, #fff, hsl(var(--hue) 100% 50%));
}
.sv-area:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sv-thumb {
  position: absolute; z-index: 1; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .4); pointer-events: none;
}
.hue {
  -webkit-appearance: none; appearance: none; width: 100%; height: 14px; margin: 0; border-radius: 999px;
  background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); cursor: pointer;
}
.hue::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 0; box-shadow: 0 0 0 1px rgba(0, 0, 0, .4), 0 1px 3px rgba(0, 0, 0, .3);
}
.hue:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.pages-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-presets .chip { padding: 0 7px; min-width: 27px; }
.pages-field { flex: none; }
.page-presets { display: flex; gap: 4px; flex-wrap: wrap; }
/* narrow panels: drop the 100-page chip so the chips stay on the stepper's line */
@media (max-width: 370px) { .page-presets [data-pages="100"] { display: none; } }

/* very narrow panels: one column */
@media (max-width: 340px) {
  .fields.two { grid-template-columns: minmax(0, 1fr); }
  .pages-row { gap: 8px; }
}

/* ---------- pinned actions ---------- */
.actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  padding: 12px var(--gutter);
  border-top: 1px solid var(--line); background: var(--card);
}
.btn.small { height: var(--control-h); padding: 0 12px; font-size: 12.5px; border-width: 1px; }
.actions .tip { grid-column: 1 / -1; text-align: center; }
#status { grid-column: 1 / -1; margin: 0; font-size: 11px; color: var(--muted); }
#status:empty { display: none; }

/* thin-line warning under a line-weight field */
.field-warning {
  display: flex; gap: 6px; align-items: flex-start; margin: 6px 0 0; padding: 6px 9px;
  border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent-hover);
  font-size: 12.5px; line-height: 1.35;
}
.field-warning::before { content: "⚠"; flex: none; }
#margin-warning { grid-column: 1 / -1; } /* the whole width of the Paper section, not one column */
