:root {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #0b0b0d;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: #e8e6e3;
  overflow: hidden;
}

.startup-warning {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 560px;
  padding: 20px 24px;
  background: #3a1414;
  border: 1px solid #a33;
  border-radius: 8px;
  color: #ffdede;
  font-size: 15px;
  line-height: 1.5;
  z-index: 1000;
}

.startup-warning code {
  background: rgba(0, 0, 0, 0.35);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}

.startup-warning-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  color: #ffdede;
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}

.startup-warning-close:hover {
  background: rgba(255, 255, 255, 0.15);
}

#grid-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#grid-canvas:active {
  cursor: grabbing;
}

#panel {
  position: fixed;
  top: 16px;
  left: 16px;
  width: 380px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: rgba(18, 18, 22, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 16px;
  backdrop-filter: blur(6px);
  font-size: 13px;
  line-height: 1.4;
  transition: opacity 0.12s ease, transform 0.12s ease;
}

#panel.hidden {
  opacity: 0;
  transform: translateX(-12px);
  pointer-events: none;
  visibility: hidden;
}

.floating-button {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 5;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: rgba(18, 18, 22, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #e8e6e3;
  font-size: 16px;
  cursor: pointer;
  transition: opacity 0.12s ease;
}

.floating-button.hidden {
  opacity: 0;
  pointer-events: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.panel-header button {
  background: transparent;
  border: none;
  color: #cfcbc5;
  font-size: 14px;
  padding: 2px 6px;
  cursor: pointer;
}

.panel-header button:hover {
  color: #fff;
}

#panel h1 {
  font-size: 16px;
  margin: 0;
}

#panel h2 {
  font-size: 13px;
  margin: 0 0 6px;
  color: #b7b3ad;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.subtitle {
  margin: 0 0 14px;
  color: #a9a5a0;
}

section {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

section:last-of-type {
  border-bottom: none;
}

label {
  display: block;
  color: #cfcbc5;
  margin-bottom: 6px;
}

.row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

button {
  background: #2a2a30;
  color: #e8e6e3;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

button:hover {
  background: #38383f;
}

button:active {
  background: #45454d;
}

input[type="range"] {
  flex: 1;
}

input[type="number"] {
  width: 56px;
  background: #1c1c20;
  color: #e8e6e3;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  padding: 4px 6px;
}

input[type="text"] {
  flex: 1;
  min-width: 0;
  background: #1c1c20;
  color: #e8e6e3;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

select {
  width: 100%;
  background: #1c1c20;
  color: #e8e6e3;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  padding: 6px 8px;
}

.tag {
  background: #1c1c20;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  padding: 4px 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: #cfcbc5;
}

.status {
  min-height: 16px;
  margin: 6px 0 0;
  color: #8fd19e;
  font-size: 11px;
}

.status.error {
  color: #e3897a;
}

.hint {
  margin: 0;
  color: #8b877f;
  font-size: 11px;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.density-row {
  margin-top: 8px;
}

.density-row label {
  margin-bottom: 0;
  white-space: nowrap;
}

.mode-button.active {
  background: #3a6b4a;
  border-color: #5fae78;
}

#stats-canvas {
  width: 100%;
  height: 90px;
  background: #14141a;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

#stats-label {
  color: #cfcbc5;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

#paint-swatches {
  flex-wrap: wrap;
}

.swatch {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 5px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  color: rgba(0, 0, 0, 0.55);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
}

.swatch.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.4);
}

.advanced-rule-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.advanced-rule-row .swatch {
  width: 20px;
  height: 20px;
  flex: none;
  cursor: default;
}

.pin-button {
  flex: none;
  width: 52px;
  padding: 4px 2px;
  font-size: 11px;
}

.pin-button.pinned {
  background: #6b4a1e;
  border-color: #e0a44d;
  font-weight: 600;
}

.row-step-button {
  flex: none;
  width: 22px;
  padding: 2px 0;
  font-size: 11px;
}

.row-tick-badge {
  flex: none;
  width: 34px;
  font-size: 10px;
  font-family: monospace;
  color: #666;
  text-align: center;
  visibility: hidden;
}

.row-tick-badge.active {
  visibility: visible;
  color: #e0c44d;
  font-weight: 600;
}

.row-bar {
  flex: 1 1 auto;
  min-width: 60px;
  height: 16px;
  border-radius: 3px;
  overflow: hidden;
  display: flex;
  background: #14141a;
}

.row-bar-segment.stasis {
  background: #6b6b76;
}

.row-bar-segment.advance {
  background: #5fae78;
}

.row-bar-segment.retreat {
  background: #d9645a;
}

.row-bar-segment.other {
  background: #8a5fbf;
}

select {
  margin-bottom: 6px;
}
