:root {
  color-scheme: light;
  --bg: #eef2f4;
  --surface: #ffffff;
  --surface-soft: #f7f9fa;
  --surface-strong: #edf6f6;
  --text: #172024;
  --muted: #647176;
  --faint: #8a989e;
  --border: #d9e1e4;
  --border-strong: #b9c8cc;
  --accent: #087d84;
  --accent-strong: #05636a;
  --accent-soft: #dff5f4;
  --amber: #c57b10;
  --danger: #b23b3b;
  --shadow: 0 20px 50px rgba(23, 32, 36, 0.12);
  --radius: 8px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.74), rgba(238, 242, 244, 0.86)),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 0 auto 14px;
  max-width: 1680px;
  min-height: 72px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 1px solid rgba(8, 125, 132, 0.22);
  border-radius: 8px;
  background: linear-gradient(135deg, #e8fbf9, #ffffff);
  color: var(--accent);
  box-shadow: 0 10px 28px rgba(8, 125, 132, 0.12);
}

.brand-mark svg,
.icon svg,
.icon-button svg,
.drop-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.brand-mark svg {
  fill: currentColor;
  stroke: none;
  width: 24px;
  height: 24px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 21px;
  line-height: 1.15;
  font-weight: 760;
  letter-spacing: 0;
}

.brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.topbar-actions,
.toolbar-controls,
.output-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.button,
.seg-button,
.tab-button,
.icon-button {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.16s ease, background-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 13px;
  font-size: 13px;
  font-weight: 680;
  text-decoration: none;
}

.button:hover,
.seg-button:hover,
.tab-button:hover,
.icon-button:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.button-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.button-primary:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.button-secondary {
  background: rgba(255, 255, 255, 0.88);
}

.button.compact {
  min-height: 32px;
  margin-left: auto;
  padding: 0 10px;
}

.icon {
  display: inline-grid;
  place-items: center;
}

.icon svg {
  width: 17px;
  height: 17px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(250px, 300px) minmax(420px, 1fr) minmax(260px, 320px);
  grid-template-rows: minmax(520px, calc(100vh - 260px)) minmax(220px, 28vh);
  gap: 14px;
  max-width: 1680px;
  margin: 0 auto;
}

.panel,
.canvas-panel {
  min-width: 0;
  border: 1px solid rgba(217, 225, 228, 0.92);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.asset-panel,
.settings-panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
}

.canvas-panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

.output-panel {
  grid-column: 1 / -1;
  min-height: 0;
  overflow: hidden;
}

.panel-heading,
.canvas-toolbar,
.output-tabs {
  border-bottom: 1px solid var(--border);
  background: rgba(247, 249, 250, 0.78);
}

.panel-heading,
.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 13px 14px;
}

.panel-heading h2,
.canvas-toolbar h2 {
  font-size: 14px;
  line-height: 1.2;
  font-weight: 760;
}

.panel-heading span,
.canvas-toolbar span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.icon-button {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  color: var(--muted);
}

.icon-button svg {
  width: 17px;
  height: 17px;
}

.dropzone {
  display: grid;
  margin: 14px;
  min-height: 134px;
  place-items: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #ffffff, #f3fbfb);
  color: var(--muted);
  text-align: center;
  padding: 18px;
}

.dropzone.is-dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.drop-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  margin-bottom: 8px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
}

.dropzone strong {
  color: var(--text);
  font-size: 14px;
}

.dropzone span:last-child {
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.45;
}

.asset-list {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  padding: 0 14px 14px;
}

.asset-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #ffffff;
  padding: 8px;
}

.asset-row.is-selected {
  border-color: rgba(8, 125, 132, 0.54);
  background: var(--accent-soft);
}

