/* KLMorse hub — Material Design 3 shell (carlogs / Bookshelf Beta tokens) */
html.md3 {
  --bg: #000000;
  --text: #e6e1e5;
  --muted: #cac4d0;
  --accent: #ff4500;
  --panel: #1c1b1f;
  --soft: #2b2930;
  --line: #e6e1e5;
  --menu-bg: #000000;
  --menu-button: #2b2930;
  --on-menu-button: var(--text);
  --on-toggle: #ffffff;
  --on-accent: #000000;
  --toggle-on: var(--accent);
  --card-bg: var(--panel);
  --md-primary: var(--accent);
  --md-on-primary: var(--on-toggle);
  --md-surface: var(--bg);
  --md-surface-container: var(--panel);
  --md-surface-container-high: var(--menu-button);
  --md-surface-container-highest: var(--soft);
  --md-on-surface: var(--text);
  --md-on-surface-variant: var(--muted);
  --md-outline: color-mix(in srgb, var(--line) 42%, transparent);
  --md-outline-variant: color-mix(in srgb, var(--line) 22%, transparent);
  --md-error: #f2b8b5;
  --md-shape-s: 2px;
  --md-shape-m: 4px;
  --md-shape-l: 8px;
  --md-shape-full: 999px;
  --md-title-h: calc(48px + env(safe-area-inset-top, 0px));
  --radius: 2px;
  --btn-radius: 2px;
  color-scheme: dark;
  font-family: "Roboto Flex", Roboto, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  letter-spacing: 0.15px;
  background: var(--md-surface);
  color: var(--md-on-surface);
}

html.md3.corner-square {
  --md-shape-s: 2px;
  --md-shape-m: 4px;
  --md-shape-l: 8px;
  --radius: 2px;
  --btn-radius: 2px;
}

html.md3, html.md3 body {
  margin: 0;
  min-height: 100%;
  background: var(--md-surface);
  color: var(--md-on-surface);
}

html.md3 button, html.md3 input, html.md3 select, html.md3 textarea {
  font-family: inherit;
}

html.md3 * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html.md3 #animCanvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

html.md3 .klm-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: var(--md-surface);
}

html.md3 .hub-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: env(safe-area-inset-top, 0px) 12px 6px;
  background: var(--md-surface);
  border-bottom: 0;
  flex: 0 0 auto;
}

html.md3 .hub-header-inner {
  width: 100%;
  max-width: 1100px;
  display: flex;
  align-items: center;
  gap: 8px;
}

html.md3 .hub-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 0;
  min-width: 0;
}

html.md3 .hub-logo {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: var(--md-shape-full);
  object-fit: contain;
  background: var(--md-surface-container-high);
}

html.md3 .hub-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--md-on-surface);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

html.md3 .hub-subtitle {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--md-on-surface-variant);
  letter-spacing: 0.4px;
}

html.md3 .hub-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

html.md3 .hub-seg {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: var(--md-surface-container);
  border-radius: var(--md-shape-s);
}

html.md3 .hub-btn,
html.md3 .hub-chip,
html.md3 .settings-back {
  border: 1px solid var(--md-outline-variant);
  background: var(--md-surface-container-high);
  color: var(--md-on-surface);
  border-radius: var(--md-shape-s);
  min-height: 40px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.1px;
  cursor: pointer;
}

html.md3 .hub-btn.icon {
  min-width: 40px;
  width: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--md-shape-full);
  border: 0;
}

html.md3 .hub-btn.anim-on,
html.md3 .hub-chip.active,
html.md3 .hub-btn.primary {
  background: var(--md-primary);
  border-color: var(--md-primary);
  color: var(--md-on-primary);
}

html.md3 .hub-version {
  border: 0;
  background: color-mix(in srgb, var(--md-primary) 16%, transparent);
  color: var(--md-primary);
  border-radius: var(--md-shape-full);
  min-height: 28px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 600;
}

html.md3 .klm-console-has-errors {
  color: var(--md-error) !important;
  background: color-mix(in srgb, var(--md-error) 16%, transparent) !important;
  border-color: var(--md-error) !important;
}

html.md3 .hub-main {
  padding: 8px 12px calc(16px + env(safe-area-inset-bottom, 0px));
  width: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

html.md3 .hub-main-inner {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
}

html.md3 .hub-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

html.md3 .hub-meta {
  margin: 0;
  font-size: 11px;
  font-weight: 500;
  color: var(--md-on-surface-variant);
}

html.md3 .hub-hint {
  margin: 0 0 10px;
  font-size: 11px;
  color: var(--md-on-surface-variant);
}

html.md3 .hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 8px;
}

