:root {
  /* --- CHROME DARK MODE (Default) --- */
  --bg: #202124;           /* New Tab Page Background */
  --frame-bg: #000000;     /* Tab Strip Background */
  --toolbar-bg: #35363A;   /* Toolbar & Active Tab Background */
  --tab-text: #E8EAED;
  --tab-hover: rgba(255, 255, 255, 0.08);
  --tab-inactive-text: #9AA0A6;
  --urlbar-bg: #202124;
  --urlbar-text: #E8EAED;
  --icon-color: #E8EAED;
  --border: #5F6368;       /* Subtle borders */
  --menu-bg: #292A2D;
  --menu-hover: #3C4043;
  --accent: #8AB4F8;       /* Google Blue */
  --ntp-card: #303134;     /* Shortcut hover bg */
  --shadow: 0 4px 6px rgba(0,0,0,0.3);
}

body.light-mode {
  /* --- CHROME LIGHT MODE --- */
  --bg: #FFFFFF;
  --frame-bg: #DEE1E6;
  --toolbar-bg: #FFFFFF;
  --tab-text: #1F1F1F;
  --tab-hover: #F2F2F2;
  --tab-inactive-text: #474747;
  --urlbar-bg: #F1F3F4;
  --urlbar-text: #1F1F1F;
  --icon-color: #474747;
  --border: #DADCE0;
  --menu-bg: #FFFFFF;
  --menu-hover: #F1F3F4;
  --accent: #1A73E8;
  --ntp-card: #F1F3F4;
}

* { margin: 0; padding: 0; box-sizing: border-box; user-select: none; }

body {
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--tab-text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background 0.1s;
}

/* --- CHROME UI STRUCTURE --- */
#browser-ui {
  display: flex;
  flex-direction: column;
  background: var(--toolbar-bg); /* The main toolbar color */
  flex-shrink: 0;
  position: relative;
  z-index: 100;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

/* 1. TAB STRIP (The top black bar in dark mode) */
#tabs-strip {
  background: var(--frame-bg);
  display: flex;
  align-items: flex-end; /* Tabs sit on the bottom */
  padding: 8px 12px 0 12px;
  height: 42px; /* Standard Chrome tab height + padding */
  gap: 6px;
}

#tabs-container {
  display: flex;
  flex: 1;
  overflow-x: auto;
  gap: 6px;
  scrollbar-width: none;
  height: 100%;
  align-items: flex-end;
}
#tabs-container::-webkit-scrollbar { display: none; }

/* Chrome Tab Style */
.tab {
  display: flex;
  align-items: center;
  height: 34px; /* Slightly shorter than strip */
  padding: 0 12px;
  color: var(--tab-inactive-text);
  background: transparent;
  border-radius: 8px 8px 0 0; /* Rounded top corners */
  min-width: 140px;
  max-width: 240px;
  flex: 1;
  font-size: 12px;
  cursor: default;
  position: relative;
  transition: background 0.1s, color 0.1s;
  border: none;
}

.tab:hover:not(.active) {
  background: var(--tab-hover);
  color: var(--tab-text);
}

/* The Active Tab connects seamlessly to the toolbar */
.tab.active {
  background: var(--toolbar-bg);
  color: var(--tab-text);
  z-index: 1;
  box-shadow: 0 0 5px rgba(0,0,0,0.2); /* Slight shadow for depth */
}

.tab-icon-area { 
    width: 16px; height: 16px; margin-right: 10px; flex-shrink: 0; 
    display: flex; align-items: center; justify-content: center; 
}
.tab-favicon { width: 16px; height: 16px; border-radius: 50%; } /* Chrome favicons often circular in UI context */

.tab-spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(128,128,128,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  display: none;
}
.tab.loading .tab-spinner { display: block; }
.tab.loading .tab-favicon { display: none; }

.tab-title {
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-right: 8px;
  font-size: 12px;
}

/* CLOSE BUTTON FIX: Changed opacity from 0 to 0.7 */
.tab-close {
  width: 16px; height: 16px; border-radius: 50%; border: none;
  background: transparent; color: inherit; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  opacity: 0.7; transition: opacity 0.2s; font-size: 14px;
}
.tab:hover .tab-close { opacity: 1; }
.tab-close:hover { background: rgba(128,128,128,0.3); opacity: 1; }

/* New Tab Button - FIXED COLOR VISIBILITY */
#new-tab-btn {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none;
  color: var(--tab-text) !important; /* Force high contrast color */
  border-radius: 50%;
  cursor: pointer;
  margin-left: 4px; margin-bottom: 3px;
  transition: background 0.1s;
  opacity: 1; /* Ensure full visibility */
}
#new-tab-btn:hover { background: rgba(255,255,255,0.1); }
#new-tab-btn svg { width: 20px; height: 20px; fill: currentColor; }

/* 2. NAVIGATION TOOLBAR */
#nav-toolbar {
  display: flex; align-items: center;
  padding: 8px 12px;
  gap: 8px;
  background: var(--toolbar-bg);
}

.nav-btn {
  width: 32px; height: 32px;
  border-radius: 50%; /* Chrome buttons are circular */
  border: none;
  background: transparent;
  color: var(--icon-color);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 0.1s;
}
.nav-btn:hover:not(:disabled) { background: rgba(128,128,128,0.15); }
.nav-btn:disabled { opacity: 0.3; cursor: default; }
.nav-btn svg { width: 18px; height: 18px; fill: currentColor; }

