/* Hub — quiet, classic, light & dark */

:root {
  --bg: #f6f4ef;
  --surface: #fffdf9;
  --ink: #26241f;
  --muted: #7b756b;
  --faint: #a8a196;
  --line: #e5e0d6;
  --hover: #ece8df;
  --accent: #3d5a7a;
  --accent-ink: #ffffff;
  --shadow: 0 1px 2px rgba(40, 32, 20, .06), 0 8px 28px rgba(40, 32, 20, .10);
  --tile-l: 91%;
  --tile-s: 32%;
  --tile-ink-l: 34%;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1917;
    --surface: #23221f;
    --ink: #ebe7df;
    --muted: #9d968a;
    --faint: #6f695f;
    --line: #34322d;
    --hover: #2a2926;
    --accent: #a9c1db;
    --accent-ink: #1a1917;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .45);
    --tile-l: 24%;
    --tile-s: 16%;
    --tile-ink-l: 78%;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1a1917;
  --surface: #23221f;
  --ink: #ebe7df;
  --muted: #9d968a;
  --faint: #6f695f;
  --line: #34322d;
  --hover: #2a2926;
  --accent: #a9c1db;
  --accent-ink: #1a1917;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .45);
  --tile-l: 24%;
  --tile-s: 16%;
  --tile-ink-l: 78%;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

button { font: inherit; color: inherit; }

.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 48px max(16px, env(safe-area-inset-left));
}
@media (min-width: 720px) { .page { padding-left: 32px; padding-right: 32px; padding-top: 36px; } }

/* ---------- Header ---------- */
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.today { font-family: var(--serif); font-weight: 400; font-size: 26px; line-height: 1.15; margin: 0; letter-spacing: -.005em; }
@media (min-width: 720px) { .today { font-size: 32px; } }
.weather { margin: 4px 0 0; color: var(--muted); font-size: 14px; min-height: 1.45em; }
.top-right { display: flex; align-items: center; gap: 6px; padding-top: 2px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 999px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--ink); }

.profile-wrap { position: relative; }
.profile-btn {
  display: inline-flex; align-items: center; gap: 4px;
  height: 36px; padding: 0 10px 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 14px;
}
.profile-btn:hover { border-color: var(--faint); }
.profile-btn .chev { width: 16px; height: 16px; color: var(--muted); }

.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  min-width: 220px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border: 0; border-radius: 8px; background: transparent; text-align: left; cursor: pointer;
}
.menu button:hover, .menu button:focus-visible { background: var(--hover); outline: none; }
.menu .m-text { flex: 1; display: flex; flex-direction: column; }
.menu .m-sub { color: var(--muted); font-size: 12.5px; }
.menu .m-check { width: 16px; height: 16px; color: var(--accent); }
.menu .m-lock { width: 15px; height: 15px; color: var(--faint); }