html.md3 .tile-card-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--md-surface-container);
  border: 0;
  border-radius: var(--md-shape-m);
  overflow: hidden;
  min-width: 0;
}

html.md3 .tile-card-wrap.is-pinned {
  box-shadow: inset 0 0 0 1px var(--md-primary);
}

html.md3 .tile-pin-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 2;
  font-size: 9px;
  padding: 2px 6px;
  border-radius: var(--md-shape-full);
  background: color-mix(in srgb, var(--md-primary) 22%, var(--md-surface));
  color: var(--md-primary);
  font-weight: 700;
}

html.md3 .tile-main {
  display: block;
  padding: 12px;
  text-decoration: none;
  color: inherit;
  flex: 1 1 auto;
}

html.md3 .tile-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  margin: 0 0 4px;
  color: var(--md-on-surface);
}

html.md3 .tile-desc {
  font-size: 11px;
  line-height: 1.4;
  color: var(--md-on-surface-variant);
}

html.md3 .tile-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

html.md3 .hub-tag {
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--md-shape-full);
  background: var(--md-surface-container-highest);
  color: var(--md-on-surface-variant);
}

html.md3 .hub-tag.is-pwa {
  background: color-mix(in srgb, var(--md-primary) 18%, transparent);
  color: var(--md-primary);
}

html.md3 .tile-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 12px 10px;
}

html.md3 .tile-info {
  font-size: 9px;
  color: var(--md-on-surface-variant);
  font-family: ui-monospace, monospace;
}

html.md3 .tile-changelog-btn {
  flex-shrink: 0;
  min-height: 28px;
  padding: 4px 10px;
  border: 0;
  border-radius: var(--md-shape-s);
  background: var(--md-surface-container-highest);
  color: var(--md-on-surface);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
}

html.md3 .hub-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: stretch;
  justify-content: flex-end;
}

html.md3 .hub-overlay.open { display: flex; }

html.md3 .hub-backdrop {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 62%, transparent);
}

html.md3 .hub-drawer {
  position: relative;
  z-index: 1;
  width: min(420px, 100vw);
  background: var(--md-surface-container-high);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

html.md3 .hub-modal-center {
  align-items: center;
  justify-content: center;
  padding: 16px;
}

html.md3 .hub-sheet {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  max-height: min(80vh, 560px);
  display: flex;
  flex-direction: column;
  background: var(--md-surface-container-high);
  border-radius: var(--md-shape-l);
  overflow: hidden;
}

html.md3 .hub-sheet-head,
html.md3 .bs-settings-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0 8px;
  flex-shrink: 0;
}

html.md3 .hub-sheet-head h2,
html.md3 .bs-settings-head > div {
  flex: 1 1 auto;
  min-width: 0;
}

html.md3 .bs-settings-head h2,
html.md3 .hub-sheet-head h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
}

html.md3 .bs-settings-sub {
  margin: 0;
  font-size: 12px;
  color: var(--md-on-surface-variant);
}

html.md3 .hub-sheet-body {
  overflow-y: auto;
  padding: 0 12px 12px;
}

html.md3 .changelog-entry { margin-bottom: 14px; }
html.md3 .changelog-version { font-size: 12px; font-weight: 700; margin-bottom: 4px; }
html.md3 .hub-overview-title { font-size: 15px; font-weight: 800; margin: 0 0 0.5rem; }
html.md3 .hub-overview-p { font-size: 13px; line-height: 1.45; margin: 0 0 0.65rem; color: var(--md-on-surface-variant, #cac4d0); }
html.md3 .hub-overview-features { margin: 0.35rem 0 0.75rem; }
html.md3 .hub-overview-actions .hub-btn { font-weight: 700; }
html.md3 .changelog-list {
  margin: 0;
  padding-left: 1rem;
  font-size: 12px;
  line-height: 1.45;
  color: var(--md-on-surface-variant);
}

html.md3 .ctx-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: 0;
  border-radius: var(--md-shape-s);
  background: transparent;
  color: var(--md-on-surface);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

html.md3 .ctx-item.primary { color: var(--md-primary); }
html.md3 .ctx-title {
  margin: 0 8px 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--md-on-surface-variant);
}

html.md3 #siteToast {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(12px);
  z-index: 80;
  pointer-events: none;
  padding: 10px 14px;
  max-width: min(92vw, 360px);
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--md-on-surface);
  background: var(--md-surface-container-highest);
  border-radius: var(--md-shape-s);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

