/*
 * Lumno's bookmark cascade menu, restyled from src/newtab/styles/bookmark-cascade.css
 * with the new tab's light tokens and a neutral gray dark set. Theme changes
 * cross-fade every color.
 */
.cm {
  --cm-surface: rgba(255, 255, 255, 0.96);
  --cm-border: rgba(0, 0, 0, 0.14);
  --cm-shadow:
    0 18px 34px rgba(15, 23, 42, 0.12),
    0 2px 4px rgba(15, 23, 42, 0.05),
    inset 0 1px 0 rgba(255, 255, 255, 0.74);
  --cm-quiet-ink: #7a8491;
  --cm-item-ink: #263140;
  --cm-item-hover-bg: rgba(15, 23, 42, 0.07);
  --cm-arrow-ink: #94a3b8;
  --cm-chip-hover-bg: rgba(15, 23, 42, 0.065);
  --cm-theme-fade: 520ms ease;
}

.tip-stage[data-theme="dark"] .cm {
  --cm-surface: rgba(34, 34, 34, 0.96);
  --cm-border: rgba(255, 255, 255, 0.12);
  --cm-shadow:
    0 18px 34px rgba(0, 0, 0, 0.42),
    0 2px 4px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --cm-quiet-ink: #9a9a9a;
  --cm-item-ink: #e4e4e4;
  --cm-item-hover-bg: rgba(255, 255, 255, 0.08);
  --cm-arrow-ink: #8a8a8a;
  --cm-chip-hover-bg: rgba(255, 255, 255, 0.08);
}

/* ---------- Bookmarks bar chip that anchors the menu ---------- */

.cm-chip {
  all: unset;
  position: absolute;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px 0 6px;
  border-radius: var(--lumno-radius-md, 8px);
  color: var(--cm-item-ink);
  font: 500 14px/1 var(--tip-font-sans);
  transition: background-color 160ms ease, color var(--cm-theme-fade);
}

.cm-chip[data-state] { background: var(--cm-chip-hover-bg); }

/* ---------- Levels ---------- */

.cm-level {
  position: absolute;
  box-sizing: border-box;
  width: max-content;
  min-width: 210px;
  max-width: 260px;
  border-radius: 12px;
  background: var(--cm-surface);
  border: 1px solid var(--cm-border);
  box-shadow: var(--cm-shadow);
  backdrop-filter: blur(18px) saturate(135%);
  opacity: 0;
  transform: var(--cm-closed);
  transform-origin: var(--cm-origin);
  transition:
    opacity 170ms ease,
    transform 360ms cubic-bezier(0.2, 1.45, 0.35, 1),
    background-color var(--cm-theme-fade),
    border-color var(--cm-theme-fade),
    box-shadow var(--cm-theme-fade);
}

.cm-level[data-level="0"] {
  --cm-closed: translateY(-6px) scale(0.96, 0.86);
  --cm-origin: top left;
}

/* A submenu grows out of its parent's edge. */
.cm-level[data-level="1"] {
  --cm-closed: translateX(-8px) scale(0.88, 0.98);
  --cm-origin: left center;
}

.cm-level[data-open] {
  opacity: 1;
  transform: none;
}

.cm-content {
  display: flex;
  flex-direction: column;
  row-gap: 4px;
  padding: 6px;
}

.cm-title {
  padding: 4px 8px 2px;
  color: var(--cm-quiet-ink);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  transition: color var(--cm-theme-fade);
}

.cm-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 8px;
  border-radius: var(--lumno-radius-md, 8px);
  color: var(--cm-item-ink);
  white-space: nowrap;
  transition:
    background-color 120ms ease,
    outline-color 120ms ease,
    color var(--cm-theme-fade);
}

.cm-item[data-hover],
.cm-item[data-active] {
  background: var(--cm-item-hover-bg);
}

/* A row the pointer crosses inside the safe triangle: hover is ignored. */
.cm-item {
  outline: 1.5px dashed transparent;
  outline-offset: -1.5px;
}

.cm-item[data-skipped] {
  outline-color: rgba(37, 99, 235, 0.55);
  background: rgba(59, 130, 246, 0.06);
}

.tip-stage[data-theme="dark"] .cm-item[data-skipped] {
  outline-color: rgba(96, 165, 250, 0.6);
  background: rgba(96, 165, 250, 0.08);
}

.cm-icon {
  flex: none;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  object-fit: contain;
  transition: filter var(--cm-theme-fade);
}

/* Black brand glyphs turn white in the dark theme, as in the new tab. */
.tip-stage[data-theme="dark"] .cm-icon[data-mono] { filter: invert(1); }

.cm-icon--folder {
  width: 22px;
  height: 22px;
  border-radius: 0;
}

.cm-icon--folder svg {
  display: block;
  width: 100%;
  height: 100%;
}

.cm-icon--folder .x-nt-folder-shape--hover { opacity: 0; }

.cm-label {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.25;
}

.cm-arrow {
  flex: none;
  width: 16px;
  height: 16px;
  color: var(--cm-arrow-ink);
}

/* ---------- Theme switch, after the settings page's theme picker ---------- */

.cm-theme {
  --cm-theme-bg: rgba(15, 23, 42, 0.05);
  --cm-theme-border: rgba(15, 23, 42, 0.08);
  --cm-theme-knob: #ffffff;
  --cm-theme-ink: #6b7280;
  --cm-theme-ink-on: #111827;
  position: absolute;
  display: flex;
  padding: 2px;
  border-radius: 10px;
  background: var(--cm-theme-bg);
  box-shadow: inset 0 0 0 1px var(--cm-theme-border);
  transition: background-color var(--cm-theme-fade), box-shadow var(--cm-theme-fade);
}

