:root {
  color-scheme: light;
  --bg: #f6f4f1;
  --panel: #ffffff;
  --text: #1e272e;
  --muted: #64707a;
  --line: #d8dde0;
  --accent: #c9362c;
  --accent-strong: #8e211b;
  --blue: #1f5d8f;
  --green: #197a4a;
  --shadow: 0 18px 48px rgba(22, 30, 38, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button,
.file-button {
  min-height: 42px;
  padding: 0 14px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

button:hover,
.file-button:hover,
select:hover,
input:hover {
  border-color: var(--text);
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 4px solid rgba(31, 93, 143, 0.28);
  outline-offset: 2px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px clamp(18px, 4vw, 48px);
  background: rgba(246, 244, 241, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

h1,
h2,
p {
  margin-top: 0;
}

h1,
h2 {
  line-height: 1.1;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.55rem, 3vw, 2.4rem);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-strong);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

nav {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
}

nav a {
  min-width: 94px;
  padding: 9px 14px;
  color: var(--muted);
  text-align: center;
  text-decoration: none;
  border-radius: 999px;
}

nav a.active {
  color: #ffffff;
  background: var(--text);
}

main {
  width: min(1560px, 100%);
  margin: 0 auto;
  padding: 30px clamp(16px, 4vw, 48px) 56px;
}

.intro {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.intro h2 {
  margin-bottom: 8px;
  font-size: clamp(1.35rem, 2.2vw, 2rem);
}

.intro p {
  max-width: 820px;
  margin-bottom: 0;
  color: var(--muted);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

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

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.device-panel,
.editor-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.device-panel {
  position: sticky;
  top: 104px;
  max-height: calc(100vh - 126px);
  overflow: hidden;
}

.panel-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2 {
  margin: 0;
  font-size: 1.15rem;
}

.panel-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  white-space: nowrap;
}

.search-label,
.field-group label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-weight: 800;
}

.search-label {
  padding: 16px 18px 0;
}

#deviceSearch {
  width: calc(100% - 36px);
  min-height: 42px;
  margin: 0 18px 14px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.device-list {
  display: grid;
  gap: 6px;
  max-height: calc(100vh - 276px);
  margin: 0;
  padding: 0 12px 16px;
  overflow: auto;
  list-style: none;
}

.device-list button {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  text-align: left;
}

.device-list button.active {
  color: #ffffff;
  background: var(--text);
  border-color: var(--text);
}

.device-list button.done:not(.active) {
  border-color: rgba(25, 122, 74, 0.45);
}

.status-dot {
  width: 10px;
  height: 10px;
  margin-top: 7px;
  background: var(--line);
  border-radius: 999px;
}

.done .status-dot {
  background: var(--green);
}

.editor-panel {
  padding-bottom: 18px;
}

.danger-button {
  color: var(--accent-strong);
}

.field-group {
  padding: 18px 18px 0;
}

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

.area-grid button.active {
  color: #ffffff;
  background: var(--blue);
  border-color: var(--blue);
}

select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.image-shell {
  padding: 18px;
}

.image-stage {
  position: relative;
  display: grid;
  min-height: 420px;
  overflow: hidden;
  place-items: center;
  background: #151b21;
  border: 1px solid var(--line);
  border-radius: 8px;
  user-select: none;
  touch-action: none;
}

.image-stage img {
  display: none;
  width: 100%;
  height: auto;
}

.image-stage.has-image {
  display: block;
  min-height: 0;
  cursor: crosshair;
}

.image-stage.has-image img {
  display: block;
}

.empty-state {
  padding: 24px;
  color: #dce2e6;
  text-align: center;
}

.image-stage.has-image .empty-state {
  display: none;
}

.selection-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.selection-overlay polygon {
  fill: rgba(255, 212, 77, 0.18);
  stroke: #ffd44d;
  stroke-width: 0.45;
  vector-effect: non-scaling-stroke;
}

.selection-overlay polyline {
  fill: none;
  stroke: #ffd44d;
  stroke-dasharray: 1.4 1;
  stroke-width: 0.45;
  vector-effect: non-scaling-stroke;
}

.corner-handles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.corner-handle {
  position: absolute;
  display: grid;
  width: 28px;
  height: 28px;
  padding: 0;
  place-items: center;
  color: #111820;
  font-size: 0.78rem;
  font-weight: 900;
  background: #ffd44d;
  border: 2px solid #ffffff;
  border-radius: 999px;
  cursor: grab;
  pointer-events: auto;
  transform: translate(-50%, -50%);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.36);
}

.corner-handle:active {
  cursor: grabbing;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 0 18px;
}

.info-grid div {
  min-height: 76px;
  padding: 12px;
  background: #f8fafb;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.info-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.info-grid strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
}

@media (max-width: 1100px) {
  .intro,
  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .action-row {
    justify-content: flex-start;
  }

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

  .device-panel {
    position: static;
    max-height: none;
  }

  .device-list {
    max-height: 320px;
  }

  .area-grid,
  .info-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  nav {
    align-self: flex-start;
  }

  .area-grid,
  .info-grid {
    grid-template-columns: 1fr;
  }

  .image-stage {
    min-height: 300px;
  }
}
