* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  border-radius: 0;
  transition: none;
  animation: none;
}

[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: Helvetica, Arial, sans-serif;
  background: #fff;
  color: #000;
  font-size: 12px;
  letter-spacing: 0.04em;
}

body {
  display: flex;
  min-height: 0;
}

/* ---------- sidebar ---------- */

#sidebar {
  width: 300px;
  min-width: 300px;
  height: 100%;
  min-height: 0;
  border-right: 1px solid #000;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

body.sidebar-hidden #sidebar {
  display: none;
}

.sidebar-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid #000;
  padding-bottom: 12px;
}

.sidebar-header h1 {
  border-bottom: none;
  padding-bottom: 0;
  flex: 1;
}

#sidebar-toggle {
  position: fixed;
  z-index: 3;
  padding: 4px 8px;
  font-size: 10px;
}

body:not(.sidebar-hidden) #sidebar-toggle {
  top: 16px;
  left: calc(300px - 16px);
  transform: translateX(-100%);
}

body.sidebar-hidden #sidebar-toggle {
  top: 0;
  left: 0;
  padding: 8px 10px;
  font-size: 11px;
}

h1 {
  font-size: 16px;
  font-weight: bold;
  border-bottom: 1px solid #000;
  padding-bottom: 12px;
}

h2 {
  font-size: 11px;
  font-weight: bold;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
}

h3 {
  font-size: 10px;
  font-weight: normal;
  letter-spacing: 0.08em;
  margin: 12px 0 4px;
  display: flex;
  justify-content: space-between;
}

h3:first-of-type {
  margin-top: 8px;
}

.num {
  font-family: "Courier New", monospace;
  font-weight: normal;
}

section {
  display: block;
}

/* ---------- buttons ---------- */

button, .file-btn {
  font-family: Helvetica, Arial, sans-serif;
  font-size: 11px;
  letter-spacing: 0.04em;
  background: #fff;
  color: #000;
  border: 1px solid #000;
  padding: 8px 10px;
  cursor: pointer;
  text-align: center;
  display: inline-block;
}

button:hover, .file-btn:hover {
  background: #000;
  color: #fff;
}

button.active {
  background: #000;
  color: #fff;
}

button:disabled {
  opacity: 0.35;
  cursor: default;
}

button:disabled:hover {
  background: #fff;
  color: #000;
}

/* compact borderless action button */
.btn-ghost {
  border: none;
  background: transparent;
  padding: 4px 5px;
  font-size: 9px;
  line-height: 1;
  white-space: nowrap;
}

.btn-ghost:hover {
  background: #000;
  color: #fff;
}

button.wide, .file-btn.wide {
  width: 100%;
  margin-top: 8px;
}

.btn-row {
  display: flex;
  gap: 0;
  margin-bottom: 8px;
}

.btn-row button {
  flex: 1;
}

.btn-row button + button {
  border-left: none;
}

.file-btn {
  width: 100%;
}

/* ---------- slider ---------- */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 1px;
  background: #000;
  outline: none;
  margin: 12px 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 11px;
  height: 11px;
  background: #000;
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 11px;
  height: 11px;
  background: #000;
  border: none;
  border-radius: 0;
  cursor: pointer;
}

.hint {
  font-size: 10px;
  margin: 8px 0;
}

/* ---------- upload grid ---------- */

.upload-grid {
  display: grid;
  grid-template-columns: repeat(2, 52px);
  grid-auto-rows: 52px;
  max-height: 140px;
  margin-top: 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid #000;
}

.upload-item {
  position: relative;
  width: 100%;
  height: 52px;
  min-height: 52px;
  padding: 0;
  border: none;
  border-right: 1px solid #000;
  border-bottom: 1px solid #000;
  background: #fff;
  cursor: pointer;
  overflow: hidden;
  text-align: left;
}

.upload-item:nth-child(2n) {
  border-right: none;
}

.upload-item img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.upload-item .upload-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 2px 4px;
  font-family: "Courier New", monospace;
  font-size: 8px;
  line-height: 1.1;
  background: #fff;
  border-top: 1px solid #000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upload-item .upload-del {
  position: absolute;
  top: 0;
  right: 0;
  padding: 1px 4px;
  font-size: 9px;
  border: none;
  border-left: 1px solid #000;
  border-bottom: 1px solid #000;
  background: #fff;
  line-height: 1;
}

.upload-item .upload-del:hover {
  background: #000;
  color: #fff;
}

.upload-item.active {
  outline: 2px solid #000;
  outline-offset: -2px;
  z-index: 1;
}

body.dark .upload-grid {
  border-color: #fff;
}

body.dark .upload-item {
  background: #000;
  border-color: #fff;
}

body.dark .upload-item .upload-name {
  background: #000;
  border-color: #fff;
}

body.dark .upload-item .upload-del {
  background: #000;
  border-color: #fff;
}

body.dark .upload-item.active {
  outline-color: #fff;
}

/* ---------- layer list ---------- */

#layer-toolbar {
  margin-bottom: 0;
}

#layer-list {
  display: flex;
  flex-direction: column;
  max-height: 360px;
  overflow-y: auto;
  border: 1px solid #000;
}

