:root {
  --ink: #000000;
  --muted: #5c5c5c;
  --accent: #bc0202;
  --accent-soft: #f7e8e8;
  --pressed: #830000;
  --line: rgba(0, 0, 0, 0.1);
  --island: #ffffff;
  --hover: #f0f0f0;
  --app-bg: #ececec;
  --paper: #ffffff;
  --chrome: #000000;
  --chrome-ink: #ffffff;
  --chrome-muted: #a3a3a3;
  --chrome-hover: #1a1a1a;
  --chrome-pressed: #ff0000;
  --chrome-pressed-ink: #ffffff;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 12px 32px rgba(0, 0, 0, 0.1);
  --chrome-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 16px 40px rgba(0, 0, 0, 0.35);
  --ui: "Varela Round", "Segoe UI", sans-serif;
  --menu: "Varela Round", "Segoe UI", sans-serif;
  --hand: "Varela Round", "Segoe UI", sans-serif;
  --display: "Cabin Condensed", "Arial Narrow", sans-serif;
  color: var(--ink);
  font-family: var(--ui);
}

html[data-theme="dusk"] {
  --ink: #f5f5f5;
  --muted: #a3a3a3;
  --accent: #ff0000;
  --accent-soft: #2a1212;
  --pressed: #ff0000;
  --line: rgba(255, 255, 255, 0.12);
  --island: #111111;
  --hover: #1c1c1c;
  --app-bg: #0a0a0a;
  --shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 16px 40px rgba(0, 0, 0, 0.5);
  --chrome: #000000;
  --chrome-ink: #ffffff;
  --chrome-muted: #a3a3a3;
  --chrome-hover: #1a1a1a;
  --chrome-pressed: #ff0000;
  --chrome-pressed-ink: #ffffff;
  --chrome-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 18px 44px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--app-bg);
}

body {
  background:
    radial-gradient(ellipse 55% 40% at 50% -8%, rgba(188, 2, 2, 0.07), transparent 55%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.55), transparent 32%),
    var(--app-bg);
}

html[data-theme="dusk"] body {
  background:
    radial-gradient(ellipse 50% 36% at 50% 0%, rgba(188, 2, 2, 0.18), transparent 50%),
    var(--app-bg);
}

button, textarea { font: inherit; color: inherit; }

button {
  border: 0;
  background: transparent;
  border-radius: 10px;
  cursor: pointer;
}

button:hover { background: var(--hover); }

button[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--pressed);
}

button:focus-visible, .swatch:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

button:disabled { opacity: 0.4; cursor: default; }

#canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

#text-editor {
  position: fixed;
  z-index: 5;
  margin: 0;
  padding: 4px 6px;
  border: 0;
  border-bottom: 1.5px dashed rgba(28, 26, 23, 0.35);
  border-radius: 0;
  background: transparent;
  resize: none;
  overflow: hidden;
  line-height: 1.25;
  font-family: var(--hand);
  box-sizing: border-box;
}

#text-editor:focus { outline: none; }
#text-editor[hidden] { display: none; }

.topbar, .bottombar, .properties, .hint, .note {
  position: fixed;
  z-index: 4;
}

.topbar {
  top: 8px;
  left: 14px;
  right: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  pointer-events: none;
}

.bottombar {
  left: 14px;
  bottom: 14px;
  pointer-events: none;
}

.island {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  background: var(--island);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.brand-island {
  position: relative;
  grid-column: 1;
  justify-self: start;
  gap: 8px;
  padding: 6px 8px 6px 10px;
  z-index: 2;
  background: color-mix(in srgb, var(--island) 88%, transparent);
  backdrop-filter: blur(14px);
}

.mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: var(--ink);
  border-radius: 8px;
}

.mark svg,
.mark img { display: block; }

a.mark { text-decoration: none; }
a.mark:hover { background: var(--hover); }

.brand-name {
  display: block;
  padding-right: 4px;
  text-decoration: none;
  color: inherit;
  font-family: var(--display);
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
}

.workspace-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  margin-inline: 2px;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  border-radius: 12px;
}