/* ---------- Search ---------- */
.search-bar {
  position: sticky; top: 0; z-index: 10;
  margin: 0 -16px 8px; padding: 8px 16px 10px;
  background: var(--bg);
}
@media (min-width: 720px) { .search-bar { margin: 0 -32px 8px; padding: 10px 32px 12px; } }
.search-form { width: 100%; position: relative; }
.search {
  display: flex; align-items: center; gap: 8px;
  height: 46px; padding: 0 10px 0 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  color: var(--muted);
}
.engine-picker-wrap { position: relative; display: flex; align-items: center; }
.engine-picker-btn {
  display: inline-flex; align-items: center; gap: 4px;
  height: 32px; padding: 0 6px 0 8px;
  border: 1px solid transparent; border-radius: 8px;
  background: var(--hover); cursor: pointer; color: var(--ink);
  flex-shrink: 0; transition: background .12s, border-color .12s;
}
.engine-picker-btn:hover { background: var(--line); }
.engine-picker-btn .current-engine-icon svg { width: 18px; height: 18px; display: block; }
.engine-picker-btn .chev { width: 14px; height: 14px; color: var(--muted); }
.engine-dropdown {
  position: absolute; left: 0; top: calc(100% + 6px); z-index: 30;
  width: max-content; min-width: 280px; max-width: 340px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.engine-dropdown button {
  display: flex; align-items: flex-start; gap: 10px; width: 100%;
  padding: 8px 10px; border: 0; border-radius: 8px; background: transparent; text-align: left; cursor: pointer;
  color: var(--ink);
}
.engine-dropdown button:hover, .engine-dropdown button:focus-visible { background: var(--hover); outline: none; }
.engine-dropdown .ed-icon { width: 20px; height: 20px; flex-shrink: 0; margin-top: 1px; }
.engine-dropdown .ed-icon svg { width: 20px; height: 20px; display: block; }
.engine-dropdown .ed-info { flex: 1; min-width: 0; }
.engine-dropdown .ed-name { font-size: 13.5px; font-weight: 600; display: block; color: var(--ink); }
.engine-dropdown .ed-tag { font-size: 12px; color: var(--muted); margin-top: 2px; display: block; line-height: 1.35; }
.engine-dropdown .ed-check { width: 16px; height: 16px; color: var(--accent); flex-shrink: 0; align-self: center; }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.search input {
  flex: 1; min-width: 0; height: 100%;
  border: 0; outline: 0; background: transparent; color: var(--ink);
  font: inherit; font-size: 16px; /* 16px stops iOS zoom */
}
.search input::placeholder { color: var(--faint); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-hint {
  font-family: var(--sans); font-size: 12px; color: var(--faint);
  border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px;
}
@media (hover: none) { .search-hint { display: none; } }

/* ---------- Web Search Strip ---------- */
.search-engines {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  margin-top: 8px; padding: 6px 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  font-size: 13px; animation: fade .12s ease;
}
.engine-main-btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 32px; padding: 4px 10px;
  border: 0; border-radius: 7px; background: transparent; color: var(--ink); text-decoration: none;
  cursor: pointer; font-size: 13px; font-family: inherit; text-align: left;
  flex: 1; min-width: 200px; transition: background .12s ease;
}
.engine-main-btn:hover { background: var(--hover); }
.engine-main-icon svg, .engine-toggle-icon svg, .fallback-card-icon svg { width: 18px; height: 18px; display: block; }
.engine-main-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.engine-main-text strong { font-weight: 600; color: var(--ink); }
.engine-query-text { color: var(--accent); }
.engine-main-key {
  font-family: var(--sans); font-size: 11px; color: var(--faint);
  border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; line-height: 1.4; margin-left: auto;
}
.engine-switch-wrap { display: inline-flex; align-items: center; gap: 4px; }
.engine-toggle-btn {
  display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 8px;
  border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 12px; font-family: inherit;
  transition: background .12s, color .12s, border-color .12s;
}
.engine-toggle-btn:hover { background: var(--hover); color: var(--ink); }
.engine-toggle-btn.is-active {
  background: var(--hover); border-color: var(--line); color: var(--ink); font-weight: 500;
}

/* ---------- Sections ---------- */
.section { margin-top: 18px; }
.section-head {
  display: flex; align-items: baseline; gap: 8px; width: 100%;
  padding: 6px 0; margin: 0 0 4px;
  border: 0; border-bottom: 1px solid var(--line); background: none; cursor: pointer; text-align: left;
}
.section-head.static { cursor: default; }
.section-title { font-family: var(--serif); font-size: 19px; font-weight: 400; margin: 0; }
.section-count { color: var(--faint); font-size: 13px; }
.section-head .chev { margin-left: auto; width: 16px; height: 16px; color: var(--faint); transition: transform .15s ease; align-self: center; }
.section.collapsed .chev { transform: rotate(-90deg); }
.section.collapsed .grid { display: none; }

/* ---------- Tiles ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 4px;
  padding-top: 8px;
}
@media (max-width: 419px) { .tile-name { font-size: 12.5px; } .grid { gap: 2px; } }
@media (min-width: 720px) { .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 6px; } }

.tile { position: relative; }
.tile-link {
  display: flex; min-width: 0; flex-direction: column; align-items: center; gap: 7px;
  padding: 10px 4px 9px; border-radius: 12px;
  color: var(--ink); text-decoration: none; text-align: center;
}
.tile-link:hover { background: var(--hover); }
.tile-link:focus-visible, .tile.active .tile-link { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--hover); }
.tile-name {
  font-size: 13px; line-height: 1.25; max-width: 100%;
  hyphens: auto; -webkit-hyphens: auto;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.tile-icon {
  position: relative; display: grid; place-items: center; flex: none;
  width: 46px; height: 46px; border-radius: 12px; overflow: hidden;
  background: hsl(var(--h, 30) var(--tile-s) var(--tile-l));
  color: hsl(var(--h, 30) 30% var(--tile-ink-l));
  font-family: var(--serif); font-size: 21px; line-height: 1;
}
.tile-icon img {
  position: absolute; inset: 0; margin: auto; width: 30px; height: 30px; object-fit: contain;
  opacity: 0; transition: opacity .2s ease;
}
/* Real icons sit on a soft light tile in both themes, like app icons, so dark logos stay visible */
.tile-icon.has-img { background: #fffdf9; box-shadow: inset 0 0 0 1px var(--line); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tile-icon.has-img { background: #e9e5dd; box-shadow: none; } }
:root[data-theme="dark"] .tile-icon.has-img { background: #e9e5dd; box-shadow: none; }
.tile-icon.has-img img { opacity: 1; }
.tile-icon.has-img .mono { visibility: hidden; }

.tile-more {
  position: absolute; top: 4px; right: 4px;
  display: grid; place-items: center; width: 26px; height: 26px; padding: 0;
  border: 0; border-radius: 999px; background: transparent; color: var(--faint); cursor: pointer;
  opacity: 0; transition: opacity .12s ease;
}
.tile-more svg { width: 16px; height: 16px; }
.tile:hover .tile-more, .tile-more:focus-visible { opacity: 1; }
.tile-more:hover { background: var(--surface); color: var(--ink); }
/* Touch: ⋯ only on links with other addresses, or on everything in Edit mode */
@media (hover: none) {
  .tile-more { opacity: 0; pointer-events: none; }
  .tile.has-mirrors .tile-more, .editing .tile-more { opacity: .8; pointer-events: auto; }
}
.editing .tile-more { opacity: 1; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); color: var(--ink); }
.section-action { margin-left: auto; border: 0; background: none; color: var(--accent); font-size: 13.5px; cursor: pointer; padding: 2px 0; align-self: center; }

/* Kid mode: bigger, friendlier */
.kid .grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.kid .tile-link { padding: 16px 6px 14px; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; }
.kid .tile-icon { width: 72px; height: 72px; border-radius: 20px; font-size: 32px; }
.kid .tile-icon img { width: 44px; height: 44px; }
.kid .tile-name { font-size: 15px; }

/* ---------- Search results / empty ---------- */
.empty { padding: 40px 0; text-align: center; color: var(--muted); }
.empty strong { color: var(--ink); font-weight: 500; }
.result-hint { margin: 8px 0 0; color: var(--faint); font-size: 13px; }
@media (hover: none) { .result-hint { display: none; } }

/* Web search launchpad / zero local matches fallback */
.search-fallback {
  max-width: 680px; margin: 28px auto 20px; text-align: left;
}
.fallback-head { margin-bottom: 18px; }
.fallback-title {
  font-family: var(--serif); font-size: 23px; font-weight: 400; margin: 0 0 6px;
  color: var(--ink); line-height: 1.25;
}
.fallback-sub {
  margin: 0; font-size: 13.5px; color: var(--muted); line-height: 1.5;
}
.fallback-sub strong { color: var(--ink); font-weight: 600; }
.fallback-kbd {
  display: inline-block; font-family: var(--sans); font-size: 11.5px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 4px;
  padding: 0 5px; vertical-align: baseline; line-height: 1.4;
}
.fallback-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px;
}
.fallback-card {
  display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  text-align: left; cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
  width: 100%; font-family: inherit; color: inherit; text-decoration: none;
}
.fallback-card:hover {
  border-color: var(--faint); background: var(--hover); transform: translateY(-1px);
}
.fallback-card.is-active {
  border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent);
}
.fallback-card-icon {
  width: 24px; height: 24px; flex-shrink: 0; margin-top: 1px;
}
.fallback-card-icon svg { width: 24px; height: 24px; }
.fallback-card-info { flex: 1; min-width: 0; }
.fallback-card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 3px;
}
.fallback-card-name { font-size: 15px; font-weight: 600; color: var(--ink); }
.fallback-active-badge {
  font-size: 11px; color: var(--accent); font-weight: 500; letter-spacing: .02em;
}
.fallback-card-tagline {
  margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.4;
}

