/* Colors — RGB color proof pager (all 16,777,216 colors, 8×8 per page).
   Everything is scoped to #panel-colors / .clr-* so nothing leaks into other tabs. */

#panel-colors.panel[hidden] {
  display: none !important;
}

#panel-colors.panel.active {
  display: block;
  min-height: calc(100vh - 100px);
}

body.clr-tab-active #panel-colors {
  background: #0a0c10;
}

#panel-colors .clr-shell {
  max-width: 82rem;
  margin: 0 auto;
  padding: 0.75rem 1rem 2.2rem;
  color: var(--text, #f5f0e8);
  font-family: var(--font-ui, "DM Sans", system-ui, sans-serif);
}

#panel-colors .clr-top h2 {
  margin: 0 0 0.25rem;
  font-family: var(--font-display, Georgia, "Times New Roman", serif);
  font-weight: 400;
  font-size: clamp(1.5rem, 4vw, 2rem);
  color: var(--accent, #c9a227);
}

#panel-colors .clr-hint {
  margin: 0 0 0.75rem;
  max-width: 52rem;
  font-size: 0.82rem;
  line-height: 1.45;
  color: rgba(200, 190, 160, 0.78);
}

#panel-colors .clr-prompt-wrap {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  max-width: none;
  margin: 0.45rem 0 0;
}

#panel-colors .clr-prompt {
  width: 100%;
  min-height: 3.2rem;
  margin-top: 0.25rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border, #3a3428);
  border-radius: 8px;
  background: #0c0d10;
  color: var(--text, #f5f0e8);
  font: inherit;
  font-size: 0.88rem;
  resize: vertical;
}

#panel-colors .clr-hint strong {
  color: #e8d5a3;
  font-weight: 600;
}

/* ---- controls ---- */

#panel-colors .clr-controls {
  border-radius: 12px;
  border: 1px solid rgba(201, 162, 39, 0.35);
  background:
    radial-gradient(ellipse at 50% 0%, rgba(201, 162, 39, 0.1), transparent 60%),
    linear-gradient(180deg, #16140f 0%, #0e0c0a 100%);
  padding: 0.65rem 0.75rem 0.5rem;
  margin-bottom: 0.85rem;
}

#panel-colors .clr-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.55rem;
  margin-bottom: 0.5rem;
}

#panel-colors .clr-field,
#panel-colors .clr-field-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: rgba(232, 213, 163, 0.85);
}

#panel-colors .clr-of {
  color: var(--text-muted, #9a9288);
  font-variant-numeric: tabular-nums;
}

#panel-colors .clr-btn {
  font: inherit;
  font-size: 0.82rem;
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  border: 1px solid rgba(201, 162, 39, 0.4);
  background: rgba(34, 31, 28, 0.95);
  color: #f0e6cc;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

#panel-colors .clr-btn:hover:not(:disabled) {
  border-color: rgba(240, 215, 138, 0.8);
  background: rgba(60, 50, 26, 0.95);
}

#panel-colors .clr-btn:focus-visible,
#panel-colors .clr-num:focus-visible,
#panel-colors .clr-select:focus-visible {
  outline: 2px solid var(--accent, #c9a227);
  outline-offset: 2px;
}

#panel-colors .clr-btn.accent {
  background: linear-gradient(180deg, #d4af37, #a8841c);
  border-color: #e8c65a;
  color: #1a1408;
  font-weight: 700;
}

#panel-colors .clr-btn.accent:hover:not(:disabled) {
  background: linear-gradient(180deg, #e2bf4a, #b8922a);
}

#panel-colors .clr-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#panel-colors .clr-btn-sm {
  font-size: 0.72rem;
  padding: 0.2rem 0.5rem;
}

#panel-colors .clr-num,
#panel-colors .clr-select {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.35rem 0.45rem;
  border-radius: 7px;
  border: 1px solid rgba(201, 162, 39, 0.3);
  background: rgba(0, 0, 0, 0.4);
  color: #f5f0e8;
  font-variant-numeric: tabular-nums;
}

#panel-colors .clr-num {
  width: 4.4rem;
}

#panel-colors .clr-num-wide {
  width: 5.2rem;
}

#panel-colors .clr-select {
  max-width: 100%;
}

#panel-colors .clr-jump-msg {
  font-size: 0.78rem;
}

#panel-colors .clr-jump-msg.clr-err {
  color: #ffb0a8;
}

#panel-colors .clr-page-info {
  margin: 0.1rem 0 0.15rem;
  font-size: 0.78rem;
  color: rgba(200, 190, 160, 0.78);
  font-variant-numeric: tabular-nums;
}

/* ---- grid + detail ---- */

#panel-colors .clr-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

