/* paint-it — Win11 Fluent look, light + dark, desktop + tablet */

/* ============================================================ tokens */
:root {
  color-scheme: light dark;

  --font: 'Segoe UI Variable Text', 'Segoe UI', Selawik, system-ui, -apple-system,
          'Helvetica Neue', Arial, sans-serif;

  --bg:        light-dark(#f3f3f3, #202020);
  --card:      light-dark(#ffffff, #2b2b2b);
  --card-2:    light-dark(#fbfbfb, #323232);
  --workspace: light-dark(#e2e5e9, #161616);
  --canvas:    #ffffff;

  --ctl:       light-dark(#fdfdfd, #383838);
  --hover:     light-dark(rgba(0, 0, 0, .045), rgba(255, 255, 255, .06));
  --press:     light-dark(rgba(0, 0, 0, .09), rgba(255, 255, 255, .025));
  --track:     light-dark(rgba(0, 0, 0, .18), rgba(255, 255, 255, .22));

  --line:      light-dark(rgba(0, 0, 0, .08), rgba(255, 255, 255, .08));
  --line-2:    light-dark(rgba(0, 0, 0, .17), rgba(255, 255, 255, .15));

  --fg:        light-dark(#1b1b1b, #f2f2f2);
  --dim:       light-dark(#5c6169, #adadad);

  --accent:    light-dark(#0067c0, #4cc2ff);
  --on-accent: light-dark(#ffffff, #10222e);
  --tint:      light-dark(rgba(0, 103, 192, .10), rgba(76, 194, 255, .13));
  --tint-2:    light-dark(rgba(0, 103, 192, .18), rgba(76, 194, 255, .22));

  --scrim: rgba(0, 0, 0, .2);
  --sh-1: 0 1px 3px light-dark(rgba(0, 0, 0, .10), rgba(0, 0, 0, .45));
  --sh-2: 0 8px 18px light-dark(rgba(0, 0, 0, .14), rgba(0, 0, 0, .55)),
          0 0 1px light-dark(rgba(0, 0, 0, .14), rgba(0, 0, 0, .7));

  --r: 4px;
  --r2: 8px;
  --sw: 20px;      /* palette cell */
  --ruler: 0px;    /* ruler track  */
  --lp: 0px;       /* layers panel */
}
html.light { color-scheme: light; }
html.dark  { color-scheme: dark; }

/* ============================================================ base */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  font: 13px/1.35 var(--font);
  background: var(--bg);
  color: var(--fg);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea, output, kbd {
  font: inherit;
  color: inherit;
}
button {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: default;
}
svg { display: block; }
textarea, input[type=text], input[type=number] { user-select: text; -webkit-user-select: text; }

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

button:disabled, [aria-disabled=true] { opacity: .4; pointer-events: none; }

/* icons — symbols must be filled paths (or carry their own stroke attrs) */
.ic {
  width: 20px;
  height: 20px;
  flex: none;
  fill: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ic.big { width: 24px; height: 24px; }

/* thin scrollbars everywhere */
* { scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--track);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: 6px;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--dim); }

/* ============================================================ shell */
#app {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  overflow: hidden;
}

/* ---------------- title bar */
#titlebar {
  position: relative;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 8px;
}
.grow { flex: 1 1 8px; min-width: 8px; }
.qat { display: flex; align-items: center; gap: 2px; margin-left: 6px; }

.tb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border-radius: var(--r);
  border: 1px solid transparent;
  font-size: 12.5px;
  transition: background-color .1s linear;
}
.tb.ico { width: 30px; padding: 0; }
.tb:hover { background: var(--hover); }
.tb:active { background: var(--press); }
.tb.on, .tb[aria-pressed=true] { background: var(--tint); border-color: var(--tint-2); }

#doc-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  max-width: 40%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 12px;
  color: var(--dim);
  pointer-events: none;
}

/* ---------------- ribbon card */
#ribbon {
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 74px;
  margin: 0 8px;
  padding: 4px 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r2);
  box-shadow: var(--sh-1);
  flex-wrap: wrap;
}

#ctxbar {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 36px;
  margin: 0 8px;
  padding: 4px 12px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 var(--r2) var(--r2);
  box-shadow: var(--sh-1);
  flex-wrap: wrap;
}
#app:has(#ctxbar:not([hidden])) #ribbon {
  border-radius: var(--r2) var(--r2) 0 0;
  border-bottom: 0;
  box-shadow: none;
}

