/* CSS Custom Properties (Variables) */
:root {
  --bg: #ffffff;
  --bg-sec: #f5f5f5;
  --bg-tert: #eeeeee;
  --text: #111111;
  --text-sec: #555555;
  --text-hint: #888888;
  --border: rgba(0,0,0,0.12);
  --border-med: rgba(0,0,0,0.22);
  --border-str: rgba(0,0,0,0.35);
  --radius-md: 8px;
  --radius-lg: 12px;
  --success-bg: #eaf3de;
  --success-text: #27500a;
  --danger-bg: #fcebeb;
  --danger-text: #791f1f;
  --info-bg: #e6f1fb;
  --info-text: #0c447c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1a;
    --bg-sec: #242424;
    --bg-tert: #2e2e2e;
    --text: #f0f0f0;
    --text-sec: #aaaaaa;
    --text-hint: #666666;
    --border: rgba(255,255,255,0.1);
    --border-med: rgba(255,255,255,0.2);
    --border-str: rgba(255,255,255,0.32);
    --success-bg: #173404;
    --success-text: #c0dd97;
    --danger-bg: #501313;
    --danger-text: #f09595;
    --info-bg: #042c53;
    --info-text: #b5d4f4;
  }
}

/* Global Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Base Styles */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-tert);
  color: var(--text);
  line-height: 1.6;
  padding: 1rem;
}

@media (min-width: 481px) {
  body {
    padding: 2rem 1rem;
  }
}

.container {
  max-width: 720px;
  margin: 0 auto;
}

/* Skip Link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--info-bg);
  color: var(--info-text);
  padding: 8px;
  text-decoration: none;
  z-index: 100;
}

.skip-link:focus {
  top: 0;
}

/* Live Region for Screen Readers */
.sr-live-region {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Header */
header {
  margin-bottom: 1.5rem;
}

header h1 {
  font-size: 20px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}

@media (min-width: 481px) {
  header h1 {
    font-size: 22px;
  }
}

header p {
  font-size: 14px;
  color: var(--text-sec);
  line-height: 1.5;
}

/* Section Label */
.sec-label {
  font-size: 11px;
  color: var(--text-sec);
  font-weight: 500;
  letter-spacing: .06em;
  text-transform: uppercase;
  margin: 0 0 8px;
}

/* Card Component */
.card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  margin-bottom: 1.5rem;
}

@media (min-width: 481px) {
  .card {
    padding: 1rem 1.25rem;
  }
}

.card h3 {
  font-size: 15px;
  font-weight: 500;
  margin: 0 0 12px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card h3 i {
  font-size: 18px;
  color: var(--text-sec);
  flex-shrink: 0;
}

/* Toolbar */
.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  align-items: stretch;
}

.toolbar-btn {
  font-size: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 0.5px solid var(--border-med);
  background: var(--bg-sec);
  color: var(--text-sec);
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: color .15s, border-color .15s, background .15s;
  min-height: 44px;
  flex: 1;
  min-width: 100px;
  justify-content: center;
}

@media (min-width: 481px) {
  .toolbar-btn {
    flex: initial;
    min-width: auto;
  }
}

.toolbar-btn:active {
  background: var(--bg);
}

.toolbar-btn:hover {
  color: var(--text);
  border-color: var(--border-str);
}

.toolbar-btn.active {
  background: var(--info-bg);
  color: var(--info-text);
  border-color: var(--info-text);
}

/* Form Controls */
select, input[type=text], input[type=number] {
  width: 100%;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  border: 0.5px solid var(--border-med);
  border-radius: var(--radius-md);
  background: var(--bg-sec);
  color: var(--text);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  min-height: 44px;
}

select:focus, input[type=text]:focus, input[type=number]:focus {
  box-shadow: 0 0 0 2px var(--info-bg);
  border-color: var(--info-text);
}

/* Condition Note */
.condition-note {
  font-size: 13px;
  color: var(--text-sec);
  line-height: 1.65;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 0.5px solid var(--border);
  display: none;
}