@media (min-width: 1180px) {
  #panel-colors .clr-body {
    grid-template-columns: minmax(0, 988px) minmax(14rem, 17rem);
    justify-content: center;
  }
  #panel-colors .clr-detail-wrap {
    position: sticky;
    top: 0.75rem;
  }
}

#panel-colors .clr-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 4px;
  width: 100%;
  max-width: 988px; /* 8 × 120px swatches + gaps, like the reference */
  margin: 0 auto;
}

#panel-colors .clr-slot {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2; /* 120 × 80 in the reference */
  margin: 0;
  padding: 0;
  border: 1px solid #444;
  border-radius: 6px;
  overflow: hidden;
  font: inherit;
  font-size: clamp(0.56rem, 1.05vw, 0.75rem);
  line-height: 1.2em;
  text-align: center;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#panel-colors .clr-slot:hover {
  outline: 2px solid var(--accent, #c9a227);
  outline-offset: -2px;
}

#panel-colors .clr-slot:focus-visible {
  outline: 2px solid #fff;
  outline-offset: -3px;
}

/* Selection ring is drawn inside the swatch (above the original-color strip)
   so nothing paints into the grid gaps. */
#panel-colors .clr-slot.clr-selected::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border: 2px solid #fff;
  border-radius: inherit;
  box-shadow: inset 0 0 0 2px var(--accent, #c9a227);
  pointer-events: none;
}

#panel-colors .clr-slot.clr-flash::after {
  animation: clr-flash 0.6s ease-in-out 3;
}

@keyframes clr-flash {
  0%, 100% { box-shadow: inset 0 0 0 2px var(--accent, #c9a227); }
  50% { box-shadow: inset 0 0 0 7px var(--accent, #c9a227); }
}

@media (prefers-reduced-motion: reduce) {
  #panel-colors .clr-slot.clr-flash::after {
    animation: none;
  }
}

/* Original-color strip across the top of each swatch */
#panel-colors .clr-orig-tab {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 10px;
  border-bottom: 1px solid #444;
}

#panel-colors .clr-slot-text {
  position: absolute;
  top: 14px;
  left: 0;
  width: 100%;
  padding: 2px;
  font-weight: bold;
}

#panel-colors .clr-slot-spell,
#panel-colors .clr-slot-line {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

/* ---- detail panel ---- */

#panel-colors .clr-detail-wrap {
  border-radius: 12px;
  border: 1px solid rgba(201, 162, 39, 0.35);
  background: linear-gradient(180deg, #16140f 0%, #0e0c0a 100%);
  padding: 0.75rem;
}

#panel-colors .clr-detail-empty {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted, #9a9288);
}

#panel-colors .clr-d-swatch {
  position: relative;
  height: 6.5rem;
  border-radius: 8px;
  border: 1px solid #444;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 0.4rem 0.5rem;
}

#panel-colors .clr-d-swatch .clr-orig-tab {
  height: 16px;
}

#panel-colors .clr-d-swatch-hex {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-weight: 700;
  font-size: 0.95rem;
}

#panel-colors .clr-d-spell {
  margin: 0.6rem 0 0.35rem;
  font-family: var(--font-display, Georgia, serif);
  font-weight: 400;
  font-size: 1.3rem;
  color: #f0d78a;
  font-variant-numeric: tabular-nums;
}

#panel-colors .clr-d-list {
  margin: 0;
  font-size: 0.82rem;
}

#panel-colors .clr-d-list dt {
  margin-top: 0.45rem;
  color: var(--text-muted, #9a9288);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#panel-colors .clr-d-list dd {
  margin: 0.15rem 0 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  font-variant-numeric: tabular-nums;
}

#panel-colors .clr-d-list code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color: #e8d5a3;
}

#panel-colors .clr-d-order {
  text-transform: none;
  letter-spacing: 0;
}

#panel-colors .clr-copy-status {
  min-height: 1.1em;
  margin: 0.45rem 0 0;
  font-size: 0.75rem;
  color: #7dffb3;
}

/* ---- tablet ---- */
@media (max-width: 900px) {
  #panel-colors .clr-grid {
    gap: 3px;
  }
  #panel-colors .clr-slot-text {
    top: 11px;
  }
  #panel-colors .clr-orig-tab {
    height: 8px;
  }
}