.rgroup {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
}
.rsep {
  flex: 0 0 auto;
  width: 1px;
  height: 46px;
  margin: 0 5px;
  background: var(--line-2);
}
.rstack { display: flex; flex-direction: column; gap: 2px; flex: 0 0 auto; }

/* ---------------- ribbon buttons */
.rb {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--r);
  font-size: 12px;
  transition: background-color .1s linear;
}
.rb:hover { background: var(--hover); }
.rb:active { background: var(--press); }
.rb.on, .rb[aria-pressed=true] { background: var(--tint); border-color: var(--tint-2); }
.tb[aria-expanded=true], .rb[aria-expanded=true] { background: var(--hover); }
.rb.on::after, .rb[aria-pressed=true]::after {
  content: '';
  position: absolute;
  left: 26%;
  right: 26%;
  bottom: 0;
  height: 3px;
  border-radius: 2px;
  background: var(--accent);
}
.rb span { white-space: nowrap; }

/* icon over label + chevron strip */
.rb.split {
  flex-direction: column;
  gap: 3px;
  width: 58px;
  min-height: 62px;
  padding: 6px 3px 17px;
  line-height: 1.15;
  text-align: center;
}
.rb.split.iconly { width: 44px; }

/* icon only (tools) */
.rb.ico { width: 40px; height: 40px; padding: 0; }

/* icon then label */
.rb.sm {
  gap: 6px;
  height: 28px;
  padding: 0 8px;
  justify-content: flex-start;
}
.rb.sm.ico { width: 30px; padding: 0; justify-content: center; }

.caret {
  position: absolute;
  left: 1px;
  right: 1px;
  bottom: 1px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 1px solid var(--line-2);
  border-radius: 0 0 3px 3px;
}
.caret:hover { background: var(--hover); }
.caret::after {
  content: '';
  width: 5px;
  height: 5px;
  margin-top: -3px;
  border-right: 1.4px solid currentColor;
  border-bottom: 1.4px solid currentColor;
  transform: rotate(45deg);
}

/* ---------------- colours group */
.colorslots {
  display: flex;
  align-items: center;
  padding: 0 8px 0 2px;
}
.slot {
  position: relative;
  flex: none;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: var(--card);
}
#slot1 { z-index: 1; }
#slot2 { margin-left: 6px; }
.slot > i {
  position: absolute;
  inset: 2px;
  border-radius: 4px;
  background: var(--dim);
}
.slot > span {
  position: absolute;
  right: -3px;
  bottom: -4px;
  min-width: 12px;
  padding: 0 2px;
  font-size: 9px;
  line-height: 11px;
  color: var(--dim);
  background: var(--card);
  border: 1px solid var(--line-2);
  border-radius: 3px;
}
.slot.on, .slot[aria-pressed=true] {
  box-shadow: 0 0 0 2px var(--accent);
  z-index: 2;
}

.palette {
  display: grid;
  grid-template-columns: repeat(10, var(--sw));
  grid-auto-rows: var(--sw);
  gap: 2px;
  align-content: start;
  max-height: calc(var(--sw) * 3 + 12px);
  overflow-y: auto;
  padding: 4px;
}
.swatch {
  width: var(--sw);
  height: var(--sw);
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: 3px;
  transition: box-shadow .1s linear;
}
.swatch:hover { box-shadow: 0 0 0 2px var(--card), 0 0 0 3px var(--line-2); }
.swatch.on, .swatch[aria-checked=true] {
  box-shadow: 0 0 0 2px var(--card), 0 0 0 3px var(--accent);
}

