:root {
  --bg: #e2e5ea;
  --bg-accent: #f0f2f6;
  --panel: rgba(244, 246, 249, 0.98);
  --panel-border: rgba(121, 133, 153, 0.24);
  --sheet: #ffffff;
  --text: #202938;
  --muted: #6a7487;
  --line: #0d1421;
  --primary: #3f7ee7;
  --primary-strong: #2f69d7;
  --success: #4c8f3f;
  --danger: #ea5a5a;
  --shadow-soft: 0 1px 3px rgba(42, 51, 64, 0.06);
  --shadow-sheet: 0 10px 28px rgba(58, 66, 78, 0.1);
  --radius-xl: 14px;
  --radius-lg: 12px;
  --radius-md: 8px;
  --radius-sm: 5px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #e9ebef 0%, #dde1e7 100%);
}

button,
input,
select {
  font: inherit;
}

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

.sidebar {
  padding: 16px 16px 18px;
  border-right: 1px solid rgba(126, 136, 151, 0.26);
  background: linear-gradient(180deg, rgba(248, 249, 251, 0.96), rgba(244, 246, 249, 0.96));
  overflow-y: auto;
}

.brand-block {
  padding: 4px 2px 10px;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.86rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
}

.brand-block h1 {
  margin: 0;
  font-size: clamp(2.3rem, 3vw, 2.85rem);
  line-height: 0.96;
  color: var(--primary);
}

.intro {
  margin: 8px 0 0;
  max-width: 28ch;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.panel-card {
  margin-top: 12px;
  padding: 12px 13px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow-soft);
}

.field-label,
.section-head h2 {
  margin: 0 0 9px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #687286;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}

.section-head span,
.muted {
  color: var(--muted);
  font-size: 0.74rem;
}

input[type="text"],
select {
  width: 100%;
  border: 1px solid rgba(122, 138, 163, 0.34);
  border-radius: var(--radius-md);
  background: #fff;
  padding: 9px 12px;
  font-size: 0.92rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

input[type="text"]:focus,
select:focus {
  border-color: rgba(61, 124, 236, 0.55);
  box-shadow: 0 0 0 4px rgba(61, 124, 236, 0.12);
}

.upload-card {
  display: block;
  cursor: pointer;
}

.upload-card + .upload-card {
  margin-top: 8px;
}

.asset-adjustments + .upload-card {
  margin-top: 10px;
}

.asset-adjustments {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.offset-control {
  padding: 8px 10px;
  border: 1px solid rgba(122, 138, 163, 0.2);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.56);
}

.offset-control .control-row {
  align-items: baseline;
  gap: 10px;
}

.offset-control label {
  font-size: 0.78rem;
  font-weight: 700;
  color: #5c6678;
}

.offset-control strong {
  font-size: 0.8rem;
  color: var(--muted);
}

.upload-preview {
  position: relative;
  min-height: 78px;
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1px dashed rgba(97, 122, 162, 0.38);
  background: rgba(255, 255, 255, 0.9);
  display: grid;
  place-items: center;
  text-align: center;
  overflow: hidden;
  transition: border-color 0.18s ease, background 0.18s ease;
}

.upload-preview-image,
.maze-icon-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: translate(var(--asset-shift-x, 0%), var(--asset-shift-y, 0%))
    scale(var(--asset-scale, 1));
  transform-origin: center;
}

.upload-card:hover .upload-preview {
  border-color: rgba(61, 124, 236, 0.45);
  background: rgba(246, 249, 255, 0.96);
}

.upload-preview p {
  margin: 4px 0 2px;
  font-size: 0.9rem;
  font-weight: 700;
}

.upload-preview small {
  color: var(--muted);
  font-size: 0.74rem;
}

.upload-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fff;
}

.upload-badge.start {
  background: #4b84e8;
}

.upload-badge.finish {
  background: #5d9a4d;
}

.upload-preview.has-image {
  border-style: solid;
}

.upload-preview.has-image::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(10, 15, 23, 0.05), rgba(10, 15, 23, 0.38));
}

.upload-preview.has-image p,
.upload-preview.has-image small,
.upload-preview.has-image .upload-badge {
  position: relative;
  z-index: 1;
}