html.md3 #siteToast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

html.md3 .install-pwa-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: var(--md-shape-s);
  background: var(--md-surface-container);
}

html.md3 .install-pwa-name { font-size: 13px; font-weight: 700; }
html.md3 .install-pwa-hint { font-size: 11px; color: var(--md-on-surface-variant); margin-top: 2px; }

html.md3 .hub-input {
  border: 1px solid var(--md-outline);
  background: var(--md-surface-container-highest);
  color: var(--md-on-surface);
  border-radius: var(--md-shape-s);
  min-height: 48px;
  padding: 12px 14px;
  font-size: 16px;
  width: 100%;
}

html.md3 #hubSettingsFind {
  width: 100%;
  margin: 4px 0 8px;
}

html.md3 .settings-hub { display: flex; flex-direction: column; gap: 14px; }
html.md3 #settingsForm.is-detail .settings-hub,
html.md3 #settingsForm.is-detail #hubSettingsFind { display: none; }
html.md3 .settings-back { display: none; }
html.md3 #settingsPanel.is-detail .settings-back { display: inline-flex; }

html.md3 .settings-cluster-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--md-on-surface-variant);
  margin: 0 0 6px;
}

html.md3 .settings-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

html.md3 .settings-tile {
  flex: 1 1 calc(50% - 6px);
  min-width: 132px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 7px 8px;
  text-align: left;
  border: 0;
  border-radius: var(--md-shape-s);
  background: var(--md-surface-container);
  color: var(--md-on-surface);
  cursor: pointer;
}

html.md3 .settings-tile svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--md-primary);
  fill: currentColor;
}

html.md3 .settings-tile strong { display: block; font-size: 12px; line-height: 1.15; }
html.md3 .settings-tile span span { display: block; font-size: 10px; color: var(--md-on-surface-variant); line-height: 1.2; }
html.md3 .settings-tile.is-hidden { display: none; }
html.md3 .settings-cluster.is-empty { display: none; }

html.md3 #settingsForm details[data-settings-cat] { display: none; }
html.md3 #settingsForm.is-detail details[data-settings-cat].is-active {
  display: block;
  margin: 0;
  border: 0;
  border-radius: var(--md-shape-m);
  background: var(--md-surface-container);
  padding: 8px 10px 16px;
}
html.md3 #settingsForm details[data-settings-cat] > summary { display: none; }

html.md3 .section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  color: var(--md-on-surface-variant);
  margin: 0 0 8px;
}

html.md3 .setting-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

html.md3 .anim-type-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

html.md3 .color-fold {
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-shape-s);
  background: var(--md-surface-container);
  margin-bottom: 8px;
  overflow: hidden;
}

html.md3 .color-fold > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}

html.md3 .color-fold > summary::-webkit-details-marker { display: none; }
html.md3 .color-fold .color-fold-body { padding: 0 10px 12px; }

html.md3 input[type="range"] { accent-color: var(--md-primary); width: 100%; }
html.md3 input[type="color"] {
  cursor: pointer;
  padding: 2px;
  background: transparent;
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-shape-s);
  width: 40px;
  height: 32px;
}

html.md3 .check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--md-on-surface-variant);
  margin-bottom: 8px;
}

html.md3 .hub-more-pop {
  position: fixed;
  top: calc(52px + env(safe-area-inset-top, 0px));
  right: 8px;
  z-index: 90;
  display: none;
  min-width: 168px;
  padding: 8px;
  background: var(--md-surface-container-highest);
  border-radius: var(--md-shape-s);
  flex-direction: column;
  gap: 6px;
}

html.md3 .hub-more-pop.open { display: flex; }
html.md3 .hub-more-pop .hub-btn { width: 100%; justify-content: flex-start; }

html.md3 ::-webkit-scrollbar { width: 3px; }
html.md3 ::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--md-on-surface) 16%, transparent);
  border-radius: 2px;
}

@media (max-width: 720px) {
  html.md3 .hub-subtitle { display: none; }
  html.md3 .hub-wide { display: none; }
}