/* ============================================================ contextual bar */
.ctx { display: none; }
.ctx.on, .ctx:not([hidden]) {
  display: flex;
  align-items: center;
  gap: 8px 14px;
  flex-wrap: wrap;
}
label.fld {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--dim);
  white-space: nowrap;
}
.fld output {
  min-width: 2.4em;
  text-align: right;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}
.chk {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  white-space: nowrap;
}
.seg { display: flex; align-items: center; }
.seg > .rb {
  border-radius: 0;
  border-color: var(--line-2);
}
.seg > .rb + .rb { margin-left: -1px; }
.seg > .rb:first-child { border-radius: var(--r) 0 0 var(--r); }
.seg > .rb:last-child { border-radius: 0 var(--r) var(--r) 0; }
.seg > .rb.on, .seg > .rb[aria-pressed=true] { z-index: 1; }
.seg > .rb.on::after, .seg > .rb[aria-pressed=true]::after { bottom: -1px; }

/* ---------------- form controls */
input[type=text], input[type=number], select {
  height: 28px;
  padding: 0 8px;
  background: var(--ctl);
  color: var(--fg);
  border: 1px solid var(--line-2);
  border-bottom-color: var(--dim);
  border-radius: var(--r);
  font-size: 12.5px;
}
input[type=text]:focus, input[type=number]:focus, select:focus {
  outline: none;
  border-bottom: 2px solid var(--accent);
}
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 24px;
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-repeat: no-repeat;
  background-position: right 13px center, right 9px center;
  background-size: 5px 5px, 5px 5px;
}
input[type=checkbox], input[type=radio] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}
input[type=color] {
  width: 44px;
  height: 28px;
  padding: 2px;
  background: var(--ctl);
  border: 1px solid var(--line-2);
  border-radius: var(--r);
}

input[type=range] {
  appearance: none;
  -webkit-appearance: none;
  width: 118px;
  height: 18px;
  margin: 0;
  background: none;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--track);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--card);
  box-shadow: 0 0 0 1px var(--line-2);
}
input[type=range]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--track);
}
input[type=range]::-moz-range-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
}
input[type=range]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--card);
  box-shadow: 0 0 0 1px var(--line-2);
}

/* ============================================================ work area */
#workarea {
  display: grid;
  grid-template-columns: var(--ruler) minmax(0, 1fr) var(--lp);
  grid-template-rows: var(--ruler) minmax(0, 1fr);
  min-height: 0;
  margin-top: 6px;
  background: var(--workspace);
  border-top: 1px solid var(--line);
}
#app.rulers { --ruler: 20px; }
#ruler-corner { grid-area: 1 / 1; }
#ruler-h { grid-area: 1 / 2; }
#ruler-v { grid-area: 2 / 1; }
#scroll { grid-area: 2 / 2; }
#layers-panel { grid-area: 1 / 3 / 3 / 4; }

#ruler-corner, #ruler-h, #ruler-v { display: none; }
#app.rulers #ruler-corner, #app.rulers #ruler-h, #app.rulers #ruler-v {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--card);
  color: var(--dim);   /* canvas.js reads computed color for the ticks */
}
#app.rulers #ruler-corner { border-right: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); }
#app.rulers #ruler-h { border-bottom: 1px solid var(--line-2); }
#app.rulers #ruler-v { border-right: 1px solid var(--line-2); }

#scroll {
  overflow: auto;
  display: grid;
  place-content: safe center;
  padding: 12px;
  background: var(--workspace);
}
#app.dropping #scroll {
  outline: 2px dashed var(--accent);
  outline-offset: -6px;
  background: var(--tint);
}

#stage {
  position: relative;
  margin: auto;
  background: var(--canvas);
  box-shadow: 0 0 0 1px var(--line-2), 0 2px 10px light-dark(rgba(0, 0, 0, .22), rgba(0, 0, 0, .6));
}
#stage, #board, #overlay, .cresize { touch-action: none; }
#board, #overlay {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
}
#board { z-index: 1; }
#overlay { z-index: 2; pointer-events: none; }

