:root {
  --bg: #f5f6f8; --panel: #ffffff; --ink: #161a24; --muted: #596173; --line: #e0e3ea;
  --accent: #2f5bd3; --accent-ink: #ffffff; --accent-soft: #e9eefc;
  --ok: #157f3b; --ok-soft: #e7f6ec; --warn: #8a5300; --warn-soft: #fff4e0; --bad: #b42318; --bad-soft: #fdecea;
  --flagbg: #eef0f4;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .07);
  --radius: 12px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1117; --panel: #181b24; --ink: #e8eaf1; --muted: #9ba3b6; --line: #2a2f3d;
  --accent: #8fa8ff; --accent-ink: #0f1430; --accent-soft: #212a4a;
  --ok: #4ade80; --ok-soft: #12301d; --warn: #fbbf24; --warn-soft: #33270b; --bad: #f87171; --bad-soft: #3a1414;
  --flagbg: #11141b;
  --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h1 { font-size: 30px; line-height: 1.2; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 10px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; white-space: nowrap; }
.backlink { text-decoration: none; color: var(--muted); }
.backlink:hover { color: var(--ink); }
.sep { color: var(--line); }
.topactions { display: flex; align-items: center; gap: 10px; }
.freebadge { font-size: 12px; color: var(--ok); background: var(--ok-soft); padding: 3px 10px; border-radius: 99px; white-space: nowrap; }

button, select, input, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 14px;
  cursor: pointer; min-height: 38px;
}
button:hover { border-color: var(--accent); }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }
.linkbtn { border: 0; background: none; color: var(--accent); padding: 0; min-height: 0; text-decoration: underline; }
select, input[type="text"], textarea {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 10px; min-height: 38px; width: 100%;
}

.wrap { max-width: 1120px; margin: 0 auto; padding: 24px 20px 40px; }
.hero { margin-bottom: 18px; }
.lede { color: var(--muted); margin: 0 0 14px; font-size: 16px; }
.nameform { position: relative; max-width: 560px; }
.nameform input {
  font-size: 22px; padding: 12px 48px 12px 16px; min-height: 56px; border-radius: 12px; border-width: 2px;
}
.nameform input:focus { border-color: var(--accent); outline: none; }
.clearbtn { position: absolute; right: 6px; top: 8px; min-height: 40px; width: 40px; padding: 0; border: 0; font-size: 22px; color: var(--muted); }
.examples { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 12px; }
.exlabel { color: var(--muted); font-size: 13px; margin-right: 2px; }
.chip { border-radius: 99px; padding: 4px 12px; min-height: 32px; font-size: 14px; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); }

.notice { padding: 10px 14px; border-radius: 10px; margin: 0 0 16px; }
.notice.bad { background: var(--bad-soft); color: var(--bad); }

.emptystate { text-align: center; color: var(--muted); padding: 40px 10px; border: 2px dashed var(--line); border-radius: var(--radius); }
.ghostflag { width: 180px; height: 120px; margin: 0 auto 12px; display: flex; flex-direction: column; border-radius: 6px; overflow: hidden; opacity: .5; }
.ghostflag span { flex: 1; background: var(--line); }
.ghostflag span:nth-child(2) { background: var(--panel); }

.grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.col { display: grid; gap: 18px; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.panelhead { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.flagbox { background: var(--flagbg); border-radius: 10px; padding: 18px; display: flex; justify-content: center; }
.flagbox svg { width: 100%; max-width: 560px; height: auto; display: block; box-shadow: 0 2px 10px rgba(0,0,0,.18); border-radius: 2px; }
.flagbox.square svg { max-width: 340px; }
.desc { margin: 12px 0 8px; color: var(--muted); font-size: 14px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.badge { font-size: 12.5px; padding: 3px 10px; border-radius: 99px; background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.dl { display: flex; gap: 0; }
.dl button { border-radius: 8px 0 0 8px; }
.dl select { width: auto; border-radius: 0 8px 8px 0; border-left: 0; }
.toast { min-height: 1.5em; margin: 8px 0 0; font-size: 13px; color: var(--ok); }

.adjgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 10px; }
.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.field select { color: var(--ink); }
.field.changed span { color: var(--accent); font-weight: 600; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }

.rules { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; counter-reset: r; }
.rules li { display: grid; grid-template-columns: 26px 1fr; gap: 0 10px; counter-increment: r; }
.rules li::before { content: counter(r); grid-row: span 3; width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.rhead { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.rtitle { font-weight: 600; }
.rres { font-size: 13px; background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 1px 8px; }
.rtext { color: var(--muted); font-size: 13.5px; }
.rchanged { font-size: 13px; color: var(--warn); }
.guard { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 13.5px; color: var(--muted); display: grid; gap: 4px; }
.guard strong { color: var(--ink); }

.palette { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.palette li { display: flex; gap: 10px; align-items: center; }
.sw { width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--line); flex: none; padding: 0; min-height: 0; }
.swtext { font-size: 13px; line-height: 1.3; }
.swtext code { font-size: 13px; }
.swtext small { color: var(--muted); }

.tablewrap { overflow-x: auto; max-height: 320px; overflow-y: auto; }
.letters { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
.letters th, .letters td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); }
.letters th { font-size: 12px; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); }
.letters td:nth-child(2) { font-size: 20px; }
.letters td:nth-child(3) { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; color: var(--muted); }

.compare { margin-top: 18px; }
.cmpin { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: start; margin-top: 10px; }
.cmpin textarea { min-height: 100px; resize: vertical; }
.cmpbtns { display: grid; gap: 8px; }
.cmpgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-top: 14px; }
.cmpcard { display: grid; gap: 6px; text-align: left; padding: 8px; border-radius: 10px; background: var(--flagbg); border: 1px solid transparent; }
.cmpcard svg { width: 100%; height: auto; display: block; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.cmpcard span { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.about { margin-top: 26px; color: var(--muted); font-size: 14px; max-width: 760px; }
.about h2 { color: var(--ink); }
.foot { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 18px 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; max-width: 1120px; margin: 0 auto; }

@media (max-width: 860px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .adjgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .wrap { padding: 16px 16px 32px; }
  .topbar { padding: 8px 16px; }
  .freebadge { display: none; }
  h1 { font-size: 25px; }
  .nameform input { font-size: 20px; }
  .flagbox { padding: 10px; }
  .actions > button, .dl { flex: 1 1 100%; }
  .dl button { flex: 1; }
  .cmpin { grid-template-columns: minmax(0, 1fr); }
  .cmpbtns { grid-template-columns: 1fr 1fr; }
  .cmpgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
