:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface2: #eef0f3;
  --text: #16181b;
  --muted: #5d6470;
  --line: #dcdfe5;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --accent-soft: #e3edfd;
  --hover: #f0f3f8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .05);
  --mono: ui-monospace, Menlo, Consolas, "DejaVu Sans Mono", "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twemoji Mozilla", "Segoe UI Symbol", sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a20;
  --surface2: #1f232b;
  --text: #e6e8eb;
  --muted: #9aa3af;
  --line: #2c313a;
  --accent: #5b9dff;
  --accent-ink: #0b0d10;
  --accent-soft: #1b2a44;
  --hover: #222833;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
code, kbd, .mono { font-family: var(--mono); }
code { font-size: .92em; background: var(--surface2); border-radius: 4px; padding: 0 4px; }
kbd { font-size: 12px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--surface); }
.small { font-size: 13px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.row { display: flex; align-items: center; }
.gap { gap: 8px; }
.wrap { flex-wrap: wrap; }

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.primary, .secondary, .ghost { border-radius: 8px; padding: 7px 14px; border: 1px solid var(--line); background: var(--surface); }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.secondary:hover, .ghost:hover { background: var(--hover); }
.ghost { border-color: transparent; background: transparent; }
.primary.small, .secondary.small, .ghost.small { padding: 4px 10px; font-size: 13px; }
.iconbtn { font-size: 18px; line-height: 1; padding: 6px 9px; }
.linkbtn { border: 0; background: none; color: var(--muted); text-decoration: underline; padding: 0 4px; }
select, input[type=search], textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
select { padding: 6px 8px; }

/* header */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.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(--text); }
.sep { color: var(--line); }
.topactions { display: flex; align-items: center; gap: 10px; }
.badge { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; white-space: nowrap; }

main { max-width: 1180px; margin: 0 auto; padding: 0 20px 40px; }
.hero { padding: 22px 0 8px; }
.hero h1 { font-size: 26px; line-height: 1.2; margin: 0 0 6px; letter-spacing: -.01em; }
.lede { margin: 0; color: var(--muted); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 12px 0 14px; }
.tab { border: 0; background: none; padding: 8px 14px; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* search */
.searchbar { display: flex; flex-direction: column; gap: 10px; }
.searchwrap { position: relative; }
.searchicon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%) rotate(-45deg); color: var(--muted); font-size: 18px; pointer-events: none; }
#q { width: 100%; font-size: 18px; padding: 12px 44px 12px 42px; border-radius: 12px; box-shadow: var(--shadow); }
#q::-webkit-search-cancel-button { cursor: pointer; }
.kbdhint { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.controls { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; }
.ctl { display: flex; align-items: center; gap: 8px; }
.ctl-label { font-size: 13px; color: var(--muted); }
.tones { display: flex; gap: 2px; }
.tone { width: 34px; height: 34px; border: 1px solid transparent; background: transparent; border-radius: 8px; font-size: 20px; line-height: 1; padding: 0; font-family: var(--emoji); }
.tone:hover { background: var(--hover); }
.tone[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }

.examples { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 12px 0 4px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 3px 11px; font-size: 13px; }
.chip:hover { background: var(--hover); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.ex { font-family: var(--sans); }

/* strips */
.strip { margin: 10px 0 0; display: flex; flex-direction: column; gap: 6px; }
.striprow { display: flex; align-items: center; gap: 8px; min-width: 0; }
.striplabel { font-size: 12px; color: var(--muted); width: 74px; flex: none; }
.minis { display: flex; gap: 2px; overflow-x: auto; min-width: 0; scrollbar-width: thin; }
.mini { flex: none; width: 36px; height: 36px; border: 0; background: transparent; border-radius: 8px; font-size: 22px; line-height: 1; padding: 0; font-family: var(--emoji); }
.mini:hover { background: var(--hover); }

.cats { display: flex; gap: 6px; overflow-x: auto; padding: 12px 0 4px; scrollbar-width: thin; }
.cats .chip { flex: none; white-space: nowrap; }
.cats .cicon { font-family: var(--emoji); margin-right: 4px; }

.resultsbar { display: flex; gap: 14px; flex-wrap: wrap; align-items: baseline; margin: 8px 0; min-height: 20px; }

/* grid + detail */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px; min-height: 200px;
  align-content: start;
}
.sechead { grid-column: 1 / -1; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 6px 2px; }
.tile {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 2px;
  border: 1px solid transparent; background: transparent; border-radius: 10px; padding: 8px 4px 6px; min-width: 0;
  content-visibility: auto; contain-intrinsic-size: 88px 84px;
}
.tile:hover { background: var(--hover); }
.tile.sel { border-color: var(--accent); background: var(--accent-soft); }
.tile .g { font-size: 34px; line-height: 1.15; font-family: var(--emoji); }
.tile .c { font-size: 11px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); }
.tile.nodraw .g { opacity: .45; }
.tile .newb { font-size: 9px; color: var(--accent); font-weight: 700; letter-spacing: .03em; }
.empty { grid-column: 1 / -1; padding: 30px 10px; text-align: center; color: var(--muted); }
.more { grid-column: 1 / -1; justify-self: center; margin: 8px 0; }