.condition-note strong {
  color: var(--text);
  font-weight: 500;
}

/* Preset Pills */
.preset-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.cpill {
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 20px;
  border: 0.5px solid var(--border-med);
  background: var(--bg-sec);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  transition: border-color .15s, background .15s;
  min-height: 40px;
  touch-action: manipulation;
}

.cpill:active {
  background: var(--bg);
}

.cpill:hover {
  border-color: var(--border-str);
}

.cpill:focus {
  outline: 2px solid var(--info-text);
  outline-offset: 2px;
}

.cpill.active {
  border-color: var(--border-str);
  background: var(--bg);
  font-weight: 500;
}

.cpill-swatch {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  flex-shrink: 0;
}

.cpill-ratio {
  color: var(--text-hint);
  font-size: 11px;
}

/* Preview Box */
.preview-box {
  width: 100%;
  min-height: 110px;
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border-med);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
  margin-bottom: 1.5rem;
  transition: background .2s, color .2s;
  touch-action: manipulation;
}

.preview-text {
  font-size: 20px;
  font-weight: 500;
  text-align: center;
  transition: color .2s;
}

@media (min-width: 481px) {
  .preview-text {
    font-size: 22px;
  }
}

.preview-small {
  font-size: 14px;
  margin-top: 6px;
  text-align: center;
  transition: color .2s;
}

/* Ratio Display */
.ratio-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.ratio-badge {
  font-size: 28px;
  font-weight: 500;
  min-width: 80px;
  color: var(--text);
}

@media (min-width: 481px) {
  .ratio-badge {
    font-size: 32px;
    min-width: 90px;
  }
}

.badge-pill {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 500;
  margin: 2px 2px 2px 0;
  display: inline-block;
}

.pass {
  background: var(--success-bg);
  color: var(--success-text);
}

.fail {
  background: var(--danger-bg);
  color: var(--danger-text);
}

.ratio-desc-label {
  font-size: 13px;
  color: var(--text-sec);
  line-height: 1.5;
}

.ratio-desc-label span {
  color: var(--text);
  font-weight: 500;
  display: block;
}

/* Two-Column Layout */
.cols {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 1.5rem;
}

@media (min-width: 481px) {
  .cols {
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }
}

/* Swatch and Color Input */
.swatch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.swatch {
  width: 50px;
  height: 50px;
  border-radius: var(--radius-md);
  border: 0.5px solid var(--border-med);
  flex-shrink: 0;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  min-height: 44px;
  min-width: 44px;
}

.swatch input[type=color] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.hex-input {
  flex: 1;
  padding: 10px 12px;
  font-size: 14px;
  font-family: 'Courier New', monospace;
  border: 0.5px solid var(--border-med);
  border-radius: var(--radius-md);
  background: var(--bg-sec);
  color: var(--text);
  outline: none;
  min-height: 44px;
}

.hex-input:focus {
  box-shadow: 0 0 0 2px var(--info-bg);
  border-color: var(--info-text);
}

/* RGB Sliders */
.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 8px;
  background: var(--bg-sec);
  border-radius: var(--radius-md);
  touch-action: manipulation;
}

.ch-label {
  font-size: 13px;
  color: var(--text-sec);
  width: 20px;
  font-weight: 600;
  flex-shrink: 0;
}

input[type=range] {
  flex: 1;
  height: 12px;
  appearance: none;
  -webkit-appearance: none;
  background: var(--border-med);
  border-radius: 6px;
  outline: none;
  cursor: pointer;
}

input[type=range]:focus {
  outline: 2px solid var(--info-text);
  outline-offset: 2px;
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--border-med);
  cursor: pointer;
}

input[type=range]::-moz-range-thumb {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--bg);
  cursor: pointer;
}

input[type=range]::-moz-range-track {
  background: transparent;
  border: none;
}