.asset-thumb {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #dce4e7 25%, transparent 25%),
    linear-gradient(-45deg, #dce4e7 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #dce4e7 75%),
    linear-gradient(-45deg, transparent 75%, #dce4e7 75%);
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
  background-size: 12px 12px;
}

.asset-thumb img {
  max-width: 32px;
  max-height: 32px;
}

.asset-meta {
  min-width: 0;
}

.asset-meta strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-meta span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.asset-actions {
  display: flex;
  gap: 4px;
}

.asset-actions button {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.asset-actions button:hover {
  border-color: var(--border);
  background: #ffffff;
  color: var(--text);
}

.asset-actions svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.seg-button,
.tab-button {
  min-height: 32px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 680;
}

.seg-button.is-active,
.tab-button.is-active {
  border-color: rgba(8, 125, 132, 0.45);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.preview-stage {
  display: grid;
  min-height: 0;
  flex: 1;
  overflow: auto;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at top left, rgba(8, 125, 132, 0.08), transparent 34%),
    #f7fafb;
}

.canvas-frame {
  width: max-content;
  max-width: none;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background-color: #ffffff;
  background-image:
    linear-gradient(45deg, #dce4e7 25%, transparent 25%),
    linear-gradient(-45deg, #dce4e7 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #dce4e7 75%),
    linear-gradient(-45deg, transparent 75%, #dce4e7 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
  box-shadow: 0 14px 34px rgba(23, 32, 36, 0.16);
  transform-origin: center;
}

.canvas-frame:not(.has-grid) {
  background-image: none;
}

canvas {
  display: block;
  image-rendering: auto;
}

.settings-form {
  display: grid;
  gap: 12px;
  overflow: auto;
  padding: 14px;
}

.settings-form label,
.settings-form fieldset {
  display: grid;
  gap: 7px;
  margin: 0;
  border: 0;
  padding: 0;
}

.settings-form span,
.settings-form legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.settings-form input,
.settings-form select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #ffffff;
  color: var(--text);
  padding: 0 10px;
  font-size: 13px;
}

.settings-form input:focus,
.settings-form select:focus {
  outline: 2px solid rgba(8, 125, 132, 0.22);
  border-color: var(--accent);
}

.check-row {
  display: flex !important;
  align-items: center;
  grid-template-columns: auto 1fr;
}

.check-row input {
  width: 16px;
  min-height: 16px;
}

.selected-card {
  margin: auto 14px 14px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-soft);
  padding: 12px;
}

.selected-card span,
.selected-card small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.selected-card strong {
  display: block;
  margin: 5px 0;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.output-tabs {
  min-height: 48px;
  padding: 8px;
}

.code-output,
.coordinate-wrap {
  height: calc(100% - 48px);
  margin: 0;
  overflow: auto;
  background: #10181b;
  color: #d7f2ee;
}

.code-output {
  padding: 16px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.62;
}

.coordinate-wrap {
  background: #ffffff;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

td:first-child {
  color: var(--accent-strong);
  font-family: var(--mono);
}

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

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: min(360px, calc(100vw - 36px));
  border: 1px solid rgba(8, 125, 132, 0.26);
  border-radius: 7px;
  background: #ffffff;
  box-shadow: var(--shadow);
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  padding: 12px 14px;
  font-size: 13px;
}

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

@media (max-width: 1160px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: minmax(260px, 330px) minmax(0, 1fr);
    grid-template-rows: auto minmax(480px, 64vh) auto auto;
  }

  .settings-panel {
    grid-column: 1 / -1;
  }

  .settings-form {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .selected-card {
    margin-top: 0;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 10px;
  }

  .brand {
    align-items: flex-start;
  }

  .brand p {
    font-size: 12px;
  }

  .topbar-actions .button {
    flex: 1 1 calc(50% - 8px);
  }

  .workspace {
    display: flex;
    flex-direction: column;
  }

  .asset-panel,
  .settings-panel,
  .canvas-panel,
  .output-panel {
    min-height: auto;
  }

  .asset-list {
    max-height: 330px;
  }

  .canvas-panel {
    height: 520px;
  }

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

  .preview-stage {
    padding: 18px;
  }

  .settings-form {
    grid-template-columns: 1fr;
  }

  .output-panel {
    height: 360px;
  }
}
