@font-face {
  font-family: "Iosevka Fixed";
  src: url("./vendor/GlyphdrawFixed-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #151515;
  --panel: #202020;
  --panel-2: #292929;
  --panel-deep: #1a1a1a;
  --border: #444;
  --border-light: #5b5b5b;
  --text: #e6e6e6;
  --muted: #aaa;
  --accent: #72a7d8;
  --accent-bg: #2c4154;
  --canvas: #080808;
}

* { box-sizing: border-box; }

html, body {
  min-width: 360px;
  height: 100%;
  margin: 0;
}

/* All UI buttons, text, and controls scaled +25% from original 13px / 30px baseline */
body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16.25px/1.35 system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
}

button, input, select { font: inherit; }

button, select, input[type="number"] {
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel-2);
  color: var(--text);
}

button { padding: 5px 13px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--border-light); background: #343434; }
button:disabled { cursor: default; color: #6f6f6f; opacity: 0.6; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, #outputViewport:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Top title & status strip */
.app-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 15px;
  min-height: 52px;
  padding: 9px 18px;
  border-bottom: 1px solid var(--border);
  background: #1b1b1b;
}
.app-brand { font: 600 21.25px ui-monospace, monospace; color: var(--text); }
.app-subtitle { color: var(--muted); }
.tool-readout {
  padding: 3px 10px;
  border: 1px solid #3a3a3a;
  border-radius: 4px;
  background: #232323;
  color: var(--text);
  font: 15px ui-monospace, monospace;
}
.app-header .status {
  margin-left: auto;
  color: var(--muted);
  font-family: ui-monospace, monospace;
}

/* Main Photoshop-like horizontal workspace */
.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  position: relative;
  overflow: hidden;
}

/* Left Photoshop-style 2-column vertical icon toolbar */
.tool-rail {
  flex: 0 0 auto;
  width: 112px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 9px 7px;
  border-right: 1px solid var(--border);
  background: var(--panel);
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
  z-index: 10;
}

.rail-group {
  display: grid;
  grid-template-columns: repeat(2, 46px);
  justify-content: center;
  gap: 4px;
  width: 100%;
}
.rail-group.rail-single {
  display: flex;
  justify-content: center;
}

.rail-btn {
  position: relative;
  width: 46px;
  height: 46px;
  min-height: 46px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1.5px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--text);
}
.rail-btn svg {
  width: 25px;
  height: 25px;
  display: block;
}
.rail-btn:hover:not(:disabled) {
  border-color: var(--border);
  background: #2e2e2e;
}
.rail-btn.active {
  border-color: var(--accent);
  background: var(--accent-bg);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(114, 167, 216, 0.35);
}

.rail-sep {
  width: 82px;
  height: 1px;
  margin: 2px 0;
  border: 0;
  background: #3a3a3a;
}

.rail-spacer { flex: 1 1 auto; }

/* Photoshop-style overlapping FG / BG color widget */
.color-control {
  position: relative;
  width: 66px;
  display: flex;
  justify-content: center;
}

.swatch-stack {
  position: relative;
  width: 62px;
  height: 62px;
}

.swatch-btn {
  position: absolute;
  width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 0;
  border: 2px solid #888;
  border-radius: 3px;
  display: grid;
  place-items: center;
  font: 600 13px/1 ui-monospace, monospace;
  text-shadow: 0 1px 2px #000b;
  box-shadow: 0 1px 4px #0009;
}
.swatch-btn:hover {
  border-color: #fff;
}
.swatch-fg {
  top: 0;
  left: 0;
  z-index: 2;
}
.swatch-bg {
  right: 0;
  bottom: 0;
  z-index: 1;
  align-items: end;
  justify-items: end;
  padding: 0 3px 3px 0;
}

.swatch-mini {
  position: absolute;
  width: 20px;
  height: 20px;
  min-height: 20px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
}
.swatch-mini svg { width: 16px; height: 16px; display: block; }
.swatch-mini:hover:not(:disabled) {
  background: #333;
  color: #fff;
}
.swatch-swap { top: -1px; right: -2px; z-index: 3; }
.swatch-reset { bottom: -1px; left: -2px; z-index: 3; }