/* ---- phone: keep 8 columns, shrink swatches, Spell number only ---- */
@media (max-width: 640px) {
  #panel-colors .clr-shell {
    padding: 0.5rem 0.5rem 1.8rem;
  }
  #panel-colors .clr-controls {
    padding: 0.55rem 0.55rem 0.35rem;
  }
  #panel-colors .clr-nav .clr-btn {
    flex: 1 1 0;
    min-width: 0;
    padding: 0.45rem 0.3rem;
  }
  #panel-colors .clr-field {
    flex-wrap: wrap;
  }
  #panel-colors .clr-select {
    width: 100%;
  }
  #panel-colors .clr-grid {
    gap: 2px;
  }
  #panel-colors .clr-slot {
    aspect-ratio: 1 / 1;
    border-radius: 4px;
    font-size: 0.5rem;
    line-height: 1.1em;
  }
  #panel-colors .clr-orig-tab {
    height: 6px;
  }
  #panel-colors .clr-slot-text {
    top: 8px;
    padding: 1px;
  }
  #panel-colors .clr-slot-word,
  #panel-colors .clr-slot-line {
    display: none;
  }
  #panel-colors .clr-slot-num {
    display: block;
    white-space: normal;
    word-break: break-all;
  }
}

/* ---- counting-mode toggle (Original / Unique) ---- */

#panel-colors .clr-mode {
  display: inline-flex;
  border: 1px solid rgba(201, 162, 39, 0.4);
  border-radius: 8px;
  overflow: hidden;
  flex: 0 0 auto;
}

#panel-colors .clr-mode-btn {
  font: inherit;
  font-size: 0.82rem;
  padding: 0.35rem 0.8rem;
  border: 0;
  background: rgba(34, 31, 28, 0.95);
  color: #f0e6cc;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

#panel-colors .clr-mode-btn + .clr-mode-btn {
  border-left: 1px solid rgba(201, 162, 39, 0.4);
}

#panel-colors .clr-mode-btn:hover:not(.is-on) {
  background: rgba(60, 50, 26, 0.95);
}

#panel-colors .clr-mode-btn.is-on {
  background: linear-gradient(180deg, #d4af37, #a8841c);
  color: #1a1408;
  font-weight: 700;
}

#panel-colors .clr-mode-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: -3px;
}

#panel-colors .clr-mode-note {
  flex: 1 1 18rem;
  min-width: 0;
  font-size: 0.76rem;
  line-height: 1.35;
  color: rgba(200, 190, 160, 0.78);
}

@media (max-width: 640px) {
  #panel-colors .clr-mode-note {
    flex-basis: 100%;
  }
  #panel-colors .clr-mode-btn {
    padding: 0.45rem 1rem;
  }
}

/* ---- 3-tone generator: add-as-tone, tray, results ---- */

#panel-colors .clr-add-tone-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.6rem;
  margin-top: 0.55rem;
}

#panel-colors .clr-tone-msg {
  font-size: 0.75rem;
  color: #7dffb3;
}

#panel-colors .clr-tone-msg.clr-err,
#panel-colors .clr-gen-status.clr-err,
#panel-colors .clr-gen-save.clr-err {
  color: #ffb0a8;
}

#panel-colors .clr-tones {
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(201, 162, 39, 0.25);
}

#panel-colors .clr-tones-title {
  margin: 0 0 0.3rem;
  font-family: var(--font-display, Georgia, "Times New Roman", serif);
  font-weight: 400;
  font-size: 1.15rem;
  color: var(--accent, #c9a227);
}

#panel-colors .clr-tones-hint {
  margin: 0 0 0.55rem;
  font-size: 0.76rem;
  line-height: 1.4;
  color: rgba(200, 190, 160, 0.78);
}

#panel-colors .clr-tones-hint strong {
  color: #e8d5a3;
}

#panel-colors .clr-tones-hint kbd {
  font: inherit;
  font-size: 0.72rem;
  padding: 0 0.3rem;
  border-radius: 4px;
  border: 1px solid rgba(201, 162, 39, 0.4);
  background: rgba(0, 0, 0, 0.35);
}

#panel-colors .clr-tone-tray,
#panel-colors .clr-gen-tones {
  list-style: none;
  margin: 0 0 0.55rem;
  padding: 0;
  display: grid;
  gap: 0.35rem;
}

#panel-colors .clr-tone-slot,
#panel-colors .clr-gen-tones li {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-height: 2.4rem;
  padding: 0.35rem 0.4rem;
  border-radius: 8px;
  border: 1px dashed rgba(201, 162, 39, 0.3);
  background: rgba(0, 0, 0, 0.25);
  font-size: 0.78rem;
  color: var(--text-muted, #9a9288);
}

#panel-colors .clr-add-slot {
  margin-left: auto;
}

#panel-colors .clr-subject-box {
  margin: 0.55rem 0 0.7rem;
  padding: 0.55rem 0.55rem 0.6rem;
  border-radius: 8px;
  border: 1px solid rgba(201, 162, 39, 0.28);
  background: rgba(0, 0, 0, 0.22);
}

#panel-colors .clr-subject-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
}

#panel-colors .clr-subject-readout {
  margin: 0.35rem 0 0.45rem;
  font-size: 0.88rem;
  line-height: 1.35;
  color: #f0e6cc;
}

