:root {
  color-scheme: light;
  font: 14px/1.4 system-ui, sans-serif;
  color: #292b2d;
  background: #f8f6ef;
  --paper: #f8f6ef;
  --surface: #fffdf8;
  --edge: #e0dbd0;
  --muted: #69655e;
  --blue: #314fa3;
  --highlight: #e9edfa;
  --bar-height: 68px;
  --gutter: 24px;
  --selection-bottom: max(20px, env(safe-area-inset-bottom));
  --shadow: 0 2px 3px #30281a0a, 0 6px 18px #30281a10;
}

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

body {
  height: 100vh;
  height: 100dvh;
  margin: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

button, input, textarea { font: inherit; }
button { color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.symbols { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.topbar {
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: calc(var(--bar-height) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(var(--gutter), env(safe-area-inset-right)) 0
    max(var(--gutter), env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--edge);
}

.identity, .header-actions { display: flex; align-items: center; }
.identity { gap: 11px; min-width: 0; }
.header-actions { gap: 8px; flex: none; }

.logo {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #262b3d;
  color: #fffdf8;
}

.logo .icon { width: 24px; height: 24px; }

h1 {
  margin: 0;
  color: #22242a;
  font-size: 23px;
  font-weight: 730;
  letter-spacing: -.065em;
  line-height: 1;
}

.workspace {
  color: var(--muted);
  font-size: 12px;
  font-weight: 520;
  margin-inline-start: 4px;
  padding-inline-start: 14px;
  border-inline-start: 1px solid var(--edge);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.share {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 13px;
  color: #fff;
  background: var(--blue);
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 650;
}

.share:hover { background: #27428f; }
.share[aria-busy="true"] { opacity: .76; }
.share .icon { width: 17px; height: 17px; }

.icon-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

.icon-button:disabled { color: #8d877e; opacity: .65; }
.icon-button:hover:not(:disabled) { background: #f0ece3; }
.icon-button[aria-pressed="true"] { color: var(--blue); background: var(--highlight); }
.icon-button[aria-pressed="true"]:hover { background: #dde4f8; }
.menu-button { border: 1px solid var(--edge); }

main { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
napkin-canvas { position: absolute; inset: 0; display: block; background: var(--paper); }
napkin-canvas canvas { display: block; width: 100%; height: 100%; touch-action: none; }
napkin-canvas canvas:focus-visible { outline-offset: -3px; }

.note-editor {
  position: absolute;
  top: 0;
  left: 0;
  margin: 0;
  padding: 0;
  border: 0;
  outline: 1px solid var(--blue);
  outline-offset: 3px;
  resize: none;
  overflow: hidden;
  overflow-wrap: anywhere;
  background: var(--surface);
  color: inherit;
  font-family: system-ui, sans-serif;
  transform-origin: top left;
}

.dock {
  position: absolute;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px;
  border: 1px solid var(--edge);
  border-radius: 13px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.tools { top: 22px; left: 50%; transform: translateX(-50%); }
.selection-dock, .arrow-styles {
  left: 50%;
  bottom: var(--selection-bottom);
  transform: translateX(-50%);
}
.arrow-styles[data-above] { bottom: calc(var(--selection-bottom) + 62px); }
.arrow-styles button {
  min-height: 36px;
  padding: 0 11px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 13px;
  font-weight: 650;
}
.arrow-styles button:hover { background: #f0ece3; }
.arrow-styles button[aria-pressed="true"] { color: var(--blue); background: var(--highlight); }
.fill-palette, .arrange-menu {
  position: fixed;
  inset: auto auto calc(var(--selection-bottom) + 64px) 50%;
  margin: 0;
  gap: 4px;
  transform: translateX(-50%);
}
.arrow-styles[data-above]:not([hidden]) ~ :is(.fill-palette, .arrange-menu) {
  bottom: calc(var(--selection-bottom) + 124px);
}
.fill-palette:not(:popover-open), .arrange-menu:not(:popover-open) { display: none; }
.arrange-menu { flex-direction: column; align-items: stretch; min-width: 151px; gap: 2px; }
.arrange-menu button, .group-done {
  border: 0;
  border-radius: 8px;
  min-height: 40px;
  padding: 0 10px;
  background: transparent;
}
.arrange-menu button { text-align: left; }
.arrange-menu button:disabled { opacity: .5; }
.arrange-menu button:hover:not(:disabled), .group-done:hover { background: #f0ece3; }
.group-done { color: var(--blue); font-size: 13px; font-weight: 650; }
.swatch {
  position: relative;
  display: grid;
  place-items: center;
  width: 35px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
}
.swatch:hover { background: #f0ece3; }
.swatch::before {
  content: '';
  width: 23px;
  height: 23px;
  border: 1px solid #918b80;
  border-radius: 50%;
  background: var(--swatch, var(--surface));
}
.swatch[data-fill=""]::before {
  background: linear-gradient(135deg, var(--surface) 46%, #a56868 47%, #a56868 53%, var(--surface) 54%);
}
.swatch[aria-pressed="true"]::before { outline: 2px solid var(--blue); outline-offset: 2px; }
.divider { width: 1px; height: 21px; flex: none; margin: 0 4px; background: var(--edge); }
.history, .camera { bottom: max(20px, env(safe-area-inset-bottom)); }
.history { left: max(var(--gutter), env(safe-area-inset-left)); }
.camera { right: max(var(--gutter), env(safe-area-inset-right)); }
.camera .icon-button, .history .icon-button { width: 36px; height: 36px; }
#zoom { min-width: 42px; text-align: center; font-size: 12px; font-variant-numeric: tabular-nums; }

.empty-hint {
  position: absolute;
  inset: 45% 0 auto;
  margin: 0;
  text-align: center;
  color: var(--muted);
  pointer-events: none;
  user-select: none;
}

.files {
  inset: calc(var(--bar-height) + env(safe-area-inset-top) - 5px)
    max(var(--gutter), env(safe-area-inset-right)) auto auto;
  margin: 0;
  min-width: 186px;
  max-height: calc(100dvh - var(--bar-height) - env(safe-area-inset-top) - 8px);
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--edge);
  border-radius: 12px;
  background: var(--surface);
  color: inherit;
  box-shadow: var(--shadow);
}

.files button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: start;
}

.files button:hover:not(:disabled) { background: #f0ece3; }
.files button:disabled { opacity: .55; }
.files .icon { width: 18px; height: 18px; }

.notice {
  position: fixed;
  z-index: 3;
  right: max(var(--gutter), env(safe-area-inset-right));
  top: calc(var(--bar-height) + env(safe-area-inset-top) + 78px);
  max-width: min(360px, calc(100vw - 2 * var(--gutter)));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px 8px;
  padding: 8px 8px 8px 14px;
  border: 1px solid var(--edge);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

#notice-text { flex: 1 0 190px; }
.notice-action {
  order: 1;
  padding: 7px 10px;
  border: 0;
  border-radius: 7px;
  color: var(--blue);
  background: var(--highlight);
  font-weight: 650;
}
.notice-action:hover { background: #dde4f8; }
.notice .icon-button { width: 32px; height: 32px; }

dialog {
  width: min(430px, calc(100vw - 32px));
  padding: 16px 20px 22px;
  border: 1px solid var(--edge);
  border-radius: 14px;
  color: inherit;
  background: var(--surface);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: #24263840; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.dialog-heading h2 { margin: 0; font-size: 17px; }
#share-dialog label, #name-form label { display: block; color: var(--muted); margin-bottom: 8px; }
#share-url, #sketch-name { width: 100%; height: 40px; padding: 0 10px; border: 1px solid var(--edge); border-radius: 6px; color: inherit; }
.name-title { margin: 4px 0 16px; font-size: 17px; }
.dialog-status { margin: 8px 0 0; color: var(--muted); }
.dialog-status:empty { margin: 0; }
.sketch-list { padding: 0; margin: 0; list-style: none; }
.sketch-list li { display: flex; align-items: center; gap: 3px; border-bottom: 1px solid var(--edge); }
.sketch-list li:last-child { border: 0; }
.sketch-list button {
  min-height: 40px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
}
.sketch-list button:hover { background: #f0ece3; }
.sketch-list .sketch-open {
  flex: 1;
  min-width: 0;
  padding-block: 8px;
  overflow-wrap: anywhere;
  text-align: start;
  font-weight: 650;
}
.sketch-open[aria-current="true"] { color: var(--blue); background: var(--highlight); }

#image-scopes { margin: 0; padding: 0; border: 0; }
#image-scopes legend { margin-bottom: 4px; padding: 0; color: var(--muted); font-size: 13px; }
#image-scopes label { display: flex; align-items: center; gap: 8px; min-height: 38px; cursor: pointer; }
#image-scopes input { width: 16px; height: 16px; margin: 0; accent-color: var(--blue); }
#image-scopes label:has(input:disabled) { color: var(--muted); cursor: default; }
#image-status { margin: 0; color: var(--muted); }
#image-status:not(:empty) { margin-top: 8px; }
#image-copy:disabled { opacity: .65; }
.image-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.image-download {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--edge);
  border-radius: 9px;
  background: transparent;
  font-size: 13px;
  font-weight: 650;
}
.image-download:hover { background: #f0ece3; }

@media (max-width: 620px) {
  :root { --bar-height: 60px; --gutter: 12px; --selection-bottom: calc(max(12px, env(safe-area-inset-bottom)) + 63px); }
  .tools { top: 12px; }
  .history, .camera { bottom: max(12px, env(safe-area-inset-bottom)); }
}

@media (max-width: 390px) {
  .identity { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 8px; }
  .logo { grid-row: span 2; width: 32px; height: 32px; }
  h1 { font-size: 21px; }
  .workspace { margin: 0; padding: 0; border: 0; font-size: 11px; }
  .header-actions { gap: 5px; }
  .share { padding-inline: 9px; }
  .camera .icon-button, .history .icon-button { width: 33px; }
  .tools { gap: 0; }
  .tools .icon-button { width: clamp(34px, 11.5vw, 40px); }
}

@media (pointer: coarse) {
  .tools .icon-button { height: 44px; }
  .selection-dock .icon-button, .swatch, .group-done, .arrange-menu button, .arrow-styles button { height: 44px; }
  .camera .icon-button, .history .icon-button { height: 44px; }
  .sketch-list button, #name-form button { min-height: 44px; }
}