.ch-val {
  font-size: 14px;
  font-family: monospace;
  min-width: 35px;
  text-align: right;
  color: var(--text);
  font-weight: 600;
  flex-shrink: 0;
}

/* WCAG Compliance Levels */
.levels-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

@media (min-width: 481px) {
  .levels-row {
    grid-template-columns: repeat(4, 1fr);
  }
}

.level-card {
  background: var(--bg-sec);
  border-radius: var(--radius-md);
  padding: 12px;
}

.lvl-title {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-sec);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.lvl-req {
  font-size: 12px;
  color: var(--text);
  margin-bottom: 6px;
  font-weight: 600;
}

.lvl-status {
  font-size: 13px;
  font-weight: 600;
}

/* Windows Tip Box */
.win-tip {
  background: var(--bg-sec);
  border-left: 3px solid var(--border-str);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-sec);
  line-height: 1.7;
  margin-bottom: 1rem;
}

.win-tip strong {
  color: var(--text);
  font-weight: 500;
}

/* Color Combo Display and Copy */
.combo-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.combo-row label {
  font-size: 13px;
  color: var(--text-sec);
  align-self: center;
}

#colorCombo {
  font-size: 13px;
  font-family: monospace;
  color: var(--text);
  padding: 10px 12px;
  background: var(--bg-sec);
  border-radius: var(--radius-md);
  border: 0.5px solid var(--border-med);
  flex: 1;
  min-width: 150px;
  min-height: 44px;
  display: flex;
  align-items: center;
  word-break: break-all;
}

.copy-btn {
  font-size: 12px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: 0.5px solid var(--border-med);
  background: var(--bg-sec);
  color: var(--text-sec);
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: color .15s, border-color .15s;
  min-height: 44px;
  touch-action: manipulation;
  font-weight: 500;
}

.copy-btn:active {
  background: var(--bg);
}

.copy-btn:hover {
  color: var(--text);
  border-color: var(--border-str);
}

.copy-btn:focus {
  outline: 2px solid var(--info-text);
  outline-offset: 2px;
}

/* Accessible Mode Styles */
.accessible-mode-active .swatch,
.accessible-mode-active input[type=color] {
  display: none;
}

.accessible-mode-active input[type=text],
.accessible-mode-active input[type=number] {
  font-size: 18px;
  padding: 14px;
}

.accessible-mode-active .preview-box {
  min-height: 150px;
}

.accessible-mode-active .preview-text {
  font-size: 28px;
}

@media (min-width: 481px) {
  .accessible-mode-active .preview-text {
    font-size: 32px;
  }
}

.accessible-mode-active .preview-small {
  font-size: 18px;
}

.accessible-mode-active .slider-row {
  padding: 12px;
  gap: 12px;
}

.accessible-mode-active input[type=range] {
  height: 16px;
}

.accessible-mode-active input[type=range]::-webkit-slider-thumb {
  width: 42px;
  height: 42px;
}

.accessible-mode-active input[type=range]::-moz-range-thumb {
  width: 42px;
  height: 42px;
}

.accessible-mode-active .ch-label {
  font-size: 14px;
  width: 24px;
}

.accessible-mode-active .ch-val {
  font-size: 16px;
}

/* Footer */
footer {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 0.5px solid var(--border);
  font-size: 12px;
  color: var(--text-hint);
  text-align: center;
}

footer p {
  margin-bottom: 0.5rem;
  line-height: 1.5;
}

/* Touch Optimization */
@media (hover: none) and (pointer: coarse) {
  input[type=range]::-webkit-slider-thumb {
    width: 36px;
    height: 36px;
  }

  input[type=range]::-moz-range-thumb {
    width: 36px;
    height: 36px;
  }

  button, .cpill {
    touch-action: manipulation;
  }
}

/* Prevent Zoom on Input Focus (mobile) */
@media (max-width: 480px) {
  input[type=text],
  input[type=number],
  select,
  button {
    font-size: 16px;
  }
}
