* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #111827;
  color: #e5e7eb;
}

#viewer {
  position: fixed;
  inset: 0;
}

#panel {
  position: fixed;
  top: 16px;
  left: 16px;
  width: min(500px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 14px;
  border-radius: 16px;
  background: rgba(17, 24, 39, 0.9);
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 30;
}


#panelToggleBtn {
  margin-left: auto;
  min-width: 40px;
  padding: 10px 12px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: center;
  position: sticky;
  top: 0;
  background: rgba(17, 24, 39, 0.9);
  backdrop-filter: blur(12px);
  padding: 14px 0;
  margin: -14px -14px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 1;
  position: sticky;
}

.panel-header h1 {
  flex: 1 1 auto;
  margin: 0;
  text-align: center;
}

#panelToggleBtn {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 0;
}

.panel-content {
  padding-top: 20px;
}

.always-visible-controls {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  margin-top: 14px;
  padding-top: 14px;
}

#panel.collapsed .panel-content {
  display: none;
}

#panel.collapsed .panel-header h1 {
  display: none;
}

#panel.collapsed {
  width: min(500px, calc(100vw - 32px));
}

#panel.collapsed .always-visible-controls {
  display: block;
}

#panel.collapsed .panel-header {
  display: none;
}

#panelTile {
  position: fixed;
  top: 16px;
  left: 16px;
  width: 46px;
  height: 46px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(17, 24, 39, 0.96);
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #e5e7eb;
  cursor: pointer;
  z-index: 31;
}

#panelTile.hidden {
  display: none;
}

h1 {
  margin: 0 0 8px;
  font-size: 18px;
}

p {
  margin: 0 0 12px;
  color: #9ca3af;
  font-size: 13px;
  line-height: 1.35;
}

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

.row.three {
  grid-template-columns: 1fr 1fr 1fr;
}

label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 13px;
  color: #d1d5db;
}

.field-label {
  display: block;
  margin: 10px 0 4px;
  font-size: 12px;
  color: #9ca3af;
  font-weight: 650;
}

input,
select,
textarea,
button {
  font: inherit;
}

input[type="number"],
input[type="text"],
select {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 8px 10px;
  background: #020617;
  color: #e5e7eb;
  outline: none;
}

input[type="number"]:focus,
input[type="text"]:focus,
select:focus,
textarea:focus {
  border-color: #60a5fa;
}

textarea {
  width: 100%;
  min-height: 130px;
  resize: vertical;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 10px;
  background: #020617;
  color: #e5e7eb;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.35;
  outline: none;
}

button {
  border: 0;
  border-radius: 12px;
  padding: 10px 12px;
  color: white;
  background: #2563eb;
  cursor: pointer;
  font-weight: 700;
}

button.secondary {
  background: #374151;
}

button.good {
  background: #16a34a;
}

button:hover {
  filter: brightness(1.1);
}

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

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

#status {
  margin-top: 10px;
  font-size: 12px;
  color: #93c5fd;
  white-space: pre-wrap;
}

.muted {
  color: #9ca3af;
}

.small {
  font-size: 12px;
}

.pattern-preview {
  margin-top: 8px;
  padding: 8px;
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.72);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
  color: #bfdbfe;
}

#patternCanvas {
  width: 100%;
  height: 220px;
  margin-top: 10px;
  border-radius: 12px;
  background: #020617;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

#patternInput {
  width: 100%;
  margin-top: 10px;
}
