:root {
  --bg: #201d21;
  --panel: #2f2a30;
  --panel-soft: #393139;
  --ink: #fff9f0;
  --muted: #c6b9ad;
  --line: rgba(255, 249, 240, 0.13);
  --accent: #f49b42;
  --accent-strong: #ffb45d;
  --aqua: #3ac7b5;
  --danger: #f06060;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.28);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background:
    linear-gradient(135deg, rgba(244, 155, 66, 0.15), transparent 36%),
    radial-gradient(circle at 82% 12%, rgba(58, 199, 181, 0.15), transparent 24%),
    var(--bg);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(480px, 1fr) 330px;
  gap: 14px;
  min-height: 100vh;
  padding: 14px;
}

.app-shell.is-auth-pending {
  filter: blur(2px);
  pointer-events: none;
  user-select: none;
}

.left-panel,
.right-panel,
.canvas-zone {
  background: rgba(47, 42, 48, 0.92);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.left-panel,
.right-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
  border-radius: 8px;
  padding: 14px;
}

.canvas-zone {
  display: grid;
  grid-template-rows: auto auto 1fr;
  min-width: 0;
  overflow: hidden;
  border-radius: 8px;
}

.brand {
  display: grid;
  grid-template-columns: 46px 1fr;
  align-items: center;
  gap: 12px;
  padding-bottom: 2px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.14) 0 5px, transparent 5px 11px),
    linear-gradient(135deg, #f1783d, #f5bc50);
  color: #3b1d14;
  font-weight: 900;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.15;
}

.brand p,
.status-line,
.empty-state p {
  color: var(--muted);
  font-size: 13px;
}

.panel-section {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 249, 240, 0.035);
}

.section-title {
  color: #ffdfb4;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.text-input,
textarea {
  width: 100%;
  min-width: 0;
  color: var(--ink);
  background: #211d22;
  border: 1px solid rgba(255, 249, 240, 0.16);
  border-radius: 6px;
  outline: 0;
}

.text-input {
  height: 38px;
  padding: 0 10px;
}

.text-input:focus,
textarea:focus {
  border-color: rgba(255, 180, 93, 0.75);
  box-shadow: 0 0 0 3px rgba(244, 155, 66, 0.16);
}

.text-input:disabled {
  opacity: 0.55;
}

#regionTexture:read-only {
  color: rgba(255, 249, 240, 0.72);
}

#regionTexture:read-only:focus {
  border-color: rgba(255, 249, 240, 0.16);
  box-shadow: none;
}

.mono-input,
textarea {
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

.field-row,
.action-row,
.color-row,
.level-control,
.top-bar,
.zoom-controls,
.metric-strip {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field-row > * {
  flex: 1;
}

.level-control .text-input {
  flex: 1;
  text-align: center;
  font-weight: 800;
}

.color-row {
  display: grid;
  grid-template-columns: 48px 1fr;
}

input[type="color"] {
  width: 48px;
  height: 38px;
  padding: 2px;
  border: 1px solid rgba(255, 249, 240, 0.16);
  border-radius: 6px;
  background: #211d22;
}

.file-button,
.tool-button,
.primary-button,
.command-button,
.danger-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
  transition:
    transform 120ms ease,
    border-color 120ms ease,
    background 120ms ease;
}

.file-button:hover,
.tool-button:hover,
.primary-button:hover,
.command-button:hover,
.danger-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.file-button input {
  display: none;
}

.file-button,
.command-button,
.icon-button,
.tool-button {
  background: rgba(255, 249, 240, 0.075);
  border: 1px solid rgba(255, 249, 240, 0.14);
}

.primary-button {
  background: linear-gradient(135deg, #f47c3e, #f6b44c);
  color: #32180f;
  font-weight: 900;
}

.danger-button {
  background: rgba(240, 96, 96, 0.13);
  border: 1px solid rgba(240, 96, 96, 0.35);
  color: #ffd4d4;
}

.icon-button {
  flex: 0 0 auto;
  width: 38px;
  padding: 0;
}

.full-width {
  width: 100%;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.tool-button {
  min-width: 0;
  padding: 0 10px;
}

.tool-button.is-active {
  background: rgba(58, 199, 181, 0.17);
  border-color: rgba(58, 199, 181, 0.65);
  color: #c9fff7;
}

.tool-button[data-tool="region"].is-active {
  background: rgba(255, 79, 216, 0.16);
  border-color: rgba(255, 79, 216, 0.72);
  color: #ffd6f6;
  box-shadow: inset 0 0 0 1px rgba(255, 79, 216, 0.24);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  transform: none;
}

svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.2;
}

.top-bar {
  justify-content: space-between;
  min-height: 56px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(32, 29, 33, 0.48);
}

.metric-strip {
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}

.metric-strip span {
  padding: 6px 9px;
  border-radius: 999px;
  background: rgba(255, 249, 240, 0.07);
}

.metric-strip .mode-badge {
  min-width: 106px;
  border: 1px solid rgba(58, 199, 181, 0.45);
  background: rgba(58, 199, 181, 0.13);
  color: #c9fff7;
  text-align: center;
}

.metric-strip .mode-badge.is-region {
  border-color: rgba(255, 79, 216, 0.62);
  background: rgba(255, 79, 216, 0.14);
  color: #ffd6f6;
}

.metric-strip strong {
  color: var(--ink);
}

.warning-stack {
  display: grid;
}

.geometry-warning {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid rgba(240, 96, 96, 0.48);
  background: linear-gradient(135deg, rgba(113, 28, 34, 0.96), rgba(74, 24, 33, 0.96));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.geometry-warning[hidden] {
  display: none;
}

.geometry-warning-main {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: start;
  gap: 10px;
}

.geometry-warning-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: rgba(255, 249, 240, 0.12);
  color: #fff4c2;
}

.geometry-warning-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.geometry-warning strong {
  display: block;
  color: #fff9f0;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.geometry-warning p {
  margin-top: 3px;
  color: #ffe0df;
  font-size: 13px;
  line-height: 1.4;
}

.geometry-warning-list {
  display: grid;
  gap: 6px;
  max-height: 118px;
  overflow: auto;
}

.geometry-warning-item {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid rgba(255, 249, 240, 0.18);
  border-radius: 6px;
  background: rgba(255, 249, 240, 0.075);
  color: #fff9f0;
  cursor: pointer;
  font-size: 12px;
  line-height: 1.35;
  text-align: left;
}

.geometry-warning-item:hover {
  background: rgba(255, 249, 240, 0.13);
}

.geometry-warning-more {
  color: #ffd0cf;
  font-size: 12px;
  line-height: 1.35;
}

.geometry-warning.is-soft {
  border-bottom-color: rgba(244, 155, 66, 0.42);
  background: linear-gradient(135deg, rgba(88, 56, 24, 0.96), rgba(57, 44, 32, 0.96));
}

.geometry-warning.is-soft .geometry-warning-icon {
  color: #ffe7b3;
}

.geometry-warning.is-soft p {
  color: #ffe8ca;
}

.geometry-warning.is-soft .geometry-warning-item {
  border-color: rgba(255, 231, 179, 0.18);
  background: rgba(255, 231, 179, 0.075);
}

.geometry-warning.is-soft .geometry-warning-item:hover {
  background: rgba(255, 231, 179, 0.13);
}

.geometry-warning.is-soft .geometry-warning-more {
  color: #ffe0ad;
}

.geometry-warning-dismiss {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid rgba(255, 249, 240, 0.16);
  border-radius: 6px;
  background: rgba(255, 249, 240, 0.075);
  color: #fff4c2;
  cursor: pointer;
}

.geometry-warning-dismiss:hover {
  background: rgba(255, 249, 240, 0.14);
}

#zoomLabel {
  min-width: 52px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.035) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.035) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.035) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.035) 75%),
    #1d1a1e;
  background-size: 28px 28px;
  background-position:
    0 0,
    0 14px,
    14px -14px,
    -14px 0;
}

#editorCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
}

#editorCanvas.is-tool-select {
  cursor: grab;
}

#editorCanvas.is-tool-select:active {
  cursor: grabbing;
}

#editorCanvas.is-tool-region {
  cursor: crosshair;
}

.canvas-wrap.is-region-mode {
  outline: 2px solid rgba(255, 79, 216, 0.48);
  outline-offset: -2px;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  padding: 28px;
  text-align: center;
  pointer-events: none;
  color: var(--muted);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  color: #ffbc6b;
}

.empty-state h2 {
  color: var(--ink);
  font-size: clamp(22px, 4vw, 36px);
}

.list-stack {
  display: grid;
  gap: 8px;
  max-height: 270px;
  overflow: auto;
}

.list-item {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 9px;
  padding: 9px;
  border: 1px solid rgba(255, 249, 240, 0.12);
  border-radius: 8px;
  background: rgba(255, 249, 240, 0.045);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.list-item.is-selected {
  border-color: rgba(255, 180, 93, 0.72);
  background: rgba(244, 155, 66, 0.14);
}

.swatch {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.34);
}

.item-copy {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 4px;
}

.item-title {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 800;
}

.item-meta {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.compact-list .list-item {
  grid-template-columns: 1fr auto;
}

textarea {
  min-height: 250px;
  resize: vertical;
  padding: 10px;
  color: #d9f7ec;
  font-size: 11px;
  line-height: 1.45;
}

.status-line {
  min-height: 18px;
}

.auth-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.auth-status span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(20, 17, 21, 0.78);
  backdrop-filter: blur(10px);
}

.auth-gate[hidden] {
  display: none;
}

.auth-card {
  display: grid;
  gap: 10px;
  width: min(390px, 100%);
  padding: 18px;
  border: 1px solid rgba(255, 249, 240, 0.14);
  border-radius: 8px;
  background: #252026;
  box-shadow: var(--shadow);
}

.compact-brand {
  margin-bottom: 4px;
}

.auth-error {
  min-height: 18px;
  color: #ffd4d4;
  font-size: 13px;
  line-height: 1.4;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 5;
  max-width: min(520px, calc(100vw - 28px));
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(20, 18, 21, 0.94);
  border: 1px solid rgba(255, 249, 240, 0.15);
  color: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(14, 11, 15, 0.68);
  backdrop-filter: blur(8px);
}

.dialog-backdrop[hidden] {
  display: none;
}

.dialog {
  width: min(420px, 100%);
  padding: 18px;
  border: 1px solid rgba(255, 249, 240, 0.14);
  border-radius: 8px;
  background: #211b23;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

.dialog h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.dialog p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.busy-backdrop {
  z-index: 40;
  cursor: wait;
}

.busy-dialog {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 14px;
}

.busy-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255, 249, 240, 0.2);
  border-top-color: var(--accent-strong);
  border-radius: 50%;
  animation: busy-spin 850ms linear infinite;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

@keyframes busy-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1160px) {
  .app-shell {
    grid-template-columns: 280px 1fr;
  }

  .right-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 8px;
  }

  .canvas-zone {
    min-height: 68vh;
  }

  .right-panel {
    grid-template-columns: 1fr;
  }

  .top-bar {
    align-items: stretch;
    flex-direction: column;
  }
}