.cresize {
  position: absolute;
  z-index: 4;
  background: var(--card);
  border: 1px solid var(--dim);
  border-radius: 1px;
}
.cresize[data-dir=e]  { right: -4px; top: 50%; width: 8px; height: 18px; margin-top: -9px; cursor: ew-resize; }
.cresize[data-dir=s]  { bottom: -4px; left: 50%; width: 18px; height: 8px; margin-left: -9px; cursor: ns-resize; }
.cresize[data-dir=se] { right: -4px; bottom: -4px; width: 10px; height: 10px; cursor: nwse-resize; }

/* #textbox is styled by text.js (it injects its own <style>) */
.ants { outline: 1px dashed var(--accent); }

/* ---------------- layers panel */
#layers-panel {
  display: none;
  flex-direction: column;
  width: 100%;
  min-height: 0;
  background: var(--card);
  border-left: 1px solid var(--line);
}
#app.layers-open { --lp: 240px; }
#app.layers-open #layers-panel { display: flex !important; }

.lp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 38px;
  padding: 0 6px 0 12px;
  font-size: 13px;
  font-weight: 600;
  flex: none;
}
.lp-tools {
  display: flex;
  gap: 2px;
  padding: 4px 8px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  flex: none;
}
#layer-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px;
}
.layer-row, .lrow {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 6px;
  border: 1px solid transparent;
  border-radius: var(--r);
  background: var(--card);
  transition: background-color .1s linear;
}
.layer-row:hover, .lrow:hover { background: var(--hover); }
.layer-row.on, .lrow.on { background: var(--tint); border-color: var(--tint-2); }
.thumb, .lthumb {
  flex: none;
  max-width: 40px;
  max-height: 32px;
  background: var(--canvas);
  border: 1px solid var(--line-2);
  border-radius: 2px;
  object-fit: contain;
}
.layer-row span, .lname {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 12px;
}
.lname-edit {
  flex: 1;
  min-width: 0;
  height: 24px;
  padding: 0 4px;
  background: var(--ctl);
  color: var(--fg);
  border: 1px solid var(--accent);
  border-radius: 3px;
  font-size: 12px;
}
.layer-row button, .leye {
  flex: none;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r);
  color: var(--dim);
}
.layer-row button:hover { background: var(--hover); color: var(--fg); }
.leye { width: 18px; height: 18px; margin: 0 2px; }

/* drag feedback (contract) — ui.js currently drags with an inline transform */
.layer-row.dragging, .lrow.dragging { opacity: .45; }
.layer-row.drop-above::before, .layer-row.drop-below::after,
.lrow.drop-above::before, .lrow.drop-below::after {
  content: '';
  position: absolute;
  left: 2px;
  right: 2px;
  height: 2px;
  border-radius: 1px;
  background: var(--accent);
}
.layer-row.drop-above::before, .lrow.drop-above::before { top: -2px; }
.layer-row.drop-below::after, .lrow.drop-below::after { bottom: -2px; }

/* ============================================================ status bar */
#statusbar {
  display: flex;
  align-items: center;
  height: 24px;
  padding: 0 6px;
  font-size: 11px;
  color: var(--dim);
  background: var(--card);
  border-top: 1px solid var(--line);
}
#app.no-status #statusbar { display: none; }
#statusbar > span:not(.grow):not(:empty) {
  padding: 0 10px;
  border-right: 1px solid var(--line-2);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.zoomer {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
  padding-left: 8px;
  border-left: 1px solid var(--line-2);
}
#statusbar .tb { height: 20px; padding: 0 6px; font-size: 11px; }
#statusbar .tb.ico { width: 22px; padding: 0; }
#statusbar .ic { width: 14px; height: 14px; }
#zoom-slider { width: 92px; height: 14px; }
#zoom-slider::-webkit-slider-thumb { width: 12px; height: 12px; margin-top: -4.5px; border-width: 2.5px; }
#zoom-slider::-moz-range-thumb { width: 12px; height: 12px; border-width: 2.5px; }
#st-zoom { min-width: 46px; }