.layer-item {
  padding: 8px 8px;
  display: grid;
  grid-template-columns: 16px 20px minmax(0, 1fr) max-content;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.layer-item + .layer-item {
  border-top: 1px solid #000;
}

.layer-item .check {
  font-family: "Courier New", monospace;
  font-size: 14px;
  line-height: 1;
  text-align: center;
}

.layer-item .swatch {
  width: 20px;
  height: 20px;
  border: 1px solid #000;
  flex-shrink: 0;
}

.layer-item .name {
  font-family: "Courier New", monospace;
  font-size: 11px;
  line-height: 1.3;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layer-item .bg-controls {
  display: flex;
  gap: 0;
  flex-shrink: 0;
  align-items: center;
  margin-right: 4px;
}

/* ---------- color swatch inputs ---------- */

input[type="color"].swatch-input {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  padding: 0;
  border: 1px solid #000;
  background: #fff;
  cursor: pointer;
  pointer-events: auto;
  touch-action: none;
}

input[type="color"].swatch-input::-webkit-color-swatch-wrapper {
  padding: 0;
  width: 100%;
  height: 100%;
}

input[type="color"].swatch-input::-webkit-color-swatch {
  border: none;
  width: 100%;
  height: 100%;
}

input[type="color"].swatch-input::-moz-color-swatch {
  border: none;
  width: 100%;
  height: 100%;
}

.backdrop-controls {
  display: flex;
  gap: 4px;
  align-items: center;
}

.backdrop-controls .btn-ghost {
  font-size: 11px;
}

.hint-inline {
  font-size: 9px;
  opacity: 0.6;
  margin-left: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layer-item .actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  align-items: center;
}

.layer-item.hidden-layer {
  opacity: 0.35;
}

body.dark .layer-item.hidden-layer {
  opacity: 0.4;
}

.layer-item.solo {
  background: #000;
  color: #fff;
}

.layer-item.solo .swatch {
  border-color: #fff;
}

.layer-item.solo .btn-ghost {
  background: transparent;
  color: #fff;
}

.layer-item.solo .btn-ghost:hover {
  background: #fff;
  color: #000;
}

.layer-item.solo .swatch-input {
  border-color: #fff;
}

body.dark .layer-item.solo {
  background: #fff;
  color: #000;
}

body.dark .layer-item.solo .swatch {
  border-color: #000;
}

body.dark .layer-item.solo .btn-ghost {
  background: transparent;
  color: #000;
}

body.dark .layer-item.solo .btn-ghost:hover {
  background: #000;
  color: #fff;
}

body.dark .layer-item.solo .swatch-input {
  border-color: #000;
}

body.dark #layer-list {
  border-color: #fff;
}

body.dark .layer-item + .layer-item {
  border-top-color: #fff;
}

/* ---------- status ---------- */

#status {
  margin-top: auto;
  border-top: 1px solid #000;
  padding-top: 12px;
  font-family: "Courier New", monospace;
  font-size: 11px;
}

/* ---------- viewer ---------- */

#viewer {
  flex: 1;
  min-height: 0;
  height: 100%;
  position: relative;
  background: #fff;
  overflow: hidden;
}

#viewer canvas {
  display: block;
}

.viewer-empty {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.viewer-empty .app-title {
  display: block;
  width: min(360px, 70vw);
  max-height: 40vh;
  height: auto;
  object-fit: contain;
}

#viewer.pick-mode canvas {
  cursor: crosshair;
}

#view-mode-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 3;
  margin-bottom: 0;
}

#view-mode-toggle button {
  flex: none;
  padding: 4px 8px;
  font-size: 10px;
}

#view-mode-toggle input[type="number"] {
  flex: none;
  width: 48px;
  padding: 4px 4px;
  font-family: Helvetica, Arial, sans-serif;
  font-size: 10px;
  letter-spacing: 0.04em;
  text-align: center;
  background: #fff;
  color: #000;
  border: 1px solid #000;
  border-left: none;
  -moz-appearance: textfield;
  appearance: textfield;
}

#view-mode-toggle input[type="number"]::-webkit-outer-spin-button,
#view-mode-toggle input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

#view-mode-toggle input[type="number"]:disabled {
  opacity: 0.35;
  cursor: default;
}

.pick-preview {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid #000;
  pointer-events: none;
  z-index: 10;
  box-sizing: border-box;
  transform: translate(-50%, -50%);
}

body.dark .pick-preview {
  border-color: #fff;
}

#viewer-hint {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  border-top: 1px solid #000;
  background: #fff;
  padding: 6px 10px;
  font-size: 10px;
  z-index: 2;
  display: flex;
  align-items: center;
}

#viewer-hint button {
  padding: 2px 6px;
  font-size: 10px;
  margin-left: 6px;
}

/* ---------- dark mode ---------- */

body.dark,
body.dark #sidebar,
body.dark #viewer,
body.dark #viewer-hint {
  background: #000;
  color: #fff;
}

body.dark #sidebar,
body.dark h1,
body.dark #status,
body.dark #viewer-hint,
body.dark .layer-item,
body.dark .sidebar-header {
  border-color: #fff;
}

body.dark button,
body.dark .file-btn {
  background: #000;
  color: #fff;
  border-color: #fff;
}

body.dark button:hover,
body.dark .file-btn:hover,
body.dark button.active {
  background: #fff;
  color: #000;
}

body.dark input[type="range"] {
  background: #fff;
}

body.dark input[type="range"]::-webkit-slider-thumb {
  background: #fff;
}

body.dark input[type="range"]::-moz-range-thumb {
  background: #fff;
}

body.dark .layer-item .swatch {
  border-color: #fff;
}

body.dark input[type="color"].swatch-input {
  border-color: #fff;
  background: #000;
}

body.dark #view-mode-toggle input[type="number"] {
  background: #000;
  color: #fff;
  border-color: #fff;
}

body.dark .btn-ghost {
  background: transparent;
}

body.dark button:disabled:hover {
  background: #000;
  color: #fff;
}
