:root {
  color-scheme: light;
  --ink: #1b1a18;
  --muted: #6f6a62;
  --paper: #fffdf8;
  --cream: #f7f3eb;
  --line: #ded8cd;
  --soft-line: #ece7de;
  --accent: #e4572e;
  --accent-dark: #bd3d1b;
  --selection: #2166f3;
  --danger: #b42318;
  --shadow: 0 18px 55px rgb(47 38 25 / 16%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
  color: var(--ink);
  background: var(--cream);
}

body {
  min-height: 100dvh;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
label,
select,
input[type="color"] {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgb(33 102 243 / 28%);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 370px minmax(0, 1fr);
  grid-template-rows: 68px minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

.topbar {
  position: relative;
  z-index: 5;
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  padding: 0 18px 0 20px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 34px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
}

.brand-mark circle {
  fill: var(--accent);
  stroke: none;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-family: Georgia, serif;
  font-size: 21px;
  line-height: 1;
}

.brand span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.top-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.button,
.icon-button,
.text-button,
.segmented button,
.bubble-list button {
  border: 0;
  cursor: pointer;
}

.button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 750;
  transition: background .16s ease, color .16s ease, transform .16s ease, border-color .16s ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button-primary {
  color: #fff;
  background: var(--ink);
}

.button-primary:hover {
  background: #36322d;
}

.button-photopea {
  color: #fff;
  background: #3154d8;
}

.button-photopea:hover {
  background: #243fae;
}

.button-photopea:disabled {
  cursor: wait;
  opacity: .62;
}

.button-secondary {
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
}

.button-secondary:hover {
  border-color: #b9b1a5;
  background: #fff;
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  color: #444038;
  background: transparent;
  border-radius: 9px;
  font-size: 20px;
  font-weight: 700;
}

.icon-button:hover {
  background: #eee9df;
}

.icon-button.danger:hover {
  color: var(--danger);
  background: #fff0ee;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: .42;
}

.inspector {
  grid-row: 2;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--paper);
  border-right: 1px solid var(--line);
  scrollbar-color: #c8c0b4 transparent;
  scrollbar-width: thin;
}

.panel-section {
  padding: 22px 24px 24px;
  border-bottom: 1px solid var(--soft-line);
}

.panel-section:last-child {
  border-bottom: 0;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.section-heading.compact {
  margin-bottom: 17px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent-dark);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.section-heading h2 {
  margin: 0;
  font-family: Georgia, serif;
  font-size: 20px;
  line-height: 1.1;
}

.count-badge {
  display: inline-grid;
  min-width: 26px;
  height: 26px;
  place-items: center;
  padding: 0 7px;
  color: var(--muted);
  background: #f0ece4;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.bubble-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.bubble-list button {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 42px;
  padding: 7px 10px;
  color: var(--ink);
  text-align: left;
  background: #f4f0e9;
  border: 1px solid transparent;
  border-radius: 9px;
}

.bubble-list button:hover {
  background: #eee8de;
}

.bubble-list button[aria-current="true"] {
  background: #fff;
  border-color: var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
}

.layer-number {
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  color: #fff;
  background: var(--ink);
  border-radius: 50%;
  font-size: 11px;
  font-weight: 850;
}

.layer-copy {
  overflow: hidden;
  font-size: 13px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-kind {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.field-label,
.field > span,
.range-heading label,
.small-label {
  color: #5d584f;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .055em;
  text-transform: uppercase;
}

.field-label {
  display: block;
  margin-bottom: 6px;
}

textarea,
select,
input[type="number"] {
  width: 100%;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cec7bc;
  border-radius: 9px;
}

textarea {
  min-height: 110px;
  padding: 11px 12px;
  line-height: 1.42;
  resize: vertical;
}

select,
input[type="number"] {
  height: 39px;
  padding: 0 10px;
}

.field-help {
  margin: 7px 0 14px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

code {
  padding: 1px 3px;
  color: #514a40;
  background: #f1ece4;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: .92em;
}

.field-grid {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.field-grid.two {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.field-grid.three {
  grid-template-columns: 1fr 1fr .82fr;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field.span-two {
  grid-column: 1 / -1;
}

.colour-field input[type="color"] {
  width: 100%;
  height: 39px;
  padding: 4px;
  background: #fff;
  border: 1px solid #cec7bc;
  border-radius: 9px;
  cursor: pointer;
}

.toggle-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.check-button input,
.switch-label input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.check-button span {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  color: #59544c;
  background: #f1ede6;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
}

.check-button input:checked + span {
  color: var(--ink);
  background: #fff;
  border-color: var(--ink);
}

.check-button input:focus-visible + span,
.switch-label input:focus-visible + .switch {
  outline: 3px solid rgb(33 102 243 / 28%);
  outline-offset: 2px;
}

.switch-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-left: auto;
  color: #59544c;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.switch {
  position: relative;
  width: 35px;
  height: 20px;
  background: #c8c1b6;
  border-radius: 999px;
  transition: background .16s ease;
}

.switch::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  content: "";
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgb(0 0 0 / 20%);
  transition: transform .16s ease;
}

.switch-label input:checked + .switch {
  background: var(--accent);
}

.switch-label input:checked + .switch::after {
  transform: translateX(15px);
}

.range-field {
  display: grid;
  gap: 7px;
  margin-top: 15px;
}

.range-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.range-field output {
  min-width: 38px;
  padding: 2px 5px;
  color: var(--ink);
  text-align: center;
  background: #eee9e0;
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11px;
  letter-spacing: 0;
}

input[type="range"] {
  width: 100%;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  background: #efebe4;
  border-radius: 10px;
}

.segmented button {
  min-height: 34px;
  padding: 6px 8px;
  color: #625d54;
  background: transparent;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 800;
}

.segmented button:hover {
  color: var(--ink);
  background: rgb(255 255 255 / 55%);
}

.segmented button[aria-pressed="true"] {
  color: #fff;
  background: var(--ink);
  box-shadow: 0 2px 5px rgb(32 28 23 / 18%);
}

.segmented.small {
  width: 190px;
  grid-template-columns: 1fr 1fr;
}

.colour-grid,
.number-grid {
  margin-top: 14px;
}

#tail-controls {
  margin-top: 5px;
  padding-top: 2px;
}

.upload-row,
.export-row,
.canvas-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
}

.upload-button {
  cursor: pointer;
  font-size: 13px;
}

.text-button {
  padding: 6px 3px;
  color: var(--danger);
  background: transparent;
  font-size: 12px;
  font-weight: 750;
}

.text-button:hover {
  text-decoration: underline;
}

.canvas-toggle {
  justify-content: space-between;
  margin-top: 15px;
}

.export-row {
  margin-top: 18px;
}

.export-row .button-primary {
  flex: 1 1 auto;
}

.export-row select {
  width: 61px;
  flex: 0 0 auto;
}

.workspace {
  display: flex;
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  background: #ded8cf;
}

.workspace-bar {
  display: flex;
  min-height: 43px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 18px;
  color: #5c564e;
  background: #eee9e0;
  border-bottom: 1px solid #ccc5b9;
  font-size: 12px;
}

.workspace-bar p {
  margin: 0;
}

#zoom-readout {
  flex: 0 0 auto;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11px;
}

.stage {
  display: flex;
  min-height: 0;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 28px;
  background-color: #d9d4cc;
  background-image:
    linear-gradient(45deg, rgb(255 255 255 / 38%) 25%, transparent 25%, transparent 75%, rgb(255 255 255 / 38%) 75%),
    linear-gradient(45deg, rgb(255 255 255 / 38%) 25%, transparent 25%, transparent 75%, rgb(255 255 255 / 38%) 75%);
  background-position: 0 0, 9px 9px;
  background-size: 18px 18px;
}

.canvas-frame {
  position: relative;
  flex: 0 0 auto;
  overflow: hidden;
  background: transparent;
  box-shadow: var(--shadow), 0 0 0 1px rgb(60 48 33 / 16%);
  touch-action: none;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
  user-select: none;
}

.bubble-body {
  cursor: grab;
}

.bubble-body:active {
  cursor: grabbing;
}

.selection-box {
  fill: none;
  stroke: var(--selection);
  stroke-dasharray: 10 8;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.selection-handle {
  fill: #fff;
  stroke: var(--selection);
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
}

.selection-handle.tail {
  fill: var(--selection);
  cursor: crosshair;
}

.selection-handle.resize {
  cursor: nwse-resize;
}

.keyboard-hint {
  min-height: 31px;
  margin: 0;
  padding: 8px 18px;
  color: #716a61;
  background: #eee9e0;
  border-top: 1px solid #ccc5b9;
  font-size: 10px;
  letter-spacing: .035em;
  text-align: center;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 18px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 40px));
  padding: 11px 15px;
  color: #fff;
  background: var(--ink);
  border-radius: 10px;
  box-shadow: 0 8px 30px rgb(0 0 0 / 24%);
  font-size: 13px;
  font-weight: 750;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity .18s ease, transform .18s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.is-hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(420px, 56dvh) auto;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .topbar {
    position: sticky;
    top: 0;
    grid-row: 1;
    min-height: 62px;
    padding: 8px 12px;
  }

  .brand span {
    display: none;
  }

  .top-actions {
    gap: 2px;
  }

  .top-actions .button-primary {
    min-height: 38px;
    padding: 7px 10px;
    font-size: 12px;
  }

  .icon-button {
    width: 34px;
    height: 34px;
  }

  .workspace {
    grid-column: 1;
    grid-row: 2;
  }

  .stage {
    padding: 18px;
  }

  .keyboard-hint {
    display: none;
  }

  .inspector {
    grid-column: 1;
    grid-row: 3;
    max-height: none;
    overflow: visible;
    border-top: 1px solid var(--line);
    border-right: 0;
  }

  .workspace-bar {
    padding: 0 12px;
  }

  .workspace-bar p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

@media (max-width: 520px) {
  .topbar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .top-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .brand-mark {
    width: 31px;
  }

  .brand strong {
    font-size: 18px;
  }

  .photopea-mode .topbar {
    gap: 8px;
    flex-wrap: wrap;
    padding: 8px 12px;
  }

  .photopea-mode .brand span,
  .photopea-mode #duplicate-bubble,
  .photopea-mode #send-backward,
  .photopea-mode #bring-forward {
    display: none;
  }

  .photopea-mode .button-photopea {
    min-height: 38px;
    padding: 7px 11px;
    font-size: 12px;
  }

  .top-actions .button-primary {
    width: 38px;
    padding: 0;
    font-size: 0;
  }

  .top-actions .button-primary span {
    font-size: 22px;
  }

  #send-backward,
  #bring-forward {
    display: none;
  }

  .app-shell {
    grid-template-rows: auto minmax(360px, 52dvh) auto;
  }

  .panel-section {
    padding-right: 18px;
    padding-left: 18px;
  }

  .field-grid.three {
    grid-template-columns: 1fr 1fr;
  }

  .field-grid.three .field:last-child {
    grid-column: 1 / -1;
  }

  .canvas-toggle {
    align-items: flex-start;
    flex-direction: column;
  }

  .segmented.small {
    width: 100%;
  }

  .export-row {
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