/* 3. OMNIBOX (URL Bar) */
#urlbar-container { flex: 1; position: relative; margin: 0 4px; }

#urlbar-wrapper {
  display: flex; align-items: center;
  background: var(--urlbar-bg);
  border: 1px solid transparent;
  border-radius: 99px; /* Pill shape */
  height: 34px; padding: 0 14px;
  transition: background 0.1s, box-shadow 0.1s, border 0.1s;
}
#urlbar-wrapper:focus-within {
  background: var(--toolbar-bg);
  border: 2px solid var(--accent); /* Chrome focus border */
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  padding: 0 13px; /* Adjust for border width */
}

#urlbar-input {
  flex: 1; background: transparent; border: none;
  color: var(--urlbar-text); font-size: 14px; outline: none;
  font-family: inherit; margin: 0 8px;
}

/* Icons inside Omnibox */
#url-lock { color: var(--icon-color); opacity: 0.7; width: 14px; height: 14px; }
#url-spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite; display: none;
}
.loading #url-lock { display: none; }
.loading #url-spinner { display: block; }

.urlbar-icon {
  background: transparent; border: none; color: var(--icon-color);
  width: 28px; height: 28px; border-radius: 50%;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  opacity: 0.7; transition: 0.1s;
}
.urlbar-icon:hover { background: rgba(128,128,128,0.15); opacity: 1; }

/* 4. BOOKMARKS BAR */
#bookmarks-bar {
  display: none; /* CHANGED: Hidden by default */
  align-items: center;
  padding: 6px 12px 8px 12px; gap: 4px;
  background: var(--toolbar-bg);
  font-size: 12px; overflow-x: auto;
}
#bookmarks-bar.show { display: flex; } /* NEW: Toggle class */

.bookmark {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  border-radius: 99px; /* Pill shape hover */
  color: var(--icon-color);
  cursor: pointer; border: none; background: transparent; white-space: nowrap; font-size: 11px;
  transition: background 0.1s;
}
.bookmark:hover { background: rgba(128,128,128,0.15); }
.bookmark img { width: 16px; height: 16px; }

/* 5. MENU DROPDOWN */
#menu-popup {
  position: absolute; top: 100%; right: 10px; width: 300px;
  background: var(--menu-bg);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  display: none; flex-direction: column; padding: 8px 0; z-index: 999;
  margin-top: 8px;
}
#menu-popup.show { display: flex; animation: fadein 0.1s ease-out; }

.menu-item {
  padding: 10px 20px; display: flex; align-items: center; gap: 16px;
  color: var(--tab-text); cursor: pointer; font-size: 14px;
}
.menu-item:hover { background: var(--menu-hover); }
.menu-sep { height: 1px; background: var(--border); margin: 8px 0; opacity: 0.3; }
.menu-item svg { width:18px; height:18px; fill:currentColor; opacity:0.8; }

/* 6. CONTENT & STATUS */
#web-content { flex: 1; position: relative; background: #fff; }
iframe.web-frame { width: 100%; height: 100%; border: none; display: none; background: #fff; }
iframe.web-frame.active { display: block; }

/* Chrome doesn't really have a status bar anymore, but we show link info floating usually. 
   For this app, a thin bottom bar is useful for debug status */
#status-bar {
  background: var(--toolbar-bg); color: var(--icon-color); opacity: 0.7; font-size: 11px;
  padding: 2px 12px; border-top: 1px solid var(--border);
}

/* --- NEW TAB PAGE (Google Clone) --- */
.internal-page {
  background-color: var(--bg); /* NTP Background */
  color: var(--tab-text);
  height: 100vh; width: 100%;
  font-family: 'Roboto', arial, sans-serif;
  display: flex; flex-direction: column; align-items: center;
  padding-top: 15vh;
  overflow: hidden;
}
.google-logo { width: 272px; height: 92px; margin-bottom: 38px; display: block; }

.search-box {
  width: 90%; max-width: 560px; height: 46px;
  background: var(--menu-bg); /* Search bar slightly lighter in dark mode */
  border: 1px solid var(--border);
  border-radius: 24px;
  display: flex; align-items: center; padding: 0 16px;
  margin-bottom: 28px;
  transition: background 0.1s, box-shadow 0.1s;
}
.search-box:hover {
  background: var(--menu-hover);
  box-shadow: 0 1px 6px rgba(0,0,0,0.3);
  border-color: transparent;
}
.search-input {
  flex: 1; background: transparent; border: none; font-size: 16px;
  color: var(--tab-text); outline: none; margin-left: 12px;
}

/* Shortcut Grid */
.shortcuts-grid {
  display: flex; flex-direction: row; justify-content: center;
  gap: 16px; width: 100%; max-width: 600px; flex-wrap: wrap;
}
.shortcut {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  cursor: pointer; padding: 12px; border-radius: 8px; transition: 0.1s;
  width: 112px;
}
.shortcut:hover { background: var(--ntp-card); }
.sc-icon-circle {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--menu-bg);
  display: flex; align-items: center; justify-content: center;
  padding: 10px;
}
.sc-icon-circle img { width: 24px; height: 24px; object-fit: contain; }
.sc-label {
  font-size: 13px; color: var(--tab-text); text-align: center;
  width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadein { from { opacity:0; transform:translateY(-10px); } to { opacity:1; transform:translateY(0); } }