#panel-colors .clr-toggle {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: rgba(200, 190, 160, 0.88);
  cursor: pointer;
}

#panel-colors .clr-toggle input {
  margin-top: 0.15rem;
}

#panel-colors .clr-tone-slot.is-filled,
#panel-colors .clr-gen-tones li {
  border-style: solid;
  color: #f0e6cc;
}

#panel-colors .clr-tone-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 6px;
  border: 1px solid #444;
  background: repeating-linear-gradient(45deg, #1a1712 0 4px, #231f18 4px 8px);
  font-size: 0.72rem;
  font-weight: 700;
  color: rgba(200, 190, 160, 0.6);
}

#panel-colors .clr-tone-label {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

#panel-colors .clr-tone-hex {
  font-size: 0.78rem;
  color: #f5f0e8;
}

#panel-colors .clr-tone-name {
  font-size: 0.72rem;
  color: rgba(200, 190, 160, 0.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#panel-colors .clr-tone-x {
  flex: 0 0 auto;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 6px;
  border: 1px solid rgba(201, 162, 39, 0.35);
  background: rgba(34, 31, 28, 0.95);
  color: #f0e6cc;
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
}

#panel-colors .clr-tone-x:hover {
  border-color: #ffb0a8;
  color: #ffb0a8;
}

#panel-colors .clr-tone-x:focus-visible {
  outline: 2px solid var(--accent, #c9a227);
  outline-offset: 1px;
}

#panel-colors .clr-gen-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.5rem;
}

#panel-colors .clr-select-sm {
  font-size: 0.8rem;
  padding: 0.3rem 0.35rem;
}

#panel-colors .clr-gen-status {
  min-height: 1.1em;
  margin: 0.45rem 0 0;
  font-size: 0.75rem;
  color: rgba(200, 190, 160, 0.85);
}

#panel-colors .clr-gen-key {
  margin-top: 0.35rem;
}

#panel-colors .clr-gen-dock {
  max-width: 82rem;
  margin: 1.1rem auto 0;
  padding: 0.75rem 1rem 0.4rem;
  border-top: 1px solid rgba(201, 162, 39, 0.28);
}

#panel-colors .clr-gen-results {
  margin-top: 0.35rem;
}

#panel-colors .clr-gen-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 30rem), 1fr));
  gap: 0.85rem;
}

#panel-colors .clr-gen-card {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(10rem, 1fr);
  gap: 0.7rem;
  padding: 0.6rem;
  border-radius: 12px;
  border: 1px solid rgba(201, 162, 39, 0.35);
  background: linear-gradient(180deg, #16140f 0%, #0e0c0a 100%);
}

#panel-colors .clr-gen-media {
  position: relative;
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
}

#panel-colors .clr-gen-img-link,
#panel-colors .clr-gen-img {
  display: block;
  width: 100%;
  height: 100%;
}

#panel-colors .clr-gen-img {
  object-fit: cover;
}

#panel-colors .clr-gen-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.75;
}

#panel-colors .clr-gen-card.is-pending .clr-gen-placeholder {
  animation: clr-gen-pulse 1.6s ease-in-out infinite;
}

#panel-colors .clr-gen-placeholder span {
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: #f5f0e8;
  font-size: 0.8rem;
}

#panel-colors .clr-gen-card.is-failed .clr-gen-placeholder {
  opacity: 0.35;
  animation: none;
}

@keyframes clr-gen-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 0.9; }
}

@media (prefers-reduced-motion: reduce) {
  #panel-colors .clr-gen-card.is-pending .clr-gen-placeholder {
    animation: none;
  }
}

#panel-colors .clr-gen-side {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

#panel-colors .clr-gen-kicker {
  margin: 0 0 0.35rem;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(200, 190, 160, 0.7);
}

#panel-colors .clr-gen-subject {
  margin: 0 0 0.35rem;
  font-size: 0.74rem;
  color: rgba(200, 190, 160, 0.85);
}

#panel-colors .clr-gen-save {
  margin: 0 0 0.45rem;
  font-size: 0.72rem;
  color: #7dffb3;
}

#panel-colors .clr-gen-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: auto;
}

#panel-colors .clr-gen-actions a.clr-btn {
  text-decoration: none;
  display: inline-block;
}

@media (max-width: 640px) {
  #panel-colors .clr-gen-card {
    grid-template-columns: minmax(0, 1fr);
  }
  #panel-colors .clr-gen-tones {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  #panel-colors .clr-gen-tones li {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }
  #panel-colors .clr-gen-tones li .clr-tone-chip {
    width: 100%;
  }
  #panel-colors .clr-tone-x {
    width: 2.3rem;
    height: 2.3rem;
  }
  #panel-colors .clr-gen-row .clr-btn {
    flex: 1 1 auto;
  }
}
