:root {
  color-scheme: dark;
  --chrome: #202020;
  --chrome-2: #2b2b2b;
  --chrome-3: #383838;
  --ink: #f3f3f3;
  --muted: #a9a9a9;
  --paper: #fbfbfb;
  --grid-minor: #e7eeee;
  --grid: #bad8d2;
  --grid-inch: #86aaa3;
  --accent: #e2463d;
  --accent-2: #18a16f;
  --line: #525252;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #161616;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

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

.app {
  display: grid;
  grid-template-columns: 56px 1fr;
  grid-template-rows: 40px 1fr;
  width: 100%;
  height: 100%;
}

.tools {
  grid-row: 1 / span 2;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  padding: 8px 6px;
  background: var(--chrome);
  border-right: 1px solid #101010;
  z-index: 3;
}

.topbar {
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 40px;
  padding: 0 10px 0 12px;
  background: var(--chrome-2);
  border-bottom: 1px solid #151515;
  z-index: 2;
}

.brand {
  font-size: 13px;
  font-weight: 700;
  color: #f5f5f5;
  letter-spacing: 0;
  flex: 0 0 auto;
}

.project-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.project-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 84px;
  max-width: 160px;
  height: 29px;
  min-height: 29px;
  padding: 0 6px 0 9px;
  color: #d7d7d7;
  background: #242424;
}

.project-tab-title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-tab-close {
  display: grid;
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
  place-items: center;
  border-radius: 4px;
  color: #bfbfbf;
  font-size: 12px;
  line-height: 1;
}

.project-tab-close:hover {
  background: #3d3d3d;
  color: #fff;
}

.project-tab.active {
  color: #fff;
  border-color: var(--accent-2);
  background: #17382d;
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex: 0 0 auto;
}

button,
select,
input {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #303030;
  color: var(--ink);
  outline: none;
}

button {
  min-height: 30px;
  padding: 0 9px;
  cursor: pointer;
}

button:hover,
select:hover,
input:hover {
  border-color: #777;
}

button:active {
  transform: translateY(1px);
}

.tool {
  width: 42px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
}

.tool img {
  width: 22px;
  height: 22px;
  display: block;
  pointer-events: none;
}

.tool.active {
  border-color: var(--accent);
  background: #4a2421;
  color: #fff;
}

.tool-gap {
  width: 36px;
  height: 1px;
  margin: 3px 0;
  background: #424242;
}

.color-chip {
  width: 36px;
  height: 32px;
  padding: 0;
  background: #000;
}

.thin-control {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 44px;
  gap: 2px;
  color: var(--muted);
  font-size: 10px;
}

.thin-control label {
  display: block;
  width: 100%;
  line-height: 1;
  text-align: center;
}

.thin-control input {
  width: 100%;
  height: 28px;
  padding: 0 3px;
  text-align: center;
}

#fontSize {
  width: 44px;
  height: 28px;
  padding: 0 3px;
  text-align: center;
}

.snap-control {
  display: grid;
  grid-template-columns: 15px 1fr 15px;
  width: 44px;
  gap: 1px;
  align-items: center;
}

.snap-control button {
  min-height: 24px;
  height: 24px;
  padding: 0;
}

#detailReadout {
  display: block;
  min-width: 0;
  font-size: 9px;
  color: #efefef;
  text-align: center;
}

.extend-button {
  width: 44px;
  height: 30px;
  padding: 0;
  font-size: 11px;
  font-weight: 700;
}

#fontFamily {
  width: 44px;
  height: 28px;
  padding: 0 2px;
  font-size: 10px;
}

.workspace {
  position: relative;
  grid-column: 2;
  grid-row: 2;
  overflow: hidden;
  background: #262626;
}

#paperCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.hud {
  position: absolute;
  left: 10px;
  bottom: 10px;
  max-width: min(380px, calc(100% - 20px));
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(25, 25, 25, 0.82);
  color: #f5f5f5;
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.color-panel {
  position: fixed;
  left: 62px;
  top: 72px;
  width: 190px;
  padding: 10px;
  border: 1px solid #444;
  border-radius: 8px;
  background: #242424;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  z-index: 9;
}

.text-panel {
  position: fixed;
  left: 64px;
  top: 88px;
  width: min(360px, calc(100vw - 76px));
  display: grid;
  grid-template-rows: 30px 100px repeat(5, auto);
  gap: 8px;
  padding: 10px;
  border: 1px solid #464646;
  border-radius: 8px;
  background: #242424;
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.38);
  z-index: 8;
}

.text-head,
.text-row,
.text-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.text-head {
  justify-content: space-between;
}

#textValue {
  width: 100%;
  min-height: 0;
  resize: none;
  padding: 7px;
  border: 1px solid #4b4b4b;
  border-radius: 6px;
  background: #171717;
  color: #f2f2f2;
  outline: none;
}

#textFont {
  flex: 1;
  min-width: 0;
  height: 30px;
}

#textSize {
  width: 76px;
  height: 30px;
  padding: 0 6px;
}

.color-field,
.check-field {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #d7d7d7;
  font-size: 12px;
}

.color-field input[type="color"],
#textGlowColor {
  width: 32px;
  height: 28px;
  padding: 1px;
}

