:root {
  color-scheme: light;
  --paper: #f2f0e8;
  --ink: #111111;
  --muted: #54534d;
  --line: #a6a39a;
  --accent: #ff6600;
  --error: #a83400;
  --field: #e8e5da;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #111111;
  --ink: #f2f0e8;
  --muted: #b7b4a9;
  --line: #69675e;
  --error: #ff9b67;
  --field: #1e1e1b;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; }
button, input { color: inherit; font: inherit; min-width: 0; }
button, a, summary, .file-control { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; padding: 0; background: none; border: 0; text-align: left; }
button:disabled { cursor: default; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; position: relative; z-index: 1; }
p, h1, h2, h3 { margin: 0; }
.page { max-width: 1472px; padding-inline: clamp(16px, 5vw, 80px); margin-inline: auto; }
.label { font: 600 0.72rem/1.4 var(--mono); text-transform: uppercase; letter-spacing: 0.07em; }
.hint { color: var(--muted); font-size: 0.8125rem; line-height: 1.45; }

.masthead, .appearance, .section-heading, .library-row, .palette-actions, footer { display: flex; align-items: center; }
.masthead { min-height: 80px; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--ink); }
.brand { display: inline-flex; align-items: center; gap: 9px; min-height: 44px; font-size: 1.34rem; font-weight: 800; letter-spacing: -0.065em; }
.brand-mark { width: 19px; height: 19px; border: 4px solid var(--ink); border-right-color: transparent; position: relative; }
.brand-mark::after { content: ""; position: absolute; width: 4px; height: 4px; background: var(--ink); top: 50%; right: -4px; transform: translateY(-50%); }
.appearance { gap: 14px; }
.switch { display: inline-flex; border: 1px solid var(--line); }
.switch button { padding-inline: 12px; min-height: 44px; font-size: 0.8125rem; font-weight: 600; white-space: nowrap; }
.switch button + button { border-left: 1px solid var(--line); }
.switch button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.switch button[aria-pressed="true"]::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 7px; vertical-align: 0.12em; background: var(--accent); border-radius: 50%; }
.modes { border-bottom: 1px solid var(--line); }
.modes [role="tablist"] { display: flex; }
.modes button { position: relative; min-height: 56px; padding-inline: clamp(10px, 2vw, 28px); font-weight: 700; border-right: 1px solid var(--line); }
.modes button:first-child { padding-left: 0; }
.modes button span { font: 400 0.75rem var(--mono); margin-right: 7px; color: var(--muted); }
.modes button[aria-selected="true"]::after { content: ""; position: absolute; height: 3px; background: var(--accent); inset: auto 0 -1px; }

.intro { display: grid; grid-template-columns: 1.4fr 1fr; align-items: end; gap: 24px; margin-block: clamp(34px, 5.5vw, 90px) clamp(30px, 4vw, 62px); }
h1 { font-size: clamp(3.5rem, 9.75vw, 9rem); font-weight: 700; line-height: 0.8; letter-spacing: -0.06em; }
.intro p { max-width: 34ch; font-size: clamp(1rem, 1.5vw, 1.25rem); line-height: 1.45; }

.converter-grid { display: grid; grid-template-columns: 1.4fr 1fr; grid-template-areas: "entry readouts" "swatch readouts"; border-bottom: 1px solid var(--ink); }
.source-swatch { grid-area: swatch; display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 20px; padding: clamp(16px, 2.2vw, 34px); min-height: 320px; background: #2949f2; color: #fff; }
.source-swatch:disabled { background: var(--field) !important; color: var(--muted) !important; }
.source-code { font-size: clamp(2.5rem, 6.3vw, 6.4rem); letter-spacing: -0.055em; line-height: 0.95; font-weight: 700; font-variant-numeric: tabular-nums; }
.readouts { grid-area: readouts; display: flex; flex-direction: column; justify-content: center; min-width: 0; padding-left: clamp(14px, 2.2vw, 34px); border-left: 1px solid var(--ink); }
.source-entry { grid-area: entry; padding: 0 clamp(14px, 2.2vw, 34px) 16px 0; }
.hex-entry { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-block: 8px 6px; }
input[type="text"], input[type="color"] { border: 1px solid var(--line); border-radius: 0; background: var(--field); min-height: 52px; }
input[type="text"] { padding: 8px 13px; font: 600 1rem var(--mono); }
#converter-hex { font-size: 1.375rem; }
input[type="color"] { width: 52px; padding: 6px; cursor: pointer; }
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: 0; }
input[type="color"]::-moz-color-swatch { border: 0; }
[aria-invalid="true"] { border-color: var(--error) !important; }
#converter-hint[data-error="true"], #palette-status[data-error="true"] { color: var(--error); }
.readout { display: grid; grid-template-columns: 70px minmax(0, 1fr); gap: 8px; align-items: center; width: 100%; min-height: 55px; padding: 8px 0; border-top: 1px solid var(--line); }
.readout:last-child { border-bottom: 1px solid var(--line); }
.value { font-family: var(--mono); font-weight: 600; font-size: clamp(0.83rem, 1.55vw, 1.2rem); overflow-wrap: anywhere; }
.approx { color: var(--muted); }
.conversion-note { padding-block: 11px 14px; }

