:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.4;
  color: #222;
  background-color: #f6f6f8;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: #222;
  color: #fff;
}

.app-header h1 {
  margin: 0;
  font-size: 1.5rem;
}

.app-header p {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
  opacity: 0.8;
}

.app-header-ads {
  min-width: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ad-placeholder {
  border: 1px dashed rgba(255, 255, 255, 0.4);
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  text-align: center;
  border-radius: 4px;
}

.app-main {
  display: flex;
  gap: 1rem;
  padding: 1rem;
}

.panel {
  background: #fff;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.panel-left {
  flex: 0 0 320px;
  max-width: 380px;
  overflow-y: auto;
  max-height: calc(100vh - 80px);
}

.panel-right {
  flex: 1;
  overflow-y: auto;
  max-height: calc(100vh - 80px);
}

.panel-section {
  border-bottom: 1px solid #eee;
  padding-bottom: 0.75rem;
  margin-bottom: 0.75rem;
}

.panel-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.panel-section h2 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}

.field,
.checkbox-field {
  display: flex;
  flex-direction: column;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.field span {
  margin-bottom: 0.15rem;
}

.field input[type="number"],
.field input[type="text"],
.field select {
  padding: 0.3rem 0.4rem;
  border-radius: 4px;
  border: 1px solid #ccc;
  font-size: 0.9rem;
}

.field input[type="file"] {
  font-size: 0.85rem;
}

.field-group {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.field-separator {
  font-size: 0.8rem;
  opacity: 0.7;
  align-self: center;
}

.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.mode-toggle label {
  margin-right: 0.75rem;
  font-size: 0.9rem;
}

.primary-button,
button {
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  border: 1px solid #ccc;
  background: #fafafa;
  cursor: pointer;
  font-size: 0.9rem;
}

.primary-button {
  background: #2563eb;
  border-color: #2563eb;
  color: white;
}

.primary-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.hint {
  font-size: 0.8rem;
  color: #555;
}

#preview-container {
  border: 1px solid #ddd;
  border-radius: 4px;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fafafa;
}

#preview-canvas {
  max-width: 100%;
  max-height: 400px;
  display: none;
}

#preview-placeholder {
  font-size: 0.9rem;
  color: #777;
  text-align: center;
  padding: 1rem;
}

.range-value {
  font-size: 0.8rem;
  margin-top: 0.2rem;
  align-self: flex-end;
}

/* Advanced-only fields (hidden by default in beginner mode) */
.advanced-only {
  display: none;
}

/* Responsive */
@media (max-width: 900px) {
  .app-main {
    flex-direction: column;
  }

  .panel-left,
  .panel-right {
    max-height: none;
  }

  .panel-left {
    max-width: 100%;
    flex: 1;
  }
}

.results-actions {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.results-actions .merge-controls {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.color-row-selected {
  outline: 2px solid #2563eb;
  background: rgba(37, 99, 235, 0.06);
}

/* --------- Tooltips --------- */
.tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
  width: 16px;
  height: 16px;
  font-size: 12px;
  border-radius: 50%;
  border: 1px solid #bbb;
  color: #555;
  cursor: help;
  position: relative;
  user-select: none;
}

.tip:focus {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}


.tip[data-tip]:hover::after,
.tip[data-tip]:focus::after {
  opacity: 1;
}

/* small triangle */
.tip[data-tip]:hover::before,
.tip[data-tip]:focus::before {
  opacity: 1;
}

/* Base pill (keep yours) */
.tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
  width: 16px;
  height: 16px;
  font-size: 12px;
  border-radius: 50%;
  border: 1px solid #bbb;
  color: #555;
  cursor: help;
  user-select: none;
}

/* Floating tooltip layer (appended to <body>) */
.tooltip-layer {
  position: fixed;
  /* key for viewport-safe positioning */
  z-index: 9999;
  max-width: min(340px, 92vw);
  background: #111;
  color: #fff;
  font-size: 12px;
  line-height: 1.35;
  padding: 8px 10px;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .12s ease, transform .12s ease;
  pointer-events: none;
  /* don’t trap the mouse */
}

.tooltip-layer[data-show="true"] {
  opacity: 1;
  transform: translateY(0);
}

.tooltip-layer .arrow {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #111;
  transform: rotate(45deg);
}

.tooltip-layer[data-placement="top"] .arrow {
  bottom: -5px;
}

.tooltip-layer[data-placement="bottom"] .arrow {
  top: -5px;
}


/* Helper block */
.helper {
  background: #f4f6fb;
  border: 1px solid #dbe3ff;
  padding: 0.7rem;
  border-radius: 6px;
  margin-top: 0.5rem;
}

.helper .row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: end;
}

.helper .row .field {
  min-width: 140px;
}

.preview-controls {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 0.5rem;
}

#legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 14px;
  padding: 4px 8px;
  cursor: pointer;
  user-select: none;
}

.legend-item .sw {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid #ccc;
}

.legend-item.active {
  outline: 2px solid #2563eb;
  background: rgba(37, 99, 235, .08);
}

#preview-container {
  position: relative;
  /* needed for absolute positioning inside */
}

#preview-readout {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  background: rgba(17, 17, 17, 0.96);
  color: #fff;
  font-size: 12px;
  line-height: 1.3;
  padding: 6px 8px;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .12s ease, transform .12s ease;
  max-width: 260px;
}

#preview-readout[data-show="true"] {
  opacity: 1;
  transform: translateY(0);
}

#preview-readout .row {
  display: flex;
  align-items: center;
  gap: 8px;
}

#preview-readout .sw {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid #ccc;
}

.preview-panes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.preview-pane h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: #333;
}

#final-preview-container {
  border: 1px solid #ddd;
  border-radius: 4px;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fafafa;
}

#final-preview-canvas {
  max-width: 100%;
  max-height: 400px;
  display: none;
}

#final-preview-placeholder {
  font-size: 0.9rem;
  color: #777;
  text-align: center;
  padding: 1rem;
}

.palette-list {
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 0.5rem;
  background: #fafafa;
  max-height: 220px;
  overflow-y: auto;
  margin-bottom: 0.5rem;
}

.palette-list .palette-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
  flex-wrap: wrap;
}

.palette-row .palette-row-name,
.palette-row .palette-row-hex {
  flex: 1;
  min-width: 120px;
  padding: 0.3rem 0.4rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.85rem;
}

.palette-row .palette-row-hex {
  max-width: 140px;
}

.palette-row .palette-row-remove {
  border: none;
  background: transparent;
  color: #b00;
  font-size: 1.1rem;
  padding: 0.1rem 0.25rem;
  cursor: pointer;
}

.palette-row .palette-swatch {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid #ccc;
}

.palette-row label {
  font-size: 0.8rem;
  color: #555;
}

.palette-row-index {
  width: 18px;
  text-align: right;
  font-size: 0.8rem;
  color: #666;
}

.palette-actions {
  display: flex;
  gap: 0.5rem;
  margin: 0.5rem 0;
  flex-wrap: wrap;
}
