:root {
  color-scheme: light;
  --bg: #f3f5f2;
  --surface: #ffffff;
  --surface-soft: #eef2ee;
  --ink: #1b201e;
  --muted: #67736e;
  --line: #d9dfdb;
  --line-strong: #b9c4be;
  --accent: #08796f;
  --accent-soft: #e5f4f0;
  --gold: #d09a27;
  --danger: #c44f42;
  --shadow: 0 12px 34px rgba(28, 39, 34, 0.09);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
select,
input {
  font: inherit;
}

button,
.secondary-upload,
.drop-zone {
  cursor: pointer;
}

button,
select,
.secondary-upload,
.url-import input {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
}

button {
  padding: 0 13px;
}

button:hover,
.secondary-upload:hover,
.drop-zone:hover {
  border-color: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
.drop-zone:focus-within,
.secondary-upload:focus-within {
  outline: 3px solid rgba(208, 154, 39, 0.42);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: 28px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: #fafbf9;
  padding: 22px;
}

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

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  font-size: 14px;
  font-weight: 800;
}

.brand h1,
.brand p,
.section-heading h2,
.pet-title h2,
.pet-title p,
.panel-heading h2,
.panel-heading p,
.atlas-heading h2,
.atlas-heading p {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.15;
}

.brand p,
.drop-zone small,
.section-heading span,
.sidebar-footer,
.pet-title > p:last-child,
.frame-readout,
.meta-grid,
.status-list,
.pet-card p,
.atlas-heading > span {
  color: var(--muted);
}

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

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 11px;
}

.section-heading h2 {
  font-size: 13px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.section-heading span {
  font-size: 12px;
}

.pet-list {
  display: grid;
  gap: 7px;
}

.pet-card {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
  padding: 7px;
  text-align: left;
}

.pet-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 2px rgba(8, 121, 111, 0.1);
}

.pet-thumb {
  width: 46px;
  height: 50px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background-color: white;
  background-repeat: no-repeat;
}

.pet-card strong,
.pet-card p {
  display: block;
  overflow: hidden;
  margin: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pet-card strong {
  font-size: 14px;
}

.pet-card p {
  margin-top: 2px;
  font-size: 12px;
}

.import-panel {
  display: grid;
  gap: 9px;
}

.drop-zone {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 72px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
}

.drop-zone.dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drop-zone input,
.secondary-upload input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.drop-zone strong,
.drop-zone small {
  display: block;
}

.drop-zone strong {
  font-size: 13px;
}

.drop-zone small {
  margin-top: 2px;
  font-size: 11px;
}

.drop-icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--accent);
  font-size: 22px;
  line-height: 1;
}

.secondary-upload {
  display: grid;
  place-items: center;
  padding: 0 12px;
  font-size: 13px;
}

.url-import {
  display: grid;
  gap: 6px;
  margin-top: 5px;
}

.url-import label {
  color: var(--muted);
  font-size: 12px;
}

.url-import div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  gap: 7px;
}

.url-import input {
  min-width: 0;
  padding: 0 9px;
  font-size: 12px;
}

.url-import button {
  padding: 0 8px;
  font-size: 12px;
}

.sidebar-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 11px;
}

.workspace {
  display: flex;
  min-width: 0;
  max-width: 1560px;
  width: 100%;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
}

.pet-header {
  display: flex;
  min-height: 84px;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 3px 2px;
}

.pet-title {
  min-width: 0;
}