.detail {
  position: sticky; top: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; box-shadow: var(--shadow); max-height: calc(100vh - 24px); overflow: auto;
}
.detail-empty p { margin: 0 0 8px; }
.detail-head { display: flex; gap: 14px; align-items: center; }
.dglyph { font-size: 64px; line-height: 1; font-family: var(--emoji); flex: none; width: 76px; text-align: center; }
.dmeta { min-width: 0; }
.dmeta h2 { font-size: 18px; margin: 0; line-height: 1.25; text-transform: none; }
.dmeta p { margin: 2px 0 8px; }
.closebtn { display: none; }
.dtones { display: flex; gap: 2px; margin: 12px 0 4px; }
.formats { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.fmt { display: grid; grid-template-columns: 96px minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 4px 0; border-top: 1px solid var(--line); }
.fmt:first-child { border-top: 0; }
.fmt .fl { font-size: 12px; color: var(--muted); }
.fmt .fv { font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }
.fmt .fv.big { font-family: var(--emoji); font-size: 22px; }
.fmt .fv.none { color: var(--muted); font-family: var(--sans); font-style: italic; }
.fmt button { padding: 3px 10px; font-size: 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); }
.fmt button:hover { background: var(--hover); }
.aliases { margin: 10px 0 4px; font-family: var(--mono); overflow-wrap: anywhere; }
.tags { margin: 6px 0 0; display: flex; flex-wrap: wrap; gap: 4px; }
.tags .chip { padding: 1px 9px; font-size: 12px; }

/* convert */
.convert { display: flex; flex-direction: column; gap: 10px; max-width: 760px; }
.convert textarea { width: 100%; padding: 10px 12px; font-size: 16px; line-height: 1.5; resize: vertical; font-family: var(--sans), var(--emoji); }
.ctl.inline { gap: 6px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: 14px;
  transition: opacity .15s, transform .15s; z-index: 30; max-width: calc(100vw - 32px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast .tg { font-family: var(--emoji); }

.footer { max-width: 1180px; margin: 0 auto; padding: 18px 20px 30px; display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); }

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .detail { position: fixed; left: 0; right: 0; bottom: 0; top: auto; border-radius: 16px 16px 0 0; max-height: 72vh; z-index: 20; display: none; }
  .detail.open { display: block; }
  .closebtn { display: inline-block; }
}
@media (max-width: 560px) {
  main { padding: 0 16px 40px; }
  .topbar { padding: 8px 16px; }
  .badge { display: none; }
  .hero h1 { font-size: 21px; }
  .lede { font-size: 14px; }
  #q { font-size: 16px; }
  .kbdhint { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); padding: 6px; }
  .tile { contain-intrinsic-size: 64px 74px; padding: 6px 2px 4px; }
  .tile .g { font-size: 30px; }
  .tile .c { font-size: 10px; }
  .controls { gap: 8px 12px; }
  .tone { width: 32px; height: 32px; font-size: 19px; }
  .fmt { grid-template-columns: 84px minmax(0, 1fr) auto; }
}
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