.foot { margin-top: 40px; color: var(--faint); font-size: 13px; text-align: center; }
.foot button { border: 0; background: none; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: 0; font-size: inherit; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(20, 18, 14, .32);
  animation: fade .15s ease;
}
@media (min-width: 600px) { .overlay { align-items: center; } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(14px); opacity: .6; } }

.sheet, .pin {
  width: 100%; max-width: 400px;
  background: var(--surface); color: var(--ink);
  border-radius: 18px 18px 0 0; box-shadow: var(--shadow);
  padding: 20px 20px max(20px, env(safe-area-inset-bottom));
  animation: rise .18s ease;
}
@media (min-width: 600px) { .sheet, .pin { border-radius: 18px; } }

.sheet-head { display: flex; align-items: center; gap: 12px; }
.sheet-head > div { flex: 1; min-width: 0; }
.sheet-title { font-family: var(--serif); font-weight: 400; font-size: 22px; margin: 0; }
.sheet-host { margin: 1px 0 0; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-close { align-self: flex-start; }
.sheet-desc { margin: 14px 0 0; color: var(--muted); }
.sheet-mirrors { margin-top: 14px; }
.sheet-mirrors h3 { margin: 0 0 6px; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }
.sheet-mirrors .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 5px 11px; border: 1px solid var(--line); border-radius: 999px;
  color: var(--ink); text-decoration: none; font-size: 13.5px;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.sheet-actions { display: flex; gap: 8px; margin-top: 20px; }
.btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 42px; border-radius: 10px; border: 1px solid var(--line); background: transparent;
  color: var(--ink); text-decoration: none; font-size: 14.5px; cursor: pointer;
}
.btn:hover { background: var(--hover); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }

/* PIN */
.pin { max-width: 340px; text-align: center; }
.pin-title { font-family: var(--serif); font-weight: 400; font-size: 22px; margin: 4px 0 2px; }
.pin-sub { margin: 0; color: var(--muted); font-size: 14px; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 18px 0 20px; }
.pin-dots i { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--faint); transition: background .1s; }
.pin-dots i.on { background: var(--ink); border-color: var(--ink); }
.pin-dots.shake { animation: shake .3s ease; }
.pin-dots.shake i { border-color: #b4553f; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pin-pad button {
  height: 56px; border: 0; border-radius: 14px; background: var(--hover);
  font-size: 22px; font-family: var(--serif); cursor: pointer;
  display: grid; place-items: center;
}
.pin-pad button:active { filter: brightness(.95); }
.pin-pad .pin-soft { background: transparent; font-family: var(--sans); font-size: 14px; color: var(--muted); }
.pin-pad .pin-soft svg { width: 22px; height: 22px; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