.check-field input {
  margin: 0;
}

.text-toggles button,
.text-align button {
  width: 34px;
  min-height: 28px;
  padding: 0;
  font-weight: 700;
}

.text-toggles button.active,
.text-align button.active {
  border-color: var(--accent-2);
  background: #17382d;
}

#textGlowSize {
  flex: 1;
  min-width: 0;
}

.text-actions {
  justify-content: space-between;
}

.text-actions button {
  flex: 1;
}

#svPicker {
  display: block;
  width: 168px;
  height: 120px;
  border-radius: 6px;
  cursor: crosshair;
}

#hueSlider {
  width: 168px;
  margin-top: 8px;
}

.color-entry {
  display: flex;
  width: 168px;
  gap: 6px;
  margin-top: 8px;
}

#hexColor {
  flex: 1;
  min-width: 0;
  height: 28px;
  padding: 0 7px;
  text-transform: uppercase;
}

.eyedropper-button {
  width: 30px;
  min-width: 30px;
  min-height: 28px;
  padding: 0;
  display: grid;
  place-items: center;
}

.eyedropper-button.mini {
  width: 26px;
  min-width: 26px;
  min-height: 28px;
}

.eyedropper-button.active {
  border-color: var(--accent-2);
  background: #17382d;
}

.eyedropper-icon {
  position: relative;
  width: 16px;
  height: 16px;
  transform: rotate(-45deg);
}

.eyedropper-icon::before,
.eyedropper-icon::after {
  content: "";
  position: absolute;
  display: block;
}

.eyedropper-icon::before {
  left: 5px;
  top: 0;
  width: 5px;
  height: 13px;
  border: 2px solid #ededed;
  border-radius: 5px 5px 2px 2px;
  background: #262626;
}

.eyedropper-icon::after {
  left: 6px;
  top: 12px;
  width: 10px;
  height: 3px;
  border-radius: 2px;
  background: #ededed;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  margin-top: 8px;
}

.swatches button {
  min-height: 18px;
  height: 18px;
  padding: 0;
  border-radius: 4px;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.48);
  z-index: 10;
}

.dialog {
  width: min(760px, 100%);
  height: min(600px, 100%);
  display: grid;
  grid-template-rows: 38px auto 1fr;
  gap: 10px;
  padding: 12px;
  border: 1px solid #4a4a4a;
  border-radius: 8px;
  background: #242424;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.5);
}

.extend-dialog {
  width: min(940px, 100%);
  height: min(720px, 100%);
  grid-template-rows: 38px 1fr;
}

.dialog-head,
.io-grid {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.io-grid {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.extend-map {
  position: relative;
  min-height: 0;
  overflow: auto;
  border: 1px solid #424242;
  border-radius: 6px;
  background: #181818;
}

.extend-stage {
  position: relative;
  min-width: 100%;
  min-height: 100%;
}

.extend-sheet {
  position: absolute;
  border: 1px solid #86aaa3;
  background-color: #fbfbfb;
  background-image:
    linear-gradient(#bad8d2 1px, transparent 1px),
    linear-gradient(90deg, #bad8d2 1px, transparent 1px),
    linear-gradient(#86aaa3 1px, transparent 1px),
    linear-gradient(90deg, #86aaa3 1px, transparent 1px);
  background-size:
    12px 12px,
    12px 12px,
    48px 48px,
    48px 48px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
}

.extend-add {
  position: absolute;
  width: 28px;
  height: 28px;
  min-height: 28px;
  padding: 0;
  border-color: #777;
  border-radius: 8px;
  background: #f4f4f4;
  color: #141414;
  font-size: 19px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.28);
  z-index: 2;
}

.extend-add:hover {
  border-color: var(--accent-2);
}

.extend-add.top,
.extend-add.bottom {
  transform: translate(-50%, -50%);
}

.extend-add.left,
.extend-add.right {
  transform: translate(-50%, -50%);
}

#codeOutput {
  width: 100%;
  min-height: 0;
  resize: none;
  padding: 10px;
  border: 1px solid #4b4b4b;
  border-radius: 6px;
  background: #171717;
  color: #efefef;
  font-family: "Courier New", monospace;
  font-size: 12px;
  line-height: 1.45;
  outline: none;
}

.text-editor {
  position: fixed;
  z-index: 8;
  min-width: 80px;
  height: 32px;
  padding: 4px 7px;
  border: 1px solid var(--accent-2);
  border-radius: 6px;
  background: #fff;
  color: #111;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

.hidden {
  display: none;
}

@media (max-width: 640px) {
  .app {
    grid-template-columns: 50px 1fr;
    grid-template-rows: 38px 1fr;
  }

  .tools {
    padding-inline: 4px;
  }

  .tool,
  .thin-control,
  .extend-button,
  #fontFamily,
  #fontSize {
    width: 40px;
  }

  .topbar {
    padding-inline: 8px;
    gap: 6px;
  }

  .brand {
    display: none;
  }

  .project-tab {
    min-width: 72px;
    max-width: 112px;
    padding-inline: 7px;
  }

  button {
    padding-inline: 7px;
  }
}