.tip-stage[data-theme="dark"] .cm-theme {
  --cm-theme-bg: rgba(255, 255, 255, 0.06);
  --cm-theme-border: rgba(255, 255, 255, 0.1);
  --cm-theme-knob: #3d3d3d;
  --cm-theme-ink: #8f8f8f;
  --cm-theme-ink-on: #f5f5f5;
}

.cm-theme-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 36px;
  height: 30px;
  border-radius: 8px;
  background: var(--cm-theme-knob);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.14);
  transition:
    transform 280ms cubic-bezier(0.32, 0.72, 0, 1),
    background-color var(--cm-theme-fade);
}

.tip-stage[data-theme="dark"] .cm-theme-knob { transform: translateX(36px); }

.cm-theme-option {
  position: relative;
  display: grid;
  place-items: center;
  width: 36px;
  height: 30px;
  color: var(--cm-theme-ink);
  transition: color 200ms ease;
}

.cm-theme-option svg { width: 16px; height: 16px; }

.tip-stage:not([data-theme="dark"]) .cm-theme-option[data-theme-option="light"],
.tip-stage[data-theme="dark"] .cm-theme-option[data-theme-option="dark"] {
  color: var(--cm-theme-ink-on);
}

/* ---------- Debug overlay: the menu's own safe-triangle view, plus a caption ---------- */

.cm-debug {
  position: absolute;
  inset: 0;
  z-index: 5;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.cm-triangle {
  fill: rgba(59, 130, 246, 0.16);
  stroke: rgba(37, 99, 235, 0.78);
  stroke-width: 2.5;
  stroke-dasharray: 10 7;
  stroke-linejoin: round;
  opacity: 0;
  transition: opacity 140ms ease;
}

.cm-triangle[data-visible] { opacity: 1; }

.cm-pill {
  --lumno-corner-shape: round;
  position: absolute;
  left: 0;
  top: 0;
  z-index: 6;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 999px;
  border: 1.5px solid rgba(37, 99, 235, 0.32);
  background: rgba(239, 246, 255, 0.94);
  box-shadow: 0 10px 24px rgba(30, 64, 175, 0.14);
  color: #1d4ed8;
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  opacity: 0;
  transition:
    opacity 140ms ease,
    background-color var(--cm-theme-fade),
    border-color var(--cm-theme-fade),
    color var(--cm-theme-fade);
}

.cm-pill[data-visible] { opacity: 1; }

.cm-pill span { font-weight: 600; opacity: 0.72; }

/* The "without" case reads in neutral gray, not the debug blue. */
.cm-pill[data-tone="off"] {
  border-color: rgba(100, 116, 139, 0.35);
  background: rgba(248, 250, 252, 0.94);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.1);
  color: #64748b;
}

.tip-stage[data-theme="dark"] .cm-pill[data-tone="off"] {
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(40, 40, 40, 0.94);
  color: #a3a3a3;
}

/* A label without a timer. */
.cm-pill[data-plain] span { opacity: 1; }
.cm-pill[data-plain] b,
.cm-pill[data-plain] span + b + span { display: none; }

.tip-stage[data-theme="dark"] .cm-pill {
  border-color: rgba(96, 165, 250, 0.38);
  background: rgba(40, 40, 40, 0.94);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
  color: #93c5fd;
}

/* ---------- Verdict badge and caption, bottom center ---------- */

/* Plain text on the canvas, in the page's soft ink. */
.cm-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 168px;
  z-index: 6;
  margin: 0;
  color: var(--tip-ink-soft);
  font-size: 30px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.005em;
  text-align: center;
  opacity: 0;
  transition: opacity 160ms ease, color var(--cm-theme-fade);
}

.cm-caption[data-visible] { opacity: 1; }

.cm-verdict {
  --lumno-corner-shape: round;
  position: absolute;
  left: 50%;
  bottom: 226px;
  z-index: 6;
  display: grid;
  place-items: center;
  width: 104px;
  height: 104px;
  margin-left: -52px;
  border-radius: 50%;
  color: #ffffff;
  opacity: 0;
  transform: scale(0.6);
  transition:
    opacity 160ms ease,
    transform 420ms cubic-bezier(0.34, 1.56, 0.64, 1),
    background-color 160ms ease;
}

.cm-verdict[data-visible] {
  opacity: 1;
  transform: none;
}

.cm-verdict svg {
  display: none;
  width: 54px;
  height: 54px;
  filter: drop-shadow(0 -1px 0 rgba(0, 0, 0, 0.18));
}

.cm-verdict[data-kind="no"] {
  background: linear-gradient(180deg, #f87171 0%, #dc2626 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    inset 0 0 0 1px rgba(127, 29, 29, 0.25),
    0 10px 24px -6px rgba(220, 38, 38, 0.5);
}

.cm-verdict[data-kind="yes"] {
  background: linear-gradient(180deg, #4ade80 0%, #16a34a 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    inset 0 0 0 1px rgba(20, 83, 45, 0.25),
    0 10px 24px -6px rgba(22, 163, 74, 0.5);
}

.cm-verdict[data-kind="no"] svg[data-verdict="no"],
.cm-verdict[data-kind="yes"] svg[data-verdict="yes"] {
  display: block;
}