.workspace-nav a {
  text-decoration: none;
  color: var(--muted);
  font-family: var(--menu);
  font-weight: 700;
  font-size: 12px;
  padding: 7px 11px;
  border-radius: 9px;
}

.workspace-nav a:hover { color: var(--ink); background: color-mix(in srgb, var(--island) 70%, transparent); }

.workspace-nav a[aria-current="page"] {
  background: var(--ink);
  color: var(--island);
}

.workspace-nav a[aria-current="page"]:hover {
  background: var(--ink);
  color: var(--island);
  opacity: 0.92;
}

.tool-island,
.zoom-island {
  background: var(--chrome);
  color: var(--chrome-ink);
  box-shadow: var(--chrome-shadow);
  border-radius: 18px;
  padding: 6px;
  gap: 2px;
}

.tool-island {
  grid-column: 2;
  justify-self: center;
  width: max-content;
  max-width: min(100%, calc(100vw - 28px));
  flex-wrap: wrap;
  justify-content: center;
  overflow: visible;
}

.tool-island .tool-button:hover,
.zoom-island button:hover,
.brand-island > .icon-button:hover {
  background: var(--chrome-hover);
}

.tool-island .tool-button[aria-pressed="true"],
.tool-island .tool-button[aria-pressed="true"]:hover {
  background: var(--chrome-pressed);
  color: var(--chrome-pressed-ink);
}

.zoom-island button[aria-pressed="true"] {
  background: var(--chrome-pressed);
  color: var(--chrome-pressed-ink);
}

.tool-button,
.zoom-island button,
.brand-island > .icon-button {
  min-width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0 6px;
  border-radius: 11px;
  color: var(--chrome-ink);
}

.tool-island .tool-button {
  flex: 0 0 auto;
}

.brand-island > .icon-button {
  color: var(--ink);
  min-width: 36px;
  height: 36px;
  border-radius: 10px;
}

.brand-island > .icon-button:hover {
  background: var(--hover);
  color: var(--ink);
}

.tool-button svg { display: block; }

.zoom-island #zoom-reset,
.zoom-island #undo,
.zoom-island #redo {
  min-width: auto;
  padding: 0 12px;
  font-family: var(--menu);
  font-size: 13px;
  font-weight: 700;
}

.zoom-island .sep {
  width: 1px;
  height: 18px;
  margin-inline: 4px;
  background: rgba(255, 255, 255, 0.14);
}

kbd {
  font: 11px/1 var(--menu);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 2px 5px;
  color: var(--muted);
}

.icon-button { width: 36px; }
.icon-button svg { display: block; }

.popover {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  min-width: 220px;
  padding: 8px;
  background: var(--island);
  color: var(--ink);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 2px;
}

.menu-panel {
  width: min(312px, calc(100vw - 24px));
  max-height: calc(100vh - 84px);
  overflow: auto;
  padding: 10px;
  font-family: var(--menu);
  letter-spacing: 0.01em;
}

.menu-rule {
  height: 1px;
  background: var(--line);
  margin: 8px 6px;
}

.menu-label {
  margin: 6px 10px 4px;
  color: var(--muted);
  font-family: var(--menu);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

#dup-mark {
  position: fixed;
  z-index: 30;
  width: 22px;
  height: 22px;
  margin: 0;
  border-radius: 8px;
  background: var(--chrome);
  color: var(--chrome-ink);
  font-size: 15px;
  font-weight: 800;
  line-height: 22px;
  text-align: center;
  pointer-events: none;
  box-shadow: var(--chrome-shadow);
}

.tune { display: grid; gap: 10px; padding: 6px 8px 8px; }
.tune-row,
.tune-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
}
.tune-block { align-items: flex-start; flex-direction: column; }

.theme-switch {
  display: flex;
  padding: 3px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  gap: 2px;
}

.theme-switch button {
  min-width: 0;
  height: 28px;
  padding: 0 10px;
  border-radius: 8px;
  font-family: var(--menu);
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.theme-switch button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--island);
}

select,
.tune input[type="text"],
dialog input[type="search"] {
  font: inherit;
  color: var(--ink);
  background: color-mix(in srgb, var(--ink) 4%, var(--island));
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 9px;
}