.eyebrow,
.panel-kicker {
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pet-title h2 {
  margin-top: 3px;
  font-size: 30px;
  line-height: 1.1;
}

.pet-title > p:last-child {
  max-width: 720px;
  margin-top: 7px;
  line-height: 1.45;
}

.pet-header-side {
  display: grid;
  flex: 0 0 auto;
  justify-items: end;
  gap: 10px;
}

.header-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.language-switch {
  display: grid;
  grid-template-columns: 48px 38px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.language-option {
  min-height: 32px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  padding: 0 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.language-option:last-child {
  border-right: 0;
}

.language-option.active {
  background: var(--accent-soft);
  color: #075f58;
}

.github-star-link {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  padding: 0 10px;
  color: var(--ink);
  text-decoration: none;
  font-size: 11px;
  font-weight: 700;
}

.github-star-link:hover {
  border-color: var(--accent);
}

.github-star-link:focus-visible {
  outline: 3px solid rgba(208, 154, 39, 0.42);
  outline-offset: 2px;
}

.star-icon {
  color: var(--gold);
  font-size: 17px;
  line-height: 1;
}

.pet-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.badge {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.badge.ok {
  border-color: rgba(8, 121, 111, 0.34);
  background: var(--accent-soft);
  color: #075f58;
}

.viewer-grid {
  display: grid;
  grid-template-columns: minmax(490px, 1fr) 340px;
  gap: 18px;
  min-width: 0;
}

.preview-panel,
.control-panel,
.atlas-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.preview-panel {
  display: grid;
  min-width: 0;
  gap: 14px;
  align-content: start;
  padding: 16px;
}

.panel-heading,
.atlas-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.panel-heading h2,
.atlas-heading h2 {
  margin-top: 3px;
  font-size: 18px;
  line-height: 1.2;
}

.frame-readout,
.atlas-heading > span {
  flex: 0 0 auto;
  font-size: 12px;
}

.preview-stage {
  position: relative;
  display: grid;
  min-height: 500px;
  place-items: center;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background-color: #f7f9f6;
  cursor: crosshair;
}

#previewCanvas {
  display: block;
  width: 384px;
  max-width: calc(100% - 24px);
  height: auto;
  image-rendering: auto;
}

.mouse-reticle {
  position: absolute;
  left: 50%;
  top: 50%;
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--danger);
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.8);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.preview-stage.mouse-active .mouse-reticle {
  display: block;
}

.direction-readout {
  position: absolute;
  right: 12px;
  bottom: 12px;
  min-height: 27px;
  border: 1px solid rgba(27, 32, 30, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  padding: 5px 9px;
  color: var(--muted);
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.preview-stage.mouse-active .direction-readout {
  opacity: 1;
}

.checker {
  background-image:
    linear-gradient(45deg, rgba(43, 55, 49, 0.07) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(43, 55, 49, 0.07) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(43, 55, 49, 0.07) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(43, 55, 49, 0.07) 75%);
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

.frame-strip {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 7px;
}

.frame-button {
  display: grid;
  min-width: 0;
  height: 60px;
  place-items: center;
  overflow: hidden;
  padding: 0;
}

.frame-button.active {
  border-color: var(--danger);
  box-shadow: 0 0 0 2px rgba(196, 79, 66, 0.13);
}

.frame-button canvas {
  width: 43px;
  height: 47px;
}

.control-panel {
  align-self: start;
  overflow: hidden;
}

.control-section {
  padding: 15px;
  border-bottom: 1px solid var(--line);
}

.control-section:last-child {
  border-bottom: 0;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.action-button {
  display: grid;
  min-width: 0;
  height: 52px;
  place-items: center;
  gap: 2px;
  padding: 5px;
}

.action-button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(8, 121, 111, 0.13);
}

.action-button strong {
  overflow: hidden;
  max-width: 100%;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.action-button span {
  color: var(--muted);
  font-size: 10px;
}

.compact-button {
  min-height: 30px;
  padding: 0 9px;
  font-size: 11px;
}

.range-control,
.select-control {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 8px;
}

.range-control + .select-control {
  margin-top: 11px;
}

.range-control span,
.range-control output,
.select-control span {
  color: var(--muted);
  font-size: 12px;
}

.range-control output {
  text-align: right;
}

input[type="range"] {
  width: 100%;
  min-width: 0;
  accent-color: var(--accent);
}

.select-control {
  grid-template-columns: 48px minmax(0, 1fr);
}

select {
  min-width: 0;
  width: 100%;
  padding: 0 30px 0 10px;
  font-size: 12px;
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
  margin: 0;
}

.meta-grid div {
  min-width: 0;
}

.meta-grid dt {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.meta-grid dd {
  overflow: hidden;
  margin: 3px 0 0;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 700;
}

.status-list {
  display: grid;
  gap: 7px;
  margin-top: 15px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 11px;
}

.status-item {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  line-height: 1.35;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  margin-top: 3px;
  border-radius: 50%;
  background: var(--accent);
}

.status-item.warn .status-dot {
  background: var(--gold);
}

.status-item.fail .status-dot {
  background: var(--danger);
}

.atlas-section {
  min-width: 0;
  padding: 16px;
}

.atlas-heading {
  margin-bottom: 13px;
}

.atlas-scroll {
  max-height: 62vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8faf7;
}

.atlas-grid {
  min-width: 870px;
}

.atlas-row {
  display: grid;
  grid-template-columns: 142px repeat(8, 86px);
  min-width: 830px;
  border-bottom: 1px solid var(--line);
}

.atlas-row:last-child {
  border-bottom: 0;
}

.atlas-row-label {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  padding: 10px 12px;
  border-right: 1px solid var(--line);
  background: #f0f3ef;
}

.atlas-row-label strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.atlas-row-label span {
  color: var(--muted);
  font-size: 10px;
}

.atlas-cell {
  position: relative;
  display: grid;
  width: 86px;
  height: 94px;
  min-height: 94px;
  place-items: center;
  overflow: hidden;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background-color: white;
  padding: 0;
}

.atlas-cell:last-child {
  border-right: 0;
}

.atlas-cell::after {
  position: absolute;
  top: 4px;
  left: 5px;
  color: rgba(27, 32, 30, 0.48);
  content: attr(data-frame);
  font-size: 9px;
}

.atlas-cell.empty::before {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(45deg, rgba(40, 52, 46, 0.05) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(40, 52, 46, 0.05) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(40, 52, 46, 0.05) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(40, 52, 46, 0.05) 75%);
  background-position:
    0 0,
    0 8px,
    8px -8px,
    -8px 0;
  background-size: 16px 16px;
  content: "";
}

.atlas-grid.plain .atlas-cell.empty::before {
  display: none;
}

.atlas-cell canvas {
  position: relative;
  z-index: 1;
  width: 72px;
  height: 78px;
}

@media (max-width: 1200px) {
  .app-shell {
    grid-template-columns: 250px minmax(0, 1fr);
  }

  .viewer-grid {
    grid-template-columns: 1fr;
  }

  .control-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .control-section {
    border-right: 1px solid var(--line);
  }

  .control-section:nth-child(2n) {
    border-right: 0;
  }
}

@media (max-width: 800px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .pet-list {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }

  .import-panel {
    grid-template-columns: 1fr 1fr;
  }

  .import-panel .section-heading,
  .url-import {
    grid-column: 1 / -1;
  }

  .sidebar-footer {
    display: none;
  }

  .workspace {
    order: -1;
    padding: 18px;
  }
}

@media (max-width: 580px) {
  .sidebar,
  .workspace {
    padding: 14px;
  }

  .sidebar {
    gap: 22px;
  }

  .import-panel,
  .control-panel {
    grid-template-columns: 1fr;
  }

  .import-panel .section-heading,
  .url-import {
    grid-column: auto;
  }

  .control-section {
    border-right: 0;
  }

  .pet-header {
    min-height: 0;
    flex-direction: column;
    gap: 14px;
  }

  .pet-title h2 {
    font-size: 25px;
  }

  .pet-header-side {
    width: 100%;
    justify-items: start;
  }

  .header-tools {
    width: 100%;
    justify-content: flex-start;
  }

  .pet-badges {
    justify-content: flex-start;
  }

  .preview-panel,
  .atlas-section {
    padding: 12px;
  }

  .preview-stage {
    min-height: 370px;
  }

  .frame-strip {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

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

  .meta-grid {
    grid-template-columns: 1fr 1fr;
  }

  .url-import div {
    grid-template-columns: 1fr;
  }
}