/* ============================================================ flyouts */
.flyout {
  position: fixed;
  z-index: 60;
  display: none;
  min-width: 132px;
  max-height: 80vh;
  overflow: auto;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--line-2);
  border-radius: var(--r2);
  box-shadow: var(--sh-2);
}
.flyout.on, .flyout.open {
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: pop .12s ease-out;
}
.flyout hr {
  height: 0;
  margin: 4px 6px;
  border: 0;
  border-top: 1px solid var(--line-2);
}
.flyout button {
  display: flex;
  align-items: center;
  border-radius: var(--r);
  transition: background-color .1s linear;
}
.flyout button:hover { background: var(--hover); }
.flyout button:active { background: var(--press); }
.flyout button.on, .flyout button[aria-pressed=true] { background: var(--tint); }

.flyout.menu { min-width: 214px; }
.flyout.menu button {
  position: relative;
  width: 100%;
  min-height: 32px;
  padding: 5px 12px 5px 36px;
  text-align: left;
  font-size: 12.5px;
}
.flyout.menu button .ic { position: absolute; left: 9px; top: 50%; margin-top: -10px; }
.flyout.menu kbd {
  margin-left: auto;
  padding-left: 20px;
  font-size: 11px;
  color: var(--dim);
}

.flyout.grid.on, .flyout.grid.open {
  display: grid;
  grid-template-columns: repeat(6, 40px);
  gap: 2px;
  min-width: 0;
}
.flyout.grid button {
  width: 40px;
  height: 40px;
  justify-content: center;
  overflow: hidden;
}
.flyout.grid .ic { width: 24px; height: 24px; }
.flyout.grid button > span { display: none; }        /* title attr carries the name */

/* brushes flyout: icon over name */
#fly-brushes.open, #fly-brushes.on { grid-template-columns: repeat(3, 84px); }
#fly-brushes button {
  flex-direction: column;
  gap: 3px;
  width: 84px;
  height: 64px;
  padding: 4px 2px;
}
#fly-brushes button > span {
  display: block;
  font-size: 10px;
  line-height: 1.15;
  text-align: center;
  color: var(--dim);
  white-space: normal;
}

/* size flyout: a rule of the given thickness + the px label */
#fly-size { min-width: 150px; }
#fly-size button {
  width: 100%;
  min-height: 30px;
  padding: 4px 10px;
  gap: 10px;
  font-size: 12px;
}
#fly-size button > i {
  flex: none;
  width: 66px;
  max-height: 34px;
  background: currentColor;
  border-radius: 99px;
}
#fly-size button > span { margin-left: auto; color: var(--dim); font-size: 11px; }

/* ============================================================ dialogs */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--scrim);
  animation: fade .12s ease-out;
}
.dialog {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 460px;
  max-height: 92vh;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line-2);
  border-radius: var(--r2);
  box-shadow: var(--sh-2);
  animation: pop .12s ease-out;
}
.dialog.wide { max-width: 620px; }
.dialog-head {
  flex: none;
  padding: 18px 20px 6px;
  font-size: 15px;
  font-weight: 600;
}
.dialog-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 20px 18px;
  font-size: 13px;
}
.dialog-body label { display: flex; align-items: center; gap: 8px; }
.dialog-body fieldset { margin: 0; padding: 0; border: 0; display: flex; gap: 16px; flex-wrap: wrap; }
.dialog-body canvas { border-radius: var(--r); border: 1px solid var(--line-2); touch-action: none; cursor: crosshair; }
.dialog-body input[type=number] { width: 82px; }
.dialog-body hr { height: 0; margin: 2px 0; border: 0; border-top: 1px solid var(--line-2); }
.dialog-foot {
  flex: none;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  background: var(--bg);
  border-top: 1px solid var(--line);
}