.paper-row { display: flex; flex-wrap: wrap; gap: 6px; }
.paper-row button,
.paper-row input[type="color"] {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.paper-row input[type="color"] { background: transparent; }

.popover[hidden] { display: none; }

.popover button,
.popover a.menu-link {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  text-align: left;
  padding: 9px 11px;
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  font-family: var(--menu);
  font-weight: 600;
}

.popover a.menu-link:hover,
.popover button:hover { background: var(--hover); }

.popover button span,
.popover a.menu-link span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.properties {
  top: 78px;
  right: 14px;
  left: auto;
  width: 264px;
  max-height: calc(100vh - 104px);
  overflow: auto;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
  padding: 14px 12px;
  background: var(--chrome);
  color: var(--chrome-ink);
  border-radius: 18px;
  box-shadow: var(--chrome-shadow);
  -webkit-overflow-scrolling: touch;
}

.properties[hidden] { display: none; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: -2px 0 2px;
}

.panel-head > span {
  font-family: var(--menu);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--chrome-muted);
}

.panel-close {
  width: 32px;
  height: 32px;
  min-width: 32px;
  padding: 0;
  border-radius: 10px;
  background: var(--chrome-hover);
  color: var(--chrome-ink);
  font-size: 22px;
  line-height: 1;
  font-weight: 600;
}

.panel-close:hover { background: color-mix(in srgb, var(--chrome-hover) 70%, white); }

