:root {
  --sky: #a8d4ec;          /* top bar */
  --sky-ink: #12324a;
  --indigo: #5b4fcf;       /* buttons and selected states */
  --indigo-dark: #4639b3;
  --indigo-soft: #ecebfb;
  --frame: #34404d;        /* tool card border */
  --cell: #f2f3f5;         /* palette cells */
  --cell-line: #d6dade;
  --ink-900: #1d232a;
  --ink-700: #3a434d;
  --ink-500: #6a7480;
  --line: #e2e5e9;
  --bg: #ffffff;
  --clin-red: #e74c3c;
  --clin-blue: #3498db;
  --danger: #c0392b;
  --focus: #2f6fbf;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  font: 15px/1.55 var(--font); color: var(--ink-900); background: var(--bg);
}
img, svg, canvas { display: block; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--indigo-dark); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: 12px; top: -48px; z-index: 50; background: #fff; padding: 8px 12px; border-radius: 6px; box-shadow: 0 4px 16px rgba(0, 0, 0, .15); }
.skip-link:focus { top: 12px; }

/* ------------------------------------------------------------------ top bar */
.topbar { background: var(--sky); box-shadow: 0 1px 4px rgba(18, 50, 74, .18); }
.topbar__inner {
  max-width: 1100px; margin: 0 auto; padding: 9px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  color: var(--sky-ink);
}
.topbar__brand { font-size: 14px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; }
.topbar__note { font-size: 13px; }

/* --------------------------------------------------------------------- page */
.page { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 44px 16px 48px; }
.intro { text-align: center; margin: 0 auto 34px; max-width: 680px; }
.intro h1 { margin: 0 0 10px; font-size: clamp(26px, 4vw, 34px); font-weight: 400; line-height: 1.25; color: var(--ink-900); }
.intro p { margin: 0; color: var(--ink-500); }

/* --------------------------------------------------------------------- tool */
.tool { max-width: 720px; margin: 0 auto; }
.tool:focus { outline: none; }
.tool__tabs { display: flex; gap: 10px; padding-left: 12px; }
.tab {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  border: 0; background: var(--indigo); color: #fff;
  font-weight: 700; font-size: 14px; padding: 10px 20px 9px;
  border-radius: 10px 10px 0 0; box-shadow: 0 -1px 6px rgba(91, 79, 207, .25);
  transition: background-color .12s;
}
.tab:hover { background: var(--indigo-dark); }
.tab[aria-busy="true"] { opacity: .75; cursor: progress; }

.tool__card {
  background: #fff; border: 2px solid var(--frame); border-radius: 14px;
  box-shadow: 0 10px 28px rgba(29, 35, 42, .16); padding: 14px 14px 12px;
}

