:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --line: #c9d2db;
  --line-strong: #8795a1;
  --text: #18202a;
  --muted: #5e6b78;
  --accent: #177a8c;
  --accent-2: #c54835;
  --focus: #f2b84b;
  --shadow: 0 12px 32px rgba(24, 32, 42, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
select,
input {
  font: inherit;
}

button,
select,
input[type="number"] {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

button {
  padding: 0 12px;
  cursor: pointer;
}

button:hover,
select:hover,
input[type="number"]:hover {
  border-color: var(--line-strong);
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 58px minmax(0, 1fr) 126px;
  height: 100%;
  height: 100dvh;
}

.menu-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  padding: 0 14px;
  z-index: 5;
}

.menu-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.menu-popover a {
  padding: 7px 12px;
  color: var(--text);
  text-decoration: none;
  border-radius: 6px;
}

.menu-popover a:hover,
.menu-popover a:focus-visible {
  background: var(--surface-2);
}

.menu {
  position: relative;
}

.menu summary {
  display: flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 6px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.menu summary::-webkit-details-marker {
  display: none;
}

.menu[open] summary,
.menu summary:hover {
  background: var(--surface-2);
}

.menu-popover {
  position: absolute;
  top: calc(100% + 7px);
  left: 0;
  display: grid;
  min-width: 190px;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}


.menu-popover button {
  justify-content: flex-start;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
}

.menu-popover button:hover {
  background: var(--surface-2);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
  flex: 0 1 auto;
}

.global-variants {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.global-variants button {
  display: grid;
  place-items: center;
  width: 28px;
  min-width: 0;
  min-height: 26px;
  padding: 0;
}

.global-variants button.active {
  border-color: var(--accent);
  background: #dff8fb;
  color: #0f4050;
  box-shadow: inset 0 0 0 1px var(--accent);
}

.layout-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.layout-section {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 5px;
}

.layout-section-label {
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  padding-top: 2px;
}

.layout-icon-grid {
  display: grid;
  gap: 2px;
}

.align-grid {
  grid-template-columns: repeat(6, 28px);
}

.distribute-grid {
  grid-template-columns: repeat(2, 28px);
}

.layout-icon-button {
  position: relative;
  width: 28px;
  min-width: 28px;
  height: 24px;
  min-height: 24px;
  padding: 0;
}

.layout-icon-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.layout-icon {
  position: relative;
  display: block;
  width: 22px;
  height: 18px;
  margin: auto;
}

.layout-icon::before,
.layout-icon::after,
.layout-icon span {
  position: absolute;
  content: "";
  display: block;
  box-sizing: border-box;
}

.layout-icon::before {
  background: #4f4f4f;
}

.layout-icon span {
  background: #555;
}

.layout-icon span + span {
  background: #b7b7b7;
}

.align-x-min::before,
.align-x-mean::before,
.align-x-max::before {
  top: 1px;
  width: 2px;
  height: 16px;
}

.align-x-min::before {
  left: 1px;
}

.align-x-mean::before {
  left: 10px;
}

.align-x-max::before {
  right: 1px;
}

.align-x-min span,
.align-x-mean span,
.align-x-max span {
  height: 6px;
}

.align-x-min span:first-child {
  left: 3px;
  top: 10px;
  width: 16px;
}

.align-x-min span + span {
  left: 3px;
  top: 3px;
  width: 10px;
}

.align-x-mean span:first-child {
  left: 5px;
  top: 10px;
  width: 12px;
}

.align-x-mean span + span {
  left: 7px;
  top: 3px;
  width: 8px;
}

.align-x-max span:first-child {
  right: 3px;
  top: 10px;
  width: 16px;
}

.align-x-max span + span {
  right: 3px;
  top: 3px;
  width: 10px;
}

.align-y-min::before,
.align-y-mean::before,
.align-y-max::before {
  left: 1px;
  width: 20px;
  height: 2px;
}

.align-y-min::before {
  top: 1px;
}

.align-y-mean::before {
  top: 8px;
}

.align-y-max::before {
  bottom: 1px;
}

.align-y-min span,
.align-y-mean span,
.align-y-max span {
  width: 6px;
}

.align-y-min span:first-child {
  left: 4px;
  top: 3px;
  height: 14px;
}

.align-y-min span + span {
  left: 12px;
  top: 3px;
  height: 9px;
}

.align-y-mean span:first-child {
  left: 5px;
  top: 4px;
  height: 10px;
}

.align-y-mean span + span {
  left: 13px;
  top: 5px;
  height: 8px;
}

.align-y-max span:first-child {
  left: 4px;
  bottom: 3px;
  height: 14px;
}

.align-y-max span + span {
  left: 12px;
  bottom: 3px;
  height: 9px;
}

.distribute-x::before,
.distribute-x::after {
  top: 1px;
  width: 2px;
  height: 16px;
  background: #4f4f4f;
}

.distribute-x::before {
  left: 2px;
}

.distribute-x::after {
  right: 2px;
}

.distribute-x span {
  top: 4px;
  width: 6px;
  height: 10px;
}

.distribute-x span:first-child {
  left: 5px;
}

.distribute-x span + span {
  right: 5px;
}

.distribute-y::before,
.distribute-y::after {
  left: 2px;
  width: 18px;
  height: 2px;
  background: #4f4f4f;
}

.distribute-y::before {
  top: 2px;
}

.distribute-y::after {
  bottom: 2px;
}

.distribute-y span {
  left: 6px;
  width: 10px;
  height: 5px;
}

.distribute-y span:first-child {
  top: 5px;
}

.distribute-y span + span {
  bottom: 5px;
}

.header-file-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.header-file-actions button {
  min-height: 28px;
  padding: 0 7px;
}

.history-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.history-controls button {
  min-height: 28px;
  padding: 0 7px;
}

.history-controls select {
  width: 170px;
  min-height: 28px;
  padding: 0 34px 0 8px;
  appearance: none;
  background-color: var(--surface);
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 13px, calc(100% - 11px) 13px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  text-overflow: ellipsis;
}

.active-letter {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.active-letter strong {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: var(--text);
  color: #fff;
  font-size: 18px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  min-height: 0;
  min-width: 0;
}

.stage-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  background:
    linear-gradient(90deg, rgba(24, 32, 42, 0.05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(24, 32, 42, 0.05) 1px, transparent 1px);
  background-size: 18px 18px;
}

.stage {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.guide-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

#artboard {
  fill: #fbfcfd;
  stroke: #abb8c4;
  stroke-width: 2;
}

.grid-line {
  stroke: #d6dee6;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.grid-line.major {
  stroke: #b8c5d1;
}

#grid-layer,
#guide-layer {
  pointer-events: none;
}

.shape {
  cursor: grab;
}

.shape:active {
  cursor: grabbing;
}

.shape path {
  stroke: #17202a;
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
}

.shape .selection-glow {
  fill: rgba(242, 184, 75, 0.14);
  stroke: rgba(23, 122, 140, 0.26);
  stroke-width: 18;
  filter: drop-shadow(0 0 7px rgba(23, 122, 140, 0.32));
  pointer-events: none;
}

.shape.selected path:not(.selection-glow) {
  filter: drop-shadow(0 0 5px rgba(23, 122, 140, 0.32));
}

.edit-handle-guide {
  stroke: rgba(24, 32, 42, 0.62);
  stroke-width: 3;
  stroke-dasharray: 10 8;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.curve-control-guide {
  stroke: rgba(23, 122, 140, 0.38);
  stroke-width: 2;
  stroke-dasharray: 4 8;
}

.curve-pair-guide {
  stroke: rgba(23, 122, 140, 0.32);
  stroke-width: 2;
  stroke-dasharray: 3 9;
}

.hover-handles .edit-handle-guide {
  opacity: 0.5;
}

.edit-handle {
  fill: #ffffff;
  stroke: var(--accent);
  stroke-width: 4;
  filter: drop-shadow(0 2px 5px rgba(24, 32, 42, 0.24));
  vector-effect: non-scaling-stroke;
}

.rotate-handle {
  cursor: grab;
}

.length-handle {
  cursor: ew-resize;
}

.stem-combo-handle {
  cursor: grab;
}

.curve-rotate-handle {
  cursor: grab;
  pointer-events: all;
}

.curve-rotate-rail {
  fill: none;
  stroke: rgba(23, 122, 140, 0.78);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.curve-rotate-box {
  fill: #ffffff;
  stroke: var(--accent);
  stroke-width: 4;
  filter: drop-shadow(0 2px 5px rgba(24, 32, 42, 0.24));
  vector-effect: non-scaling-stroke;
}

.curve-rotate-handle:hover .curve-rotate-rail,
.curve-rotate-handle:hover .curve-rotate-box {
  stroke: #0f6777;
}

.curve-rotate-handle:hover .curve-rotate-box {
  fill: #e9fbff;
}

.curve-pair-handle {
  cursor: grab;
  pointer-events: all;
}

.curve-pair-diamond {
  fill: #ffffff;
  stroke: var(--accent);
  stroke-width: 4;
  filter: drop-shadow(0 2px 5px rgba(24, 32, 42, 0.24));
  vector-effect: non-scaling-stroke;
}

.curve-pair-mark {
  fill: none;
  stroke: rgba(23, 122, 140, 0.82);
  stroke-width: 3;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.curve-pair-handle:hover .curve-pair-diamond {
  fill: #e9fbff;
  stroke: #0f6777;
}

.curve-pair-handle:hover .curve-pair-mark {
  stroke: #0f6777;
}

.stem-seed-handle {
  cursor: grab;
}

.circle-stem-arc {
  fill: none;
  stroke: rgba(23, 32, 42, 0.72);
  stroke-width: 3;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.stem-seed-handle:hover {
  stroke: #0f6777;
}

.edit-handle:hover {
  fill: #e9fbff;
  stroke: #0f6777;
}

#selection-box {
  fill: rgba(23, 122, 140, 0.12);
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-dasharray: 8 6;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.inspector {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--surface);
  padding: 16px;
}

.panel-section {
  display: grid;
  gap: 8px;
}

.panel-section h2 {
  margin: 0;
  font-size: 15px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.panel-grid {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.panel-grid input {
  width: 100%;
  padding: 0 8px;
}

.panel-section select {
  width: 100%;
  padding: 0 8px;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.swatch {
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.swatch.active {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.panel-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stage-toggle {
  display: inline-grid;
  grid-template-columns: repeat(2, 28px);
  gap: 4px;
}

.stage-toggle button {
  min-width: 0;
  height: 26px;
  padding: 0;
}

.stage-toggle button.active {
  border-color: var(--accent);
  background: #dff8fb;
  color: #0f4050;
  box-shadow: inset 0 0 0 1px var(--accent);
}

.polish-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.polish-grid #polish-all {
  grid-column: 1 / -1;
}

.letter-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 82px;
  gap: 6px;
  align-items: stretch;
  overflow-x: auto;
  overflow-y: hidden;
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 8px 10px;
}

.letter-card {
  display: grid;
  grid-template-rows: 25px minmax(0, 1fr);
  gap: 4px;
  min-width: 0;
  overflow: hidden;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
}

.letter-card.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.letter-card-top {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 3px;
  min-width: 0;
}

.letter-label-button {
  display: grid;
  place-items: center;
  min-height: 18px;
  width: 18px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

.variant-pills {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.variant-pill {
  display: grid;
  place-items: center;
  min-height: 17px;
  width: 17px;
  padding: 0;
  border-radius: 4px;
  border-color: #d5dee6;
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
}

.variant-pill.active {
  border-color: var(--accent);
  background: #dff7fb;
  color: var(--text);
}

.variant-pill.empty {
  opacity: 0.5;
}

.letter-preview-button {
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: #f7f9fb;
}

.letter-preview {
  display: block;
  width: 100%;
  height: 100%;
}

.letter-preview-bg {
  fill: #f7f9fb;
}

.letter-preview-empty {
  fill: none;
  stroke: #ccd6df;
  stroke-width: 1.5;
}

@media (max-width: 900px) {
  .menu-bar {
    gap: 8px;
  }

  .history-controls select {
    width: 132px;
    padding-right: 28px;
  }

  .history-controls button {
    padding: 0 7px;
  }

  .layout-actions {
    gap: 4px;
  }

  .layout-icon-button {
    width: 26px;
    min-width: 26px;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) 250px;
  }

  .inspector {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .letter-strip {
    grid-auto-columns: 82px;
    height: 150px;
  }
}

@media (max-width: 700px) {
  .app-shell {
    grid-template-rows: 94px minmax(0, 1fr) 126px;
  }

  .menu-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 36px 38px;
    gap: 4px;
    padding: 6px 10px;
  }

  .header-right {
    width: 100%;
    align-self: stretch;
    font-size: 14px;
  }

  .history-controls {
    order: -1;
    flex-shrink: 0;
  }

  .header-file-actions {
    order: 1;
  }
}

@media (max-height: 600px) and (min-width: 600px) {
  .app-shell { grid-template-rows: 48px minmax(0, 1fr) 100px; }
  .menu-bar { display: flex; padding: 0 10px; }
  .header-right { width: auto; }
  .workspace {
    grid-template-columns: minmax(0, 1fr) 240px;
    grid-template-rows: minmax(0, 1fr);
  }
  .inspector { border-top: 0; border-left: 1px solid var(--line); }
  .letter-strip { height: auto; }
}