.panel-open {
  position: fixed;
  z-index: 5;
  right: 14px;
  top: 78px;
  pointer-events: auto;
  border: 0;
  border-radius: 999px;
  padding: 10px 14px;
  background: var(--chrome);
  color: var(--chrome-ink);
  box-shadow: var(--chrome-shadow);
  font-family: var(--menu);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.panel-open[hidden] { display: none; }
.panel-open:hover { background: var(--chrome-hover); }

.properties button:hover { background: var(--chrome-hover); }

.properties button[aria-pressed="true"],
.properties button[aria-pressed="true"]:hover {
  background: var(--chrome-pressed);
  color: var(--chrome-pressed-ink);
}

.prop-group[hidden] { display: none; }

.prop-group {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 7px;
}

.prop-label {
  color: var(--chrome-muted);
  font-family: var(--menu);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.choice-row,
.color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.icon-choice {
  width: 44px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--chrome-hover);
  padding: 0;
  color: var(--chrome-ink);
}

.icon-choice svg { display: block; }

.color-chip {
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  padding: 2px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  cursor: pointer;
  background: conic-gradient(from 210deg, #ff0000, #f08c00, #ffec99, #2f9e44, #1971c2, #6741d9, #c2255c, #ff0000);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
}

.color-chip-face {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: var(--chip, #ffffff);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.28), 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.color-picker-native {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: 0;
  padding: 0;
}

.recent-swatches {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding-left: 6px;
  margin-left: 2px;
  border-left: 1px solid rgba(255, 255, 255, 0.16);
}

.recent-swatches[hidden] { display: none; }

.swatch.recent {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.opacity-scale {
  display: flex;
  justify-content: space-between;
  color: var(--chrome-muted);
  font-size: 12px;
}

.opacity-wrap { display: flex; flex-direction: column; gap: 2px; width: 100%; }

.properties .size-field {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.properties .size-field input[type="number"] {
  flex: 1;
  min-width: 0;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  padding: 0 10px;
  font: inherit;
  font-weight: 700;
}

.properties .px-unit {
  color: rgba(255, 255, 255, 0.55);
  font-weight: 800;
  font-size: 13px;
}

.swatch {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  padding: 0;
}

.swatch[aria-pressed="true"] {
  outline: 2px solid var(--chrome-pressed);
  outline-offset: 1px;
}

.swatch.none {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #d5d5e0 25%, transparent 25%),
    linear-gradient(-45deg, #d5d5e0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d5d5e0 75%),
    linear-gradient(-45deg, transparent 75%, #d5d5e0 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
}

.choice {
  height: 30px;
  padding: 0 10px;
  border-radius: 9px;
  font-family: var(--menu);
  font-size: 13px;
  font-weight: 700;
  background: var(--chrome-hover);
  color: var(--chrome-ink);
}

input[type="range"] { width: 100%; accent-color: var(--chrome-pressed); }

.hint,
.note {
  left: 50%;
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  pointer-events: none;
}

.hint {
  bottom: 78px;
  margin: 0;
  max-width: min(520px, calc(100vw - 32px));
  font-family: var(--menu);
  font-weight: 600;
  opacity: 0.85;
}
.hint[hidden] { display: none; }

.note {
  bottom: 112px;
  margin: 0;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  background: color-mix(in srgb, var(--island) 92%, transparent);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  border-radius: 14px;
  padding: 12px 14px;
  max-width: min(520px, calc(100vw - 24px));
  font-family: var(--menu);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  text-align: left;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  z-index: 6;
  margin: 0;
  padding: 10px 16px;
  background: var(--chrome);
  color: var(--chrome-ink);
  border-radius: 12px;
  font-family: var(--menu);
  font-size: 14px;
  font-weight: 700;
  box-shadow: var(--chrome-shadow);
}
.toast[hidden] { display: none; }

.note[hidden] { display: none; }
.note button {
  margin-left: auto;
  flex: none;
  color: var(--ink);
  font-weight: 800;
  font-family: var(--menu);
  padding: 6px 10px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}
.note button:hover { background: var(--hover); }

.sep { width: 1px; height: 22px; background: var(--line); margin-inline: 2px; }

dialog {
  border: 0;
  border-radius: 18px;
  padding: 0;
  background: var(--island);
  color: var(--ink);
  box-shadow: var(--shadow);
  max-width: min(440px, calc(100vw - 32px));
}

dialog::backdrop { background: rgba(20, 18, 14, 0.38); }
dialog form { padding: 20px 18px 16px; display: grid; gap: 12px; }
dialog h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.03em;
}
dialog p { margin: 0; line-height: 1.5; color: var(--muted); }
dialog input[type="search"] { width: 100%; }

.choice-list { display: grid; gap: 4px; max-height: 280px; overflow: auto; }
.choice-list button {
  text-align: left;
  padding: 9px 11px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-radius: 10px;
  font-family: var(--menu);
  font-weight: 600;
}
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; }

#help-list {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  font-size: 14px;
  font-family: var(--menu);
}

#help-list span { color: var(--muted); }

.credit { color: var(--muted); font-size: 13px; line-height: 1.45; }

.primary {
  background: var(--ink);
  color: var(--island);
  padding: 9px 14px;
  border-radius: 10px;
  font-family: var(--menu);
  font-weight: 700;
}

.primary:hover { background: color-mix(in srgb, var(--ink) 88%, white); color: var(--island); }

@media (max-width: 820px) {
  .topbar {
    display: flex;
    flex-wrap: wrap;
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    gap: 8px;
  }
  .tool-island {
    order: 3;
    width: 100%;
    max-width: 100%;
    justify-content: center;
  }
  .brand-name { display: none; }
  .workspace-nav a { padding: 6px 10px; font-size: 12px; }
  .properties {
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    top: auto;
    width: auto;
    bottom: max(64px, calc(56px + env(safe-area-inset-bottom)));
    max-height: min(48vh, calc(100dvh - 160px));
    border-radius: 18px 18px 14px 14px;
    z-index: 6;
  }
  .panel-open {
    right: max(10px, env(safe-area-inset-right));
    top: auto;
    bottom: max(64px, calc(56px + env(safe-area-inset-bottom)));
  }
  .bottombar {
    left: max(8px, env(safe-area-inset-left));
    bottom: max(8px, env(safe-area-inset-bottom));
  }
  .zoom-island { flex-wrap: wrap; max-width: calc(100vw - 24px); }
  .hint { display: none; }
  .note { display: none; }
  .menu-panel {
    max-width: min(320px, calc(100vw - 24px));
    max-height: min(70vh, calc(100dvh - 80px));
    overflow: auto;
  }
}

@media (max-width: 520px) {
  .topbar { grid-template-columns: 1fr; }
  .brand-island { max-width: 100%; }
  .zoom-island button#undo,
  .zoom-island button#redo { display: none; }
}