.pantone { margin-top: clamp(36px, 5vw, 72px); }
.section-heading { justify-content: space-between; gap: 14px; flex-wrap: wrap; padding-block: 12px; border-bottom: 1px solid var(--ink); }
h2 { font-size: clamp(1.5rem, 3.2vw, 2.8rem); line-height: 1.05; letter-spacing: -0.055em; }
.match-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); margin-block: 16px 0; border: solid var(--line); border-width: 1px 0 0 1px; }
.match { min-width: 0; border: solid var(--line); border-width: 0 1px 1px 0; display: flex; flex-direction: column; position: relative; }
.match[aria-pressed="true"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--accent); }
.match-color { width: 100%; aspect-ratio: 1.25; border-bottom: 1px solid var(--line); }
.match-body { display: grid; gap: 5px; width: 100%; padding: 10px; }
.match-code { font-size: 0.9rem; font-weight: 700; overflow-wrap: anywhere; }
.match-meta { color: var(--muted); font: 0.75rem/1.5 var(--mono); overflow-wrap: anywhere; }
.library-row { justify-content: space-between; gap: 14px; padding-block: 15px 8px; }
#library-status { font-size: 0.875rem; font-weight: 600; margin-bottom: 4px; overflow-wrap: anywhere; }
#library-status:empty { display: none; }
.action { display: inline-flex; align-items: center; justify-content: center; gap: 12px; min-height: 44px; padding: 0 14px; border: 1px solid var(--ink); font-weight: 700; font-size: 0.875rem; white-space: nowrap; }
.primary { background: var(--accent); color: #111; border-color: var(--accent); }
.file-control { position: relative; }
.file-control input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; min-height: 44px; cursor: pointer; }
.file-control:focus-within { outline: 2px solid var(--ink); outline-offset: 3px; }
.library-format { color: var(--muted); font-size: 0.8125rem; line-height: 1.55; }
.library-format summary { width: fit-content; min-height: 44px; line-height: 44px; cursor: pointer; }
.source-link { text-decoration: underline; text-underline-offset: 0.22em; }
.library-format p { max-width: 66ch; margin-bottom: 8px; }

#palette-form { border-top: 1px solid var(--ink); padding-top: 16px; }
.palette-entry { display: grid; grid-template-columns: minmax(0, 1fr) auto; margin-top: 8px; }
#palette-hint { margin-top: 8px; }
.palette-actions { gap: 16px; }
.text-action { font-size: 0.875rem; min-height: 44px; min-width: 44px; text-decoration: underline; text-underline-offset: 0.22em; }
.palette-toolbar { margin-top: 28px; }
.palette-group { padding-block: 24px 10px; }
.palette-group h3 { font: 700 1.15rem var(--mono); margin-bottom: 8px; }
.palette-bands { display: grid; grid-template-columns: minmax(0, 10fr) minmax(0, 1fr) minmax(0, 10fr); gap: 3px; }
.band { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); }
.band.base { grid-template-columns: minmax(0, 1fr); }
.band > .label { grid-column: 1 / -1; padding-block: 4px; }
.color-cell { min-height: 80px; display: flex; flex-direction: column; justify-content: space-between; gap: 6px; padding: 6px 3px; border: 1px solid rgba(0, 0, 0, 0.12); font: 0.66rem/1.2 var(--mono); }
.color-cell span { white-space: nowrap; }
footer { justify-content: space-between; gap: 12px; border-top: 1px solid var(--ink); margin-top: clamp(38px, 6vw, 88px); min-height: 70px; color: var(--muted); font-size: 0.8125rem; }
footer .brand { color: var(--ink); font-size: 1rem; }
.toast { pointer-events: none; position: fixed; z-index: 3; inset: auto 16px max(16px, env(safe-area-inset-bottom)) auto; max-width: calc(100% - 32px); background: var(--ink); color: var(--paper); font-size: 0.875rem; overflow-wrap: anywhere; }
.toast:not(:empty) { padding: 10px 14px; border-left: 3px solid var(--accent); }

@media (hover: hover) {
  .readout:enabled:hover, .action:not(.primary):hover, .match:hover { background: var(--field); }
  .text-action:hover { text-decoration-thickness: 2px; }
}
[data-copy]:active:not(:disabled) { outline: 2px solid var(--ink); outline-offset: -2px; }
@media (max-width: 1260px) {
  .palette-bands { grid-template-columns: minmax(0, 1fr); gap: 10px; }
}
@media (max-width: 680px) {
  .masthead { min-height: 68px; }
  .appearance > .label { position: absolute; clip-path: inset(50%); }
  .intro { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .title-break { display: none; }
  h1 { font-size: clamp(3rem, 11vw, 5rem); line-height: 0.9; }
  .converter-grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: "entry" "swatch" "readouts"; }
  .source-entry { padding-right: 0; }
  .source-swatch { min-height: 198px; }
  .readouts { padding: 16px 0 0; border: 0; }
  .match-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .band { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .library-row { align-items: flex-start; flex-direction: column; }
}
@media (max-width: 355px) {
  .switch button { padding-inline: 9px; }
  .match-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .band { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
