:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --bg-gradient-1: rgba(5, 150, 105, 0.08);
  --bg-gradient-2: #ffffff;
  --bg-gradient-3: #f8fafc;
  --bg-gradient-4: #f1f5f9;
  --panel: #f8fafc;
  --panel-strong: #f1f5f9;
  --text: #1e293b;
  --muted: #64748b;
  --line: rgba(30, 41, 59, 0.1);
  --accent: #059669;
  --accent-warm: #d97706;
  --danger: #ef4444;
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --canvas-bg: #f8fafc;
  --site-icon-bg: rgba(30, 41, 59, 0.05);
  --toolbar-bg: rgba(255, 255, 255, 0.72);
  --button-bg: rgba(30, 41, 59, 0.06);
}

:root.theme-dark {
  color-scheme: dark;
  --bg: #121417;
  --bg-gradient-1: rgba(53, 198, 164, 0.12);
  --bg-gradient-2: #101215;
  --bg-gradient-3: #15191c;
  --bg-gradient-4: #1b1714;
  --panel: #181d22;
  --panel-strong: #20272e;
  --text: #f4f1e8;
  --muted: #9ba7ad;
  --line: rgba(244, 241, 232, 0.12);
  --accent: #35c6a4;
  --accent-warm: #f0b35a;
  --danger: #f06c64;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  --canvas-bg: #050607;
  --site-icon-bg: rgba(244, 241, 232, 0.05);
  --toolbar-bg: rgba(12, 15, 18, 0.68);
  --button-bg: rgba(244, 241, 232, 0.09);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow-x: hidden;
  background:
    radial-gradient(circle at 16% 8%, var(--bg-gradient-1), transparent 28rem),
    linear-gradient(135deg, var(--bg-gradient-2) 0%, var(--bg-gradient-3) 45%, var(--bg-gradient-4) 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.newtab-shell {
  display: grid;
  grid-template-columns: minmax(22rem, 0.88fr) minmax(26rem, 1.12fr);
  gap: clamp(1rem, 3vw, 2.5rem);
  min-height: 100vh;
  padding: clamp(1rem, 3vw, 2.5rem);
}

.links-pane,
.mandelbrot-pane {
  min-width: 0;
}

.links-pane {
  display: flex;
  flex-direction: column;
  gap: 1.35rem;
  justify-content: center;
}

.brand-bar,
.section-heading,
.fractal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.title-group {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.eyebrow-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.2rem;
}

.eyebrow-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  width: 100%;
}

#fractal-title {
  flex: 0 1 auto;
  min-width: 0;
  line-height: 1.2;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.header-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.85rem;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2.6rem, 8vw, 3.5rem);
  line-height: 0.95;
}

h2 {
  font-size: 1rem;
  line-height: 1.2;
}

.clock {
  flex: 0 0 auto;
  color: var(--accent-warm);
  font-size: clamp(1.15rem, 2vw, 1.7rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums lining-nums;
}

.search-wrap {
  width: 100%;
}

#searchBox {
  width: 100%;
  height: 3.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--text);
  padding: 0 1.1rem;
  transition: border-color 160ms ease, background 160ms ease;
}

#searchBox:focus {
  border-color: var(--accent);
  background: var(--panel-strong);
}

.top-sites-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.muted {
  color: var(--muted);
  font-size: 0.83rem;
}

.top-sites {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.7rem;
}

.site-tile {
  display: grid;
  grid-template-columns: 2.35rem minmax(0, 1fr);
  align-items: center;
  gap: 0.72rem;
  min-height: 4.2rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0.65rem;
  text-decoration: none;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.site-tile:hover,
.site-tile:focus-visible {
  border-color: var(--accent);
  background: var(--panel-strong);
  outline: none;
  transform: translateY(-2px);
}

.site-icon {
  display: grid;
  place-items: center;
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 8px;
  background: var(--site-icon-bg);
  color: #111417;
  font-weight: 800;
  text-transform: uppercase;
  overflow: hidden;
}

.site-icon img {
  width: 1.25rem;
  height: 1.25rem;
  object-fit: contain;
}

.site-meta {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

.site-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
  font-weight: 700;
}

.empty-state {
  grid-column: 1 / -1;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 1rem;
}

.mandelbrot-pane {
  display: grid;
  place-items: center;
}

.canvas-frame {
  position: relative;
  width: min(100%, calc(100vh - clamp(2rem, 6vw, 5rem)));
  max-width: 54rem;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--canvas-bg);
  box-shadow: var(--shadow);
}

