:root {
    color-scheme: light dark;
    --bg:#fff; --fg:#111; --mut:#6b7280; --dim:#f3f4f6; --br:#e5e7eb; --active: #60a5fa2b;
}
@media (prefers-color-scheme: dark){
    :root { --bg:#0b1220; --fg:#e5e7eb; --mut:#9ca3af; --dim:#111827; --br:#374151; }
}
/* explicit override by class */
.theme-light { 
    color-scheme: light; 
    --bg:#fff; --fg:#111; --mut:#6b7280; --dim:#f3f4f6; --br:#e5e7eb; 
}
.theme-dark  { 
    color-scheme: dark;
    --bg:#0b1220; --fg:#e5e7eb; --mut:#9ca3af; --dim:#111827; --br:#374151; 
}

html, body { margin:0; padding:0; background:var(--bg); color:var(--fg);
    font:14px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Inter, sans-serif; }

.hdr { position:sticky; top:0; background:var(--bg); padding:10px 10px 6px; border-bottom:1px solid var(--br); z-index: 9;}
.ttl { margin:0 0 8px; font-size:16px; font-weight:700; }
.bar { display:flex; gap:6px; }
.inp { flex:1; padding:8px 8px; border:1px solid var(--br); border-radius:8px; background:var(--bg); color:var(--fg); }
/* buttons */
.btn { padding:8px 10px; border:1px solid var(--br); border-radius:8px; background:var(--dim); cursor:pointer; }
.btn:hover { filter: brightness(0.98); }
.btn.icon { width:36px; height:36px; display:grid; place-items:center; padding:0; }

/* disabled buttons (e.g., Load more) */
.btn[disabled] { opacity:.55; cursor:not-allowed; }

.filters { display:grid; grid-template-columns:1fr 1fr; gap:6px; padding:8px 10px; border-bottom:1px solid var(--br); }
.grid { display:grid; grid-template-columns:repeat(4, minmax(0, 1fr)); gap:8px; padding:10px; }

.card {
    display:flex; flex-direction:column; align-items:center; justify-content:center;
    gap:6px; padding:10px; border:1px solid var(--br); border-radius:12px; background:var(--bg);
    cursor: pointer;
}
.card .emo { font-size:28px; line-height:1; }
.card .nm  { font-size:12px; color:var(--mut); text-align:center; max-width:100%;
    white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

.ft { display:flex; align-items:center; justify-content: space-between; gap:8px; padding:10px; border-top:1px solid var(--br);
    position:sticky; bottom:0; background:var(--bg); }
.muted { color:var(--mut); }
.nowrap { white-space: nowrap; }

/* Toast */
.toast {
    position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%);
    background: var(--dim); color: var(--fg); padding: 8px 12px; border-radius: 8px;
    border:1px solid var(--br); opacity: 0; pointer-events:none; transition: opacity .18s ease;
}
.toast.show { opacity: 1; }

.sel {
    padding: 8px 10px;
    border: 1px solid var(--br);
    border-radius: 8px;
    background: var(--bg);
    color: var(--fg);
    appearance: none;           /* cleaner look */
    background-image:
      linear-gradient(45deg, transparent 50%, var(--mut) 50%),
      linear-gradient(135deg, var(--mut) 50%, transparent 50%);
    background-position:
      calc(100% - 18px) calc(50% - 3px),
      calc(100% - 12px) calc(50% - 3px);
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
  }
  .sel:disabled { opacity: .6; }
  .badge {
    padding:2px 8px; border-radius:9999px; font-size:11px; line-height:1.6;
    background: var(--dim); color: var(--fg); border:1px solid var(--br);
  }

  /* Backdrop + Sheet (modal) */
.backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.35);
    z-index: 80; opacity: 0; transition: opacity .18s ease;
  }
  .backdrop.show { opacity: 1; }
  
  .sheet {
    position: fixed; right: 12px; bottom: 12px; left: 12px; max-width: 520px;
    margin: 0 auto; z-index: 81; background: var(--bg); color: var(--fg);
    border: 1px solid var(--br); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.25);
    transform: translateY(8px); opacity: 0; transition: transform .18s ease, opacity .18s ease;
  }
  .sheet.show { transform: translateY(0); opacity: 1; }
  .sheet-head { display:flex; align-items:center; justify-content:space-between; padding:12px; border-bottom:1px solid var(--br); border-radius: inherit}
  .sheet-body { padding:12px; display:grid; gap:14px; }
  .field .lbl { display:block; font-weight:600; margin-bottom:6px; }
  .field .hint { margin-top:6px; font-size:12px; }
  .row { display:flex; gap:8px; }
  
  /* Radios */
  .radios { display:grid; gap:8px; }
  .radio { display:flex; align-items:center; gap:8px; padding:8px; border:1px solid var(--br); border-radius:8px; background: var(--bg); }
  .radio input[type="radio"] { accent-color: #3b82f6; }
  .radio[aria-disabled="true"] { opacity:.55; }
  
  .tag {
    margin-left:auto; font-size:11px; padding:2px 8px; border-radius:9999px;
    border:1px solid var(--br); background: var(--dim); color: var(--fg);
  }
  
  /* Badge (version) already exists — keep it; this is just a reminder */
  .badge { padding:2px 8px; border-radius:9999px; font-size:11px; line-height:1.6;
    background: var(--dim); color: var(--fg); border:1px solid var(--br); }
  
  /* Buttons & inputs already set; ensure icon buttons look good */
  .btn.icon { width:36px; height:36px; display:grid; place-items:center; padding:0; }
  .btn[disabled] { opacity:.55; cursor:not-allowed; }

  .diagbox {
    margin-top: 8px;
    padding: 10px;
    border: 1px dashed var(--br);
    border-radius: 8px;
    background: var(--dim);
    color: var(--fg);
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-word;
}

/* apply to the glyph container you use */
.emo, .emo * {
  font-family:
    "Segoe UI Emoji", "Noto Color Emoji", "Apple Color Emoji",
    "Twemoji Mozilla", "EmojiOne Color", "Segoe UI Symbol",
    system-ui, sans-serif !important;
  font-variant-emoji: emoji;
  line-height: 1;
}
.emo img {
  width: 1em;
  height: 1em;
  display: block;
}

#dewemoji-status {
  float: right;
}
/* Settings tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--br);
  margin-bottom: 12px;
}
.tab {
  flex: 1;
  padding: 8px;
  text-align: center;
  cursor: pointer;
  background: var(--dim);
  border: 1px solid var(--br);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  font-weight: 600;
}
.tab:not(.active) {
  opacity: 0.6;
}
.tab.active {
  background: var(--bg);
  color: var(--fg);
  opacity: 1;
}
.tabpane { display: none; }
.tabpane.active { display: block; }

/* Tone palette theming */
.theme-light, :root.theme-light {
  --c-bg: var(--bg, #ffffff);
  --c-chip: var(--dim, #f3f4f6);
  --c-border: var(--br, #e5e7eb);
}
.theme-dark, :root.theme-dark {
  --c-bg: var(--bg, #0f172a);
  --c-chip: var(--dim, #111827);
  --c-border: var(--br, #374151);
}

/* Accent color for focus/selection rings */
.theme-light, :root.theme-light { --accent: #3b82f6; }
.theme-dark,  :root.theme-dark  { --accent: #60a5fa; }

/* Tone palette buttons (popover + settings) */
.tone-btn, .tone-chip {
  border: 1px solid var(--c-border);
  background: var(--c-chip);
}
.tone-btn.selected, .tone-chip.selected {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px var(--accent) !important;
}
.tone-btn:focus-visible, .tone-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ===== Settings sheet polish ===== */
.sheet { max-width: 540px; }
.sheet-head {
  position: sticky; top: 0; background: var(--bg);
  z-index: 2; border-bottom: 1px solid var(--br);
}
.sheet-head h3 { margin: 0; }

.sheet-body { padding-top: 10px; }
.field { margin: 12px 0 16px; }
.field .lbl { display: block; font-weight: 600; margin-bottom: 6px; }

/* Compact rows */
.row {
  display: grid;
  grid-template-columns: 1fr auto auto; /* input | Activate | Deactivate */
  gap: 8px;
  align-items: center;
}
.row + .row { margin-top: 6px; }

/* Inputs and small buttons */
.inp { padding: 6px 10px; }
.btn.sm { padding: 6px 10px; font-size: 12px; line-height: 1; }
.btn.ghost { background: transparent; border: 1px solid var(--br); }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }
.link:hover { text-decoration: underline; }

/* Tabs = segmented control */
.tabs {
  background: var(--dim); padding: 4px; border-radius: 10px;
  display: inline-flex; gap: 4px; border: 1px solid var(--br);
  margin-bottom: 12px;
}
.tab { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-weight: 600; }
.tab.active { background: var(--bg); box-shadow: inset 0 0 0 1px var(--br); }

/* License subtext wraps neatly */
#license-status { display: inline-block; margin-left: 8px; }

/* Tone palette spacin.g + buttons */
.tone-palette { display: flex; gap: 8px; flex-wrap: wrap; }
.tone-chip {
  min-width: 40px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; border: 1px solid var(--c-border); background: var(--c-chip);
}
.tone-chip.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

/* Toast a tad higher so it doesn’t overlap sheet */
.toast { bottom: 18px; }

/* Make the top controls a proper stacking context above the grid */
.topbar, .filters-row {
  position: sticky; /* or relative if not sticky */
  z-index: 5;
  background: var(--c-bg, #0f172a); /* ensure it has a solid bg in dark & light */
}

/* Or ensure the select dropdown sits above adjacent icons */
select#sub {
  position: relative;
  z-index: 6;
}

div.card.active {
  background-color: var(--active)!important;
}

.tone-row {
  grid-column: 1 / -1;
  background-color: var(--active);
  border: 1px solid var(--c-border, rgba(0, 0, 0, .12));
  border-radius: 12px;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0px, 1fr));
  gap: 6px;
  align-items: center;
}

.tone-option {
  height: 56px;
    border-radius: 10px;
    border: 1px solid var(--c-border, rgba(0, 0, 0, .12));
    background: var(--c-bg, #f3f4f6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: x-large;
}

/* ===== APK companion overrides (extension-like, denser) ===== */
html {
  min-height: 100%;
}

body {
  height: auto;
  min-height: 100%;
  padding-top: max(0px, env(safe-area-inset-top));
  padding-bottom: max(0px, env(safe-area-inset-bottom));
}

.hdr {
  padding-top: calc(10px + env(safe-area-inset-top) * 0.25);
}

.grid {
  grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
  gap: 6px;
  align-content: start;
  min-height: calc(100vh - 170px);
  background: var(--bg);
}

body.overlay-mode .grid {
  min-height: 0;
}

html.overlay-mode,
body.overlay-mode {
  min-height: 0;
  height: auto;
}

body.overlay-mode {
  padding-top: 0;
  padding-bottom: 0;
}

body.overlay-mode .hdr,
body.overlay-mode .ft {
  position: static;
}

body.overlay-mode #theme {
  display: none !important;
}

body.overlay-mode #settings-sheet,
body.overlay-mode #sheet-backdrop {
  display: none !important;
}

body.overlay-mode {
  font-size: 15px;
}

body.overlay-mode .bar {
  gap: 8px;
}

body.overlay-mode .filters {
  gap: 8px;
  padding: 10px 12px;
}

body.overlay-mode .inp,
body.overlay-mode .sel {
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 16px;
  line-height: 1.2;
}

body.overlay-mode .btn {
  min-height: 46px;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.2;
}

body.overlay-mode .btn.icon {
  width: 46px;
  height: 46px;
  min-height: 46px;
  padding: 0;
  font-size: 18px;
}

body.overlay-mode .btn.w {
  min-width: 124px;
}

body.overlay-mode .ft {
  padding: 12px;
  gap: 10px;
}

body.overlay-mode .sheet {
  left: 8px;
  right: 8px;
  bottom: 8px;
  max-width: none;
  border-radius: 16px;
  box-shadow: 0 16px 44px rgba(0,0,0,.28);
}

body.overlay-mode .sheet-head {
  padding: 14px;
}

body.overlay-mode .sheet-head h3 {
  font-size: 20px;
}

body.overlay-mode .sheet-body {
  padding: 14px;
  gap: 16px;
}

body.overlay-mode .field {
  margin: 14px 0 18px;
}

body.overlay-mode .field .lbl {
  margin-bottom: 8px;
}

body.overlay-mode .field .hint,
body.overlay-mode .diagbox,
body.overlay-mode .muted {
  font-size: 13px;
  line-height: 1.35;
}

body.overlay-mode .diagbox {
  padding: 12px;
  border-radius: 10px;
}

body.overlay-mode .row,
body.overlay-mode .row-inline,
body.overlay-mode .row-wrap {
  gap: 10px;
}

body.overlay-mode .row-inline {
  align-items: stretch;
}

body.overlay-mode .row-wrap .btn,
body.overlay-mode .row-inline .btn {
  min-height: 46px;
}

body.overlay-mode #account-connect-form .row-block .inp,
body.overlay-mode #account-connected .row-inline .btn {
  min-height: 50px;
}

body.overlay-mode .tabs {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 5px;
  border-radius: 12px;
}

body.overlay-mode .tab {
  min-height: 44px;
  padding: 10px 8px;
  border-radius: 10px;
  font-size: 15px;
}

body.overlay-mode .radio {
  min-height: 44px;
  padding: 10px;
  border-radius: 10px;
}

body.overlay-mode .tone-pref-group {
  gap: 10px;
}

body.overlay-mode .tone-swatch {
  width: 42px;
  height: 42px;
}

body.overlay-mode .tone-circle {
  width: 28px;
  height: 28px;
}

body.overlay-mode .bubble-grid {
  gap: 10px;
}

body.overlay-mode .bubble-kv {
  padding: 10px;
  border-radius: 10px;
}

body.overlay-mode .bubble-kv > span:last-child {
  font-size: 14px;
}

body.overlay-mode .tone-row {
  gap: 8px;
  padding: 8px;
}

body.overlay-mode .tone-option {
  min-height: 48px;
  font-size: 24px;
}

@media (pointer: coarse), (max-width: 900px) {
  body:not(.overlay-mode) .inp,
  body:not(.overlay-mode) .sel {
    min-height: 46px;
    padding: 10px 12px;
    border-radius: 12px;
    font-size: 16px;
    line-height: 1.2;
  }

  body:not(.overlay-mode) .btn {
    min-height: 44px;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.2;
  }

  body:not(.overlay-mode) .btn.icon {
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    font-size: 18px;
  }

  body:not(.overlay-mode) .filters {
    gap: 8px;
    padding: 10px 10px;
  }

  body:not(.overlay-mode) .bar {
    gap: 8px;
  }

  body:not(.overlay-mode) .ft {
    gap: 10px;
    padding: 12px 10px;
  }

  body:not(.overlay-mode) .sheet {
    border-radius: 14px;
  }

  body:not(.overlay-mode) .sheet-head {
    padding: 14px;
  }

  body:not(.overlay-mode) .sheet-head h3 {
    font-size: 20px;
  }

  body:not(.overlay-mode) .sheet-body {
    padding: 14px;
    gap: 16px;
  }

  body:not(.overlay-mode) .field {
    margin: 14px 0 18px;
  }

  body:not(.overlay-mode) .row,
  body:not(.overlay-mode) .row-inline,
  body:not(.overlay-mode) .row-wrap {
    gap: 10px;
  }

  body:not(.overlay-mode) .row-inline {
    align-items: stretch;
  }

  body:not(.overlay-mode) .tabs {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding: 5px;
    border-radius: 12px;
  }

  body:not(.overlay-mode) .tab {
    min-height: 44px;
    padding: 10px 8px;
    border-radius: 10px;
    font-size: 15px;
  }

  body:not(.overlay-mode) .radio {
    min-height: 44px;
    padding: 10px;
    border-radius: 10px;
  }

  body:not(.overlay-mode) #account-connect-form .row-block .inp,
  body:not(.overlay-mode) #account-connected .row-inline .btn {
    min-height: 50px;
  }

  body:not(.overlay-mode) .bubble-kv {
    padding: 10px;
    border-radius: 10px;
  }
}

.card {
  min-height: 72px;
  padding: 8px 6px;
  gap: 4px;
  border-radius: 10px;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.card * {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.card .emo {
  font-size: 24px;
}

.card .nm {
  font-size: 10px;
  line-height: 1.15;
  max-width: 100%;
}

body.emoji-names-hidden .card {
  min-height: 58px;
  gap: 2px;
  padding-top: 7px;
  padding-bottom: 7px;
}

body.emoji-names-hidden .card .nm {
  display: none;
}

body.emoji-names-hidden .card .emo {
  font-size: 28px;
}

.btn.w {
  min-width: 110px;
}

.ft {
  padding-bottom: calc(10px + env(safe-area-inset-bottom) * 0.5);
  background: var(--bg);
}

.sheet {
  bottom: calc(12px + env(safe-area-inset-bottom));
}

.row-inline {
  display: flex;
  grid-template-columns: none;
  align-items: center;
}

.row-wrap {
  display: flex;
  grid-template-columns: none;
  flex-wrap: wrap;
}

.row-block {
  display: block;
  grid-template-columns: none;
}

.row-block .inp {
  width: 100%;
}

.diagbox {
  margin-top: 8px;
  padding: 10px;
  border: 1px dashed var(--br);
  border-radius: 8px;
  background: var(--dim);
  color: var(--fg);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.tone-pref-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.tone-swatch {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  cursor: pointer;
}

.tone-swatch input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}

.tone-circle {
  display: block;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid var(--br);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}

.tone-default {
  background:
    radial-gradient(circle at 50% 50%, transparent 0 28%, rgba(255,255,255,.7) 29% 34%, transparent 35%),
    linear-gradient(180deg, #d7e0eb 0%, #a4b2c3 100%);
}

.tone-1 { background: #f7d7c4; }
.tone-2 { background: #e8bf95; }
.tone-3 { background: #c68642; }
.tone-4 { background: #8d5524; }
.tone-5 { background: #5e3b22; }

.tone-swatch input:checked + .tone-circle {
  outline: 2px solid #60a5fa;
  outline-offset: 2px;
  border-color: #60a5fa;
}

.tone-swatch input:focus-visible + .tone-circle {
  outline: 2px solid #60a5fa;
  outline-offset: 2px;
}

.bubble-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 8px 0 10px;
}

.bubble-kv {
  display: grid;
  gap: 4px;
  border: 1px solid var(--br);
  background: var(--bg);
  border-radius: 8px;
  padding: 8px;
  min-width: 0;
}

.bubble-kv > span:last-child {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bubble-kv .ok { color: #059669; }
.bubble-kv .warn { color: #d97706; }
.bubble-kv .bad { color: #dc2626; }

.alert {
  grid-column: 1 / -1;
  border: 1px solid var(--br);
  background: var(--dim);
  border-radius: 12px;
  padding: 10px;
}

.alert strong {
  display: block;
  margin-bottom: 2px;
}

.alert.error {
  border-color: rgba(220, 38, 38, .35);
}

.alert.warn {
  border-color: rgba(217, 119, 6, .35);
}

.autoload-sentinel {
  width: 100%;
  height: 1px;
}

.card.private {
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, .35);
}

.card.private .nm::after {
  content: " · private";
  color: #3b82f6;
}

.card.toneable::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 5px;
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: #60a5fa;
  opacity: 0.9;
}

.tone-row {
  grid-column: 1 / -1;
  border: 1px solid var(--br);
  background: var(--dim);
  border-radius: 12px;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  align-items: center;
}

.tone-option {
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid var(--br);
  background: var(--bg);
  color: var(--fg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.tone-option.selected {
  box-shadow: inset 0 0 0 2px #60a5fa;
  border-color: #60a5fa;
}

.tone-option.label {
  font-size: 12px;
  font-weight: 600;
}

.tone-note {
  grid-column: 1 / -1;
  font-size: 12px;
  color: var(--mut);
  padding: 2px 2px 0;
}

@media (max-width: 640px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 5px;
    padding: 8px;
  }

  .card {
    min-height: 64px;
    padding: 6px 4px;
  }

  .card .emo {
    font-size: 22px;
  }

  .card .nm {
    font-size: 9px;
  }

  body.emoji-names-hidden .card {
    min-height: 52px;
    padding-top: 6px;
    padding-bottom: 6px;
  }

  body.emoji-names-hidden .card .emo {
    font-size: 25px;
  }

  .bubble-grid {
    grid-template-columns: 1fr;
  }

  .tone-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .tabs {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .tab {
    width: 100%;
    text-align: center;
  }
}

@media (max-width: 420px) {
  .card {
    min-height: 54px;
    gap: 2px;
  }

  .card .emo {
    font-size: 20px;
  }

  .card .nm {
    font-size: 8px;
  }

  body.emoji-names-hidden .card .emo {
    font-size: 24px;
  }

  .tone-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    padding: 6px;
  }

  .tone-option {
    min-height: 38px;
    font-size: 20px;
  }
}
