:root {
  color-scheme: dark;
  --bg: #17191d;
  --panel: #22262b;
  --panel-2: #2b3037;
  --line: #3b424c;
  --text: #f2f4f7;
  --muted: #aab2bf;
  --accent: #18a889;
  --accent-2: #e8b84a;
  --danger: #dc5b5b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior-y: contain;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="color"],
input[type="number"] {
  border: 1px solid var(--line);
  background: #303741;
  color: var(--text);
  border-radius: 6px;
}

button {
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: #657184;
}

button.active,
.tabs button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #081512;
  font-weight: 700;
}

button.primary {
  width: 100%;
  background: #3f82e8;
  border-color: #3f82e8;
  font-weight: 700;
}

#addLatarButton {
  width: 100%;
  margin-top: 8px;
}

.mobile-background-launch {
  display: none;
  width: 100%;
  margin-top: 8px;
  font-weight: 700;
}

button.export {
  background: #1084dc;
  border-color: #1084dc;
  color: #ffffff;
  font-weight: 800;
  min-width: 132px;
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
}

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

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

.app-footer {
  padding: 12px 16px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.pull-refresh-indicator {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  z-index: 120;
  min-width: 148px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(31, 35, 41, 0.94);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -18px);
  transition: opacity 140ms ease, transform 140ms ease;
}

.pull-refresh-indicator.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.pull-refresh-indicator.ready {
  background: #1084dc;
  border-color: #1084dc;
  color: #ffffff;
}

.sidebar {
  background: var(--panel);
  border-color: var(--line);
  overflow: auto;
  padding: 16px;
}

.left-panel {
  border-right: 1px solid var(--line);
}

.right-panel {
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 0;
  overflow: hidden;
}

.right-panel-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 16px;
}

.desktop-export-panel {
  flex: none;
  padding: 16px;
  background: #2b2b2b;
  border-top: 1px solid var(--line);
}

.desktop-export-panel #exportButton {
  width: 100%;
  min-height: 48px;
  background: #1084dc;
  border-color: #1084dc;
  color: #ffffff;
  font-weight: 900;
}

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

.brand-mark {
  width: 48px;
  aspect-ratio: 1;
  border-radius: 8px;
  object-fit: contain;
  background: #f7f8fb;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
}

h2 {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.brand p,
.visually-hidden {
  color: var(--muted);
}

section {
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
}

select,
input[type="range"] {
  width: 100%;
}

select {
  height: 36px;
  padding: 0 10px;
}

input[type="file"] {
  display: none;
}

input[type="color"] {
  width: 48px;
  height: 36px;
  padding: 4px;
}

input[type="number"] {
  height: 34px;
  padding: 0 6px;
}

.segmented,
.tabs,
.control-row,
.button-grid {
  display: grid;
  gap: 8px;
}

.segmented,
.tabs {
  grid-template-columns: 1fr 1fr;
  margin-bottom: 10px;
}

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

.control-row {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
}

.control-row label {
  margin: 0;
  min-width: 112px;
}

.control-row .export {
  min-height: 36px;
  min-width: 132px;
}

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

.thumb {
  min-height: 92px;
  padding: 4px;
  overflow: hidden;
  text-align: left;
  background: var(--panel-2);
}

.thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 4px;
}

.thumb span {
  display: block;
  padding: 5px 2px 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.solid-panel {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 8px;
}

.color-grid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.swatch {
  aspect-ratio: 1;
  min-height: 34px;
  padding: 0;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #1d2025;
}

.history-button {
  min-width: 92px;
  height: 36px;
  min-height: 36px;
  padding: 0 18px;
  font-weight: 800;
}

.mobile-export {
  display: none;
}

.canvas-wrap {
  display: grid;
  place-items: center;
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 16px;
  background: #111317;
  -webkit-touch-callout: none;
  user-select: none;
}

canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  background: #25282d;
  border: 1px solid #333943;
  pointer-events: none;
  touch-action: auto;
  -webkit-touch-callout: none;
  user-select: none;
}

#frameTouchTarget {
  position: absolute;
  z-index: 2;
  display: block;
  background: transparent;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.layer-list {
  display: grid;
  gap: 8px;
}

.layer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.layer-actions #deleteLayer,
.layer-actions #removeBgButton {
  grid-column: 1 / -1;
}

.layer-item {
  display: grid;
  grid-template-columns: 32px 1fr 32px;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.layer-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.layer-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  min-height: 30px;
  padding: 0;
}

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

.mobile-skin-launch {
  display: none;
}

.mobile-skin-launch button {
  width: 100%;
  font-weight: 700;
}

.background-panel-header {
  display: block;
}

#closeBackgroundPanel {
  display: none;
}

.skin-panel-header {
  display: block;
}

#closeSkinPanel {
  display: none;
}

.check-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 700;
}

.check-row input {
  width: 24px;
  height: 24px;
  accent-color: var(--accent);
}

.skin-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.skin-control {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

.skin-control label {
  margin: 0;
  color: var(--text);
  font-weight: 700;
}

.skin-control > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  align-items: center;
  gap: 8px;
}

.skin-control input[type="range"] {
  margin: 0;
}