.color-popover {
  position: fixed;
  z-index: 100;
  top: 80px;
  left: 82px;
  width: 392px;
  padding: 10px;
  border: 1px solid #777;
  border-radius: 5px;
  background: #191919;
  box-shadow: 0 12px 30px #000c;
}
.popover-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.color-target-tabs {
  display: flex;
  gap: 6px;
}
.target-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 4px 10px;
  font-size: 14.5px;
  background: #232323;
  border-color: #444;
}
.target-tab.active {
  border-color: var(--accent);
  background: var(--accent-bg);
}
.target-tab i {
  width: 18px;
  height: 18px;
  border: 1px solid #888;
  border-radius: 2px;
  display: inline-block;
}
.target-tab b {
  font-family: ui-monospace, monospace;
  font-weight: 600;
}
.popover-close {
  min-height: 32px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  font-size: 24px;
  line-height: 1;
}
.popover-hint {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13.75px;
}
.irc-palette {
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  gap: 3px;
}
.irc-color {
  width: 100%;
  height: 29px;
  min-height: 29px;
  padding: 0;
  border: 1px solid #555;
  border-radius: 2px;
  background: var(--swatch);
  color: var(--label);
  font: 11.5px/1 ui-monospace, monospace;
  text-shadow: 0 1px 1px #0008;
  position: relative;
}
.irc-color.is-fg {
  outline: 2px solid #fff;
  outline-offset: -3px;
  border-color: #000;
  z-index: 2;
}
.irc-color.is-bg {
  box-shadow: inset 0 0 0 2px var(--accent);
  border-color: #000;
  z-index: 1;
}

/* Center canvas editor area */
.editor {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #111;
}

.canvas-viewport {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  padding: 18px;
  overflow: auto;
  background: #111;
}

.canvas-stack {
  position: relative;
  width: max-content;
  line-height: 0;
  margin: 0 auto;
  background: var(--canvas);
}

#referenceCanvas, #canvas, #gridCanvas, #inputCanvas {
  display: block;
  width: auto;
  max-width: none;
  height: auto;
  margin: 0;
}
#referenceCanvas {
  position: absolute;
  inset: 0;
  border: 1px solid transparent;
  pointer-events: none;
  z-index: 0;
}
#canvas {
  position: relative;
  z-index: 1;
  border: 1px solid #666;
  background: transparent;
  opacity: var(--glyph-opacity, 1);
  cursor: crosshair;
  touch-action: none;
}
#gridCanvas, #inputCanvas {
  position: absolute;
  inset: 0;
  border: 1px solid transparent;
  pointer-events: none;
}
#gridCanvas { z-index: 2; mix-blend-mode: difference; }
#inputCanvas { z-index: 3; }

.canvas-viewport.drop-active {
  outline: 2px dashed var(--accent);
  outline-offset: -8px;
}

/* Right dockable Properties Inspector */
.inspector {
  flex: 0 0 320px;
  width: 320px;
  overflow-y: auto;
  border-left: 1px solid var(--border);
  background: var(--panel);
}
.inspector.collapsed { display: none; }

.inspector-section {
  padding: 13px 15px;
  border-bottom: 1px solid #353535;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.inspector-heading {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.prop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
}
.prop-row select {
  flex: 0 1 175px;
  min-width: 0;
  padding: 4px 28px 4px 9px;
}
.prop-slider {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}
.prop-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.prop-label output {
  color: var(--text);
  font-family: ui-monospace, monospace;
}
.inspector input[type="range"] {
  width: 100%;
  height: 24px;
  margin: 0;
  accent-color: var(--accent);
}

.checkbox-control {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  cursor: pointer;
}
.checkbox-control input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.grid-form {
  display: flex;
  align-items: center;
  gap: 7px;
}
.grid-form input {
  width: 72px;
  padding: 4px 7px;
}
.grid-form .grid-x { color: var(--muted); }
.grid-form button { margin-left: auto; }

/* Reference image inspector controls */
.ref-actions {
  display: flex;
  gap: 8px;
}
.ref-actions button { flex: 1; }
.bezier-actions {
  display: flex;
  gap: 8px;
}
.bezier-actions[hidden] { display: none; }
.bezier-actions button { flex: 1; }
.primary-btn {
  border-color: var(--accent);
  background: var(--accent-bg);
  color: #fff;
}
.primary-btn:hover:not(:disabled) {
  border-color: #93c1ec;
  background: #38536b;
}
#adjustReference[aria-pressed="true"] {
  border-color: #d6a965;
  background: #483b24;
  color: #fce8c3;
}
.ref-status {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  word-break: break-word;
}
.ref-status:empty { display: none; }
.ref-controls {
  display: flex;
  flex-direction: column;
  gap: 11px;
}
.ref-controls[hidden] { display: none; }
.ref-hint {
  margin: 0;
  padding: 7px 9px;
  border: 1px solid #6e5932;
  border-radius: 4px;
  background: #2b2417;
  color: #f0d7a8;
  font-size: 14px;
  line-height: 1.4;
}
.ref-hint[hidden] { display: none; }
.ref-percent {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text);
  font-family: ui-monospace, monospace;
}
.ref-percent input {
  width: 78px;
  min-height: 32px;
  padding: 2px 6px;
}
.ref-dims {
  display: flex;
  gap: 10px;
}
.ref-dims label {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
}
.ref-dims input {
  width: 100%;
  min-width: 0;
  min-height: 34px;
  padding: 3px 6px;
}