.btn {
  min-height: 32px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  background: var(--ctl);
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  box-shadow: inset 0 -1px 0 var(--line);
  transition: background-color .1s linear;
}
.btn:hover { background: var(--hover); }
.btn:active { background: var(--press); }
.btn.primary {
  background: var(--accent);
  color: var(--on-accent);
  border-color: transparent;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .12);
}
.btn.primary:hover { opacity: .9; }
.btn.danger { background: light-dark(#c42b1c, #f1707a); color: light-dark(#fff, #201010); }
.btn.sw { min-height: 0; border-radius: 3px; box-shadow: none; border-color: var(--line-2); }
.dialog .row { flex-wrap: wrap; }
.dialog .hint { margin: 0; font-size: 12px; color: var(--dim); }
.dialog .dlg-sec { font-size: 12px; color: var(--dim); }

/* ============================================================ toasts */
#toasts {
  position: fixed;
  left: 50%;
  bottom: 44px;
  z-index: 200;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
#toasts .toast {
  padding: 9px 18px;
  font-size: 12.5px;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--line-2);
  border-radius: 18px;
  box-shadow: var(--sh-2);
  animation: pop .16s ease-out;
}

@keyframes pop { from { opacity: 0; transform: translateY(2px); } }
@keyframes fade { from { opacity: 0; } }
#toasts .toast, .dialog { will-change: auto; }

/* ============================================================ tablet */
@media (pointer: coarse), (max-width: 1100px) {
  :root { --sw: 26px; }
  #titlebar { height: 46px; }
  .tb { height: 40px; padding: 0 12px; }
  .tb.ico { width: 40px; }
  #ribbon { min-height: 90px; }
  .rb.split { width: 66px; min-height: 68px; padding: 7px 3px 25px; }
  .rb.split.iconly { width: 50px; }
  .rb.ico { width: 48px; height: 48px; }
  .rb.sm { height: 40px; padding: 0 12px; }
  .rb.sm.ico { width: 40px; padding: 0; }
  .caret { height: 22px; }
  .slot { width: 40px; height: 40px; }
  #slot2 { margin-left: 6px; }
  #ctxbar { min-height: 48px; }
  .flyout.menu button { min-height: 40px; }
  .flyout.grid.on, .flyout.grid.open { grid-template-columns: repeat(5, 48px); }
  .flyout.grid button { width: 48px; height: 48px; }
  #fly-brushes.on, #fly-brushes.open { grid-template-columns: repeat(3, 92px); }
  #fly-brushes button { width: 92px; height: 72px; }
  #fly-size button { min-height: 44px; }
  .layer-row, .lrow { height: 52px; }
  .layer-row button { width: 36px; height: 36px; }
  .leye { width: 22px; height: 22px; }
  .lp-head { height: 44px; }
  #statusbar { height: 40px; }
  #statusbar .tb { height: 36px; padding: 0 8px; }
  #statusbar .tb.ico { width: 36px; }
  #statusbar .ic { width: 16px; height: 16px; }
  #zoom-slider { width: 110px; height: 36px; }
  .btn { min-height: 40px; }
  input[type=range] { height: 36px; }
  input[type=checkbox], input[type=radio] { width: 20px; height: 20px; }
  input[type=text], input[type=number], select { height: 36px; }
  .cresize[data-dir=e]  { right: -7px; width: 14px; height: 26px; margin-top: -13px; }
  .cresize[data-dir=s]  { bottom: -7px; width: 26px; height: 14px; margin-left: -13px; }
  .cresize[data-dir=se] { right: -7px; bottom: -7px; width: 16px; height: 16px; }
}

/* portrait / narrow */
@media (max-width: 900px) {
  #app.layers-open { --lp: 200px; }
  .rsep { margin: 0 3px; }
}

/* ============================================================ a11y / print */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

@media print {
  html, body { height: auto; overflow: visible; background: #fff; }
  #titlebar, #ribbon, #ctxbar, #statusbar, #layers-panel, #overlay, #textbox,
  #ruler-corner, #ruler-h, #ruler-v, .cresize, #flyouts, #dialogs, #toasts {
    display: none !important;
  }
  #app, #workarea, #scroll { display: block; height: auto; margin: 0; padding: 0; overflow: visible; background: #fff; border: 0; }
  #stage { margin: 0; box-shadow: none; }
  #board { position: static; max-width: 100%; height: auto; }
}