/* palette: 6 columns in the reference order */
.palette {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 3px;
  max-width: 600px; margin: 0 auto;
}
.palette__btn {
  display: flex; align-items: center; justify-content: center; min-height: 26px;
  padding: 3px 4px; cursor: pointer; text-align: center; line-height: 1.15;
  font-size: 11.5px; font-weight: 700; color: #3c4650;
  background: var(--cell); border: 1px solid var(--cell-line); border-radius: 3px;
  transition: background-color .1s, color .1s, border-color .1s;
}
.palette__btn:hover { background: #e4e7eb; color: var(--ink-900); }
.palette__btn[aria-pressed="true"] { background: var(--indigo); border-color: var(--indigo); color: #fff; }

.hint {
  max-width: 600px; margin: 8px auto 0; min-height: 30px; padding: 4px 10px; border-radius: 6px;
  color: var(--ink-500); font-size: 12.5px; text-align: center;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 12px;
}
.hint b { color: var(--ink-900); }
.hint.is-active, .hint.is-red { background: var(--indigo-soft); color: var(--ink-700); }
.hint__text { flex: 0 1 auto; }
.hint__option { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; color: var(--ink-700); }

.tool__bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 2px 8px; }
.segmented { display: inline-flex; gap: 4px; }
.segmented__btn {
  min-width: 56px; padding: 4px 14px; cursor: pointer; border-radius: 3px;
  border: 1px solid var(--cell-line); background: #fff;
  font-weight: 700; font-size: 12.5px; color: var(--ink-700);
}
.segmented__btn:hover { background: var(--cell); }
.segmented__btn[aria-checked="true"] { background: var(--indigo); border-color: var(--indigo); color: #fff; }
.segmented--small .segmented__btn { min-width: 0; padding: 2px 10px; font-size: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
  padding: 4px 12px; border-radius: 3px; border: 1px solid transparent;
  font-weight: 700; font-size: 12.5px; line-height: 1.4;
}
.btn--quiet { background: var(--cell); border-color: var(--cell-line); color: var(--ink-700); }
.btn--quiet:hover { background: #e4e7eb; color: var(--ink-900); }
.btn--primary { background: var(--indigo); color: #fff; }
.btn--primary:hover { background: var(--indigo-dark); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { background: #a93226; }
.dialog .btn { padding: 7px 16px; font-size: 14px; border-radius: 6px; }

.chart { background: #fff; }
.chart canvas { width: 100%; height: auto; touch-action: manipulation; cursor: pointer; }
.chart canvas:focus-visible { outline-offset: -3px; }

/* ------------------------------------------------------------------ article */
.article { max-width: 870px; margin: 64px auto 0; }
.article h2 { font-size: 26px; font-weight: 400; line-height: 1.3; margin: 0 0 12px; }
.article h3 { font-size: 20px; font-weight: 600; margin: 34px 0 8px; color: var(--ink-900); }
.article h4 { font-size: 16px; font-weight: 700; margin: 0 0 6px; color: var(--indigo-dark); }
.article p { margin: 0 0 12px; color: var(--ink-700); }
.article__lead { color: var(--ink-500) !important; }
.list { margin: 0 0 12px; padding: 0; list-style: none; display: grid; gap: 8px; }
.list li { position: relative; padding-left: 22px; color: var(--ink-700); }
.list li::before {
  content: ""; position: absolute; left: 4px; top: .62em; width: 8px; height: 8px;
  border-radius: 50%; background: var(--indigo);
}
.list b { color: var(--ink-900); }
.card {
  background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--indigo);
  border-radius: 0 10px 10px 0; padding: 14px 16px 4px; margin: 0 0 14px;
  box-shadow: 0 2px 10px rgba(29, 35, 42, .06);
}
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-2 .card { margin: 0; }

.footer { margin-top: 56px; background: #f4f6f8; border-top: 1px solid var(--line); padding: 18px 16px; text-align: center; font-size: 13px; color: var(--ink-700); }
.footer p { margin: 2px 0; }
.footer__small { font-size: 12px; color: var(--ink-500); }

/* ------------------------------------------------------------------ dialogs */
.dialog {
  border: 0; padding: 0; border-radius: 14px; box-shadow: 0 18px 50px rgba(0, 0, 0, .25);
  width: min(460px, calc(100vw - 32px)); color: var(--ink-900);
}
.dialog--small { width: min(360px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(20, 24, 30, .5); }
.dialog__form { padding: 20px 22px 18px; display: grid; gap: 12px; }
.dialog__title { margin: 0; font-size: 18px; }
.dialog__sub { margin: -6px 0 0; color: var(--ink-500); font-size: 13.5px; }
.dialog__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.field { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--ink-700); }
.field input, .field textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #c9ced4; border-radius: 6px;
  font-weight: 400; font-size: 14.5px; background: #fff;
}
.field textarea { resize: vertical; }
.field input:focus, .field textarea:focus { outline: 2px solid var(--indigo); outline-offset: 0; border-color: var(--indigo); }
.field-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.field__code { font-size: 22px !important; font-weight: 700 !important; letter-spacing: .2em; text-transform: uppercase; text-align: center; }

/* ------------------------------------------------------------------- toasts */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 10px;
  background: var(--ink-900); color: #fff; font-size: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  animation: toast-in .18s ease-out;
}
.toast--error { background: var(--danger); }
.toast.is-leaving { opacity: 0; transition: opacity .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ------------------------------------------------------------------- mobile */
@media (max-width: 640px) {
  .topbar__note { display: none; }
  .page { padding-top: 28px; }
  .intro { margin-bottom: 24px; }
  .palette { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .palette__btn { min-height: 32px; font-size: 12px; }
  .tool__card { padding: 10px 8px; border-radius: 12px; }
  .tool__tabs { padding-left: 8px; }
  .field-row { grid-template-columns: minmax(0, 1fr); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .article { margin-top: 44px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