.glyph-panel {
  border-bottom: 1px solid #353535;
}
.glyph-panel summary {
  padding: 12px 15px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}
.glyph-palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  border-top: 1px solid var(--border);
}
.glyph-swatch {
  display: grid;
  place-items: center;
  min-height: 65px;
  border: 0 solid #383838;
  border-right-width: 1px;
  border-bottom-width: 1px;
}
.glyph-swatch b { font: 31px "Iosevka Fixed", monospace; }
.glyph-swatch small { color: #888; font: 11.5px ui-monospace, monospace; }

.shortcuts-section .help {
  margin: 0;
  color: #9a9a9a;
  font-size: 14.5px;
  line-height: 1.55;
}
.shortcuts-section b {
  color: var(--text);
  font-weight: 600;
}

/* Shared button group */
.button-group { display: flex; }
.button-group button { border-radius: 0; }
.button-group button + button { margin-left: -1px; }
.button-group button:first-child { border-radius: 4px 0 0 4px; }
.button-group button:last-child { border-radius: 0 4px 4px 0; }
.button-group button.active {
  position: relative;
  z-index: 1;
  border-color: var(--accent);
  background: var(--accent-bg);
}

/* Bottom Collapsible Output / Preview Drawer (collapsed by default) */
.output-panel {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.output-summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 7px 18px;
  cursor: pointer;
  background: #1b1b1b;
  user-select: none;
}
.output-summary::-webkit-details-marker { display: none; }
.output-summary:hover { background: #232323; }

.output-chevron {
  width: 10px;
  height: 10px;
  border-right: 2.2px solid var(--muted);
  border-bottom: 2.2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 140ms ease;
  margin-right: 2px;
}
.output-panel[open] .output-chevron {
  transform: rotate(45deg);
}
.output-title {
  font-weight: 600;
  color: var(--text);
}
.output-summary-meta {
  color: var(--muted);
  font-family: ui-monospace, monospace;
  font-size: 15px;
}
.output-quick-copy {
  margin-left: auto;
  min-height: 36px;
  padding: 4px 14px;
}
.output-panel[open] .output-quick-copy {
  display: none;
}

.output-body {
  border-top: 1px solid var(--border);
}
.output-panel:not([open]) .output-body {
  display: none;
}

.output-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  min-height: 52px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-deep);
}
.output-toolbar > span { color: var(--muted); }
.output-toolbar #copy { margin-left: auto; }

#outputViewport {
  min-height: 160px;
  max-height: 34vh;
  padding: 14px 16px;
  overflow: auto;
  background: #090909;
  color: white;
}
#output {
  display: inline-block;
  min-width: 1px;
  min-height: 1px;
  font-family: "Iosevka Fixed", monospace;
  font-kerning: none;
  font-variant-ligatures: none;
}
#outputPlaceholder { margin: 0; color: var(--muted); }
#output .output-text {
  font-family: "Iosevka Fixed", monospace !important;
  text-rendering: geometricPrecision;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 960px) {
  .app-subtitle { display: none; }
  .inspector {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 25;
    box-shadow: -8px 0 24px #000b;
  }
}

@media (max-width: 620px) {
  .app-header { padding: 8px 12px; gap: 10px; }
  .tool-readout { display: none; }
  .tool-rail { width: 104px; padding: 7px 5px; }
  .rail-group { grid-template-columns: repeat(2, 44px); }
  .rail-btn { width: 44px; height: 44px; min-height: 44px; }
  .color-popover {
    position: fixed;
    top: 64px;
    left: 50%;
    transform: translateX(-50%);
    width: min(392px, calc(100vw - 16px));
  }
  .output-summary { padding: 7px 12px; }
  .output-summary-meta { display: none; }
}