.value-input {
  width: 58px;
  background: #16181c;
  border-color: #343941;
  font-weight: 700;
}

.skin-panel button:disabled,
.skin-panel input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.hidden {
  display: none;
}

.layer-menu {
  position: fixed;
  z-index: 20;
  min-width: 156px;
  padding: 6px;
  background: #242a32;
  border: 1px solid #566171;
  border-radius: 8px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.42);
}

.layer-menu button {
  display: block;
  width: 100%;
  min-height: 38px;
  border: 0;
  background: transparent;
  text-align: left;
}

.layer-menu button:hover,
.layer-menu button:focus {
  background: #343c47;
}

.layer-menu button:disabled {
  color: #757f8d;
  cursor: default;
}

.export-menu {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: end center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.24);
}

.export-menu.hidden {
  display: none;
}

.export-menu-card {
  display: grid;
  gap: 10px;
  width: min(360px, 100%);
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.48);
}

.export-menu-card h2 {
  margin-bottom: 0;
}

.export-menu-card button {
  width: 100%;
  min-height: 42px;
  font-weight: 800;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(72vh, 1fr) auto;
  }

  .sidebar {
    border: 0;
  }

  .left-panel,
  .right-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 16px;
    height: auto;
    max-height: none;
    overflow: visible;
    padding: 16px;
    position: static;
  }

  .right-panel {
    display: flex;
    flex-direction: column;
    padding-bottom: 0;
  }

  .right-panel-scroll {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 16px;
    padding: 0;
    overflow: visible;
  }

  .desktop-export-panel {
    display: none;
  }

  .skin-panel,
  .background-panel {
    grid-column: 1 / -1;
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 10px;
    z-index: 50;
    max-height: min(42vh, 430px);
    overflow: auto;
    padding: 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 16px 42px rgba(0, 0, 0, 0.48);
    opacity: 0;
    pointer-events: none;
    transform: translateY(calc(100% + 18px));
    transition: transform 180ms ease, opacity 180ms ease;
    -webkit-overflow-scrolling: touch;
  }

  body.skin-panel-open,
  body.background-panel-open {
    overflow: auto;
  }

  body.skin-panel-open .skin-panel {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }

  body.background-panel-open .background-panel {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }

  .mobile-skin-launch {
    display: block;
    grid-column: 1 / -1;
  }

  .mobile-background-launch {
    display: block;
  }

  .skin-panel-header,
  .background-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
    position: sticky;
    top: -12px;
    z-index: 1;
    padding: 0 0 8px;
    background: var(--panel);
  }

  .skin-panel-header h2,
  .background-panel-header h2 {
    margin-bottom: 0;
  }

  #closeSkinPanel,
  #closeBackgroundPanel {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 76px;
    background: var(--accent);
    border-color: var(--accent);
    color: #081512;
    font-weight: 800;
  }

  .skin-panel .check-row {
    margin-bottom: 8px;
  }

  .skin-panel .check-row input {
    width: 22px;
    height: 22px;
  }

  .skin-actions {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 10px;
  }

  .skin-actions button {
    min-height: 34px;
    padding: 0 8px;
    font-size: 13px;
  }

  .skin-control {
    margin-bottom: 9px;
  }

  .skin-control label {
    font-size: 13px;
  }

  .skin-control > div {
    grid-template-columns: minmax(0, 1fr) 48px;
    gap: 6px;
  }

  .value-input {
    width: 48px;
    height: 30px;
    font-size: 13px;
  }

  .brand,
  .photo-panel,
  .project-panel,
  .background-panel {
    grid-column: 1 / -1;
  }

  .brand {
    order: 1;
  }

  .project-panel {
    order: 2;
  }

  .photo-panel {
    order: 3;
  }

  .background-panel {
    order: 4;
  }

  .workspace {
    min-height: 72vh;
  }
}

@media (min-width: 981px) {
  .export-menu {
    place-items: center;
  }
}

@media (max-width: 640px) {
  .app-shell {
    grid-template-rows: none;
    grid-auto-rows: auto;
  }

  .left-panel {
    display: contents;
  }

  .left-panel > .brand,
  .left-panel > section {
    background: var(--panel);
    padding-left: 16px;
    padding-right: 16px;
  }

  .left-panel > .brand {
    margin-bottom: 0;
    padding-top: 16px;
    padding-bottom: 16px;
  }

  .workspace {
    order: 4;
  }

  .right-panel {
    order: 5;
    display: flex;
    flex-direction: column;
  }

  .right-panel-scroll {
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  .background-panel {
    order: 6;
  }

  .topbar {
    align-items: stretch;
  }

  .topbar .export {
    display: none;
  }

  .control-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto auto;
    align-items: end;
    width: 100%;
  }

  .control-row label:first-child {
    min-width: 0;
  }

  .history-button {
    min-width: 64px;
    padding: 0 8px;
  }

  .canvas-wrap {
    padding-bottom: 12px;
  }

  .mobile-export {
    display: block;
    width: calc(100% - 32px);
    min-height: 46px;
    margin: 0 16px 14px;
  }

  .app-footer {
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
    font-size: 12px;
  }

}