.fractal-formula {
  position: absolute;
  top: 1.25rem;
  left: 1.25rem;
  z-index: 5;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 1.1rem;
  color: var(--muted);
  opacity: 0.75;
  pointer-events: none;
  background: var(--toolbar-bg);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  transition: opacity 200ms ease;
  white-space: nowrap;
}

#mandelbrotCanvas,
#webglCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

.fractal-toolbar {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  left: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--toolbar-bg);
  padding: 0.8rem 0.85rem;
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.fractal-actions {
  display: flex;
  gap: 0.5rem;
}

#zoomIn,
#zoomOut,
.ghost-button,
.primary-button,
#resetView,
#nextParams,
#viewExplanation,
#saveImage,
#switchFractal {
  min-width: 2.35rem;
  height: 2.35rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--button-bg);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 160ms ease;
}

.ghost-button,
.primary-button,
#resetView,
#nextParams,
#viewExplanation,
#saveImage,
#switchFractal {
  min-width: 4.4rem;
  padding: 0 0.85rem;
}

#viewExplanation,
#saveImage,
#switchFractal {
  min-width: 3.2rem;
  height: 1.6rem;
  padding: 0 0.5rem;
  font-size: 0.85rem;
}

#viewExplanation,
#switchFractal {
  font-size: 0.76rem;
}

:root.theme-dark #switchFractal {
  background: rgba(240, 179, 90, 0.15);
}

#switchFractal:hover {
  background: var(--accent-warm);
  color: white;
}

#viewExplanation {
  background: rgba(5, 150, 105, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

:root.theme-dark #viewExplanation {
  background: rgba(53, 198, 164, 0.22);
  border-color: var(--accent);
}

#saveImage {
  background: rgba(59, 130, 246, 0.15);
  border-color: #3b82f6;
  color: #3b82f6;
}

:root.theme-dark #saveImage {
  background: rgba(96, 165, 250, 0.2);
  border-color: #60a5fa;
  color: #60a5fa;
}

#saveImage:hover {
  background: #3b82f6;
  color: white;
}

:root.theme-dark #saveImage:hover {
  background: #60a5fa;
  color: #121212;
}

.ghost-button:hover,
.ghost-button:focus-visible,
.primary-button:hover,
.primary-button:focus-visible,
#resetView:hover,
#resetView:focus-visible,
#nextParams:hover,
#nextParams:focus-visible,
#viewExplanation:hover,
#viewExplanation:focus-visible,
#saveImage:hover,
#saveImage:focus-visible {
  border-color: var(--accent-warm);
  outline: none;
}

#viewExplanation:hover {
  background: var(--accent);
  color: white;
}

.primary-button {
  border-color: var(--accent);
  background: rgba(5, 150, 105, 0.1);
}

:root.theme-dark .primary-button {
  background: rgba(53, 198, 164, 0.18);
}

.mode-dialog {
  width: min(28rem, calc(100vw - 2rem));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
  box-shadow: var(--shadow);
}

.mode-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(10px);
}

.mode-dialog-panel {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1.15rem;
}

.mode-dialog-panel h2 {
  font-size: 1.25rem;
}

.dialog-copy {
  color: var(--muted);
  line-height: 1.45;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.7rem;
  padding-top: 0.35rem;
}

@media (max-width: 980px) {
  .newtab-shell {
    grid-template-columns: 1fr;
  }

  .links-pane {
    justify-content: flex-start;
  }

  .mandelbrot-pane {
    min-height: 70vw;
  }

  .canvas-frame {
    width: min(100%, 42rem);
  }
}

@media (max-width: 680px) {
  .newtab-shell {
    padding: 1rem;
  }

  .brand-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .top-sites {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .site-tile {
    grid-template-columns: 1fr;
  }

  .fractal-toolbar {
    right: 0.7rem;
    bottom: 0.7rem;
    left: 0.7rem;
  }
}

.newtab-footer {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  margin-top: auto;
  padding-top: 1.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.newtab-footer a {
  color: var(--muted);
  text-decoration: none;
  transition: color 160ms ease;
}

.newtab-footer a:hover {
  color: var(--accent);
}

.newtab-footer .divider {
  color: var(--line);
}