.upload-preview.has-image p,
.upload-preview.has-image small {
  color: #fff;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

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

.segment {
  border: 1px solid rgba(122, 138, 163, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  color: #4c5668;
  padding: 8px 6px;
  font-size: 0.88rem;
  font-weight: 800;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.segment:hover,
.toolbar-btn:hover,
.btn:hover {
  filter: brightness(0.98);
}

.segment.active {
  background: #3f7ee7;
  color: #fff;
  border-color: rgba(47, 105, 215, 0.55);
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.control-row label {
  font-weight: 700;
}

.switch-row {
  align-items: flex-start;
  margin-top: 10px;
}

.switch-row p {
  margin: 3px 0 0;
}

input[type="range"] {
  width: 100%;
  margin-top: 6px;
  accent-color: var(--primary);
}

.switch {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-ui {
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: #ccd5e2;
  position: relative;
  transition: background 0.2s ease;
}

.switch-ui::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(16, 24, 40, 0.16);
  transition: transform 0.2s ease;
}

.switch input:checked + .switch-ui {
  background: rgba(61, 124, 236, 0.5);
}

.switch input:checked + .switch-ui::after {
  transform: translateX(20px);
}

.actions-card {
  display: grid;
  gap: 7px;
}

.btn {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 10px 14px;
  font-weight: 800;
  font-size: 0.94rem;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.btn-primary {
  color: #fff;
  background: var(--success);
  border-color: rgba(63, 126, 49, 0.5);
}

.btn-secondary {
  color: #233044;
  background: rgba(255, 255, 255, 0.92);
  border-color: rgba(122, 138, 163, 0.28);
}

.workspace {
  padding: 16px clamp(10px, 2vw, 24px) 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  overflow: auto;
}

.toolbar {
  position: sticky;
  top: 12px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid rgba(123, 139, 164, 0.24);
  background: rgba(253, 253, 254, 0.96);
  box-shadow: var(--shadow-soft);
}

.toolbar-label,
.toolbar strong {
  font-size: 0.94rem;
  font-weight: 800;
}

.toolbar input[type="range"] {
  width: 144px;
  margin-top: 0;
}

.toolbar-btn {
  width: 32px;
  height: 32px;
  border: 1px solid rgba(123, 139, 164, 0.28);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 1.08rem;
  cursor: pointer;
}

.sheet-stage {
  width: 100%;
  display: grid;
  place-items: start center;
  padding: 4px 0 16px;
}

.sheet {
  width: min(100%, 888px);
  min-height: min(1260px, calc(100vh - 132px));
  padding: 18px 22px 20px;
  border-radius: 6px;
  background: var(--sheet);
  box-shadow: var(--shadow-sheet);
  transform-origin: top center;
  transition: transform 0.18s ease;
}

.sheet-header {
  text-align: center;
}

.sheet-kicker {
  display: none;
}

.sheet h2 {
  margin: 0;
  font-size: clamp(1.7rem, 2.6vw, 2.25rem);
  font-style: italic;
  font-weight: 500;
  color: #c4c8cf;
}

.maze-frame {
  position: relative;
  width: min(100%, 820px);
  margin: 34px auto 0;
  padding: 0;
  border: 0;
  background: transparent;
}

#mazeCanvas {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
}

.maze-icon {
  position: absolute;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(27, 42, 64, 0.1);
  background: #eef2f7;
  overflow: hidden;
  z-index: 8;
}

.maze-icon.has-image span {
  display: none;
}

.maze-icon span {
  position: relative;
  z-index: 1;
  font-size: 0.5rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #647086;
}

.maze-icon-start {
  left: -8px;
  top: 18px;
}

.maze-icon-finish {
  right: -8px;
  bottom: 18px;
}

.sheet-footer {
  display: none;
}

@media (max-width: 980px) and (min-width: 850px) {
  .sidebar {
    padding: 12px;
  }

  .panel-card {
    padding: 10px 11px;
  }

  .workspace {
    padding: 12px 10px 18px;
  }

  .toolbar {
    gap: 8px;
    padding: 7px 9px;
  }

  .toolbar input[type="range"] {
    width: 112px;
  }

  .sheet {
    padding: 16px 14px 18px;
  }
}

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid rgba(123, 139, 164, 0.22);
  }

  .intro {
    max-width: none;
  }
}

@media (max-width: 720px) {
  .sidebar,
  .workspace {
    padding-left: 12px;
    padding-right: 12px;
  }

  .panel-card {
    padding: 12px;
  }

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

  .toolbar {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
  }

  .sheet {
    padding: 16px 12px 18px;
  }

  .maze-icon {
    width: 36px;
    height: 36px;
  }
}
