:root {
  /* --- DARK MODE (Default) --- */
  --bg: #1C1B22;
  --toolbar: #2B2A33;
  --tab-text: #fbfbfe;
  --tab-hover: rgba(255, 255, 255, 0.1);
  --tab-active: #42414D;
  --urlbar: #1C1B22;
  --urlbar-focus: #42414D;
  --accent: #00DDFF;
  --icon: #fbfbfe;
  --border: #52525E;
  --menu-bg: #2B2A33;
  --menu-hover: #42414D;
  --ntp-bg: #1C1B22;
  --ntp-card: #2B2A33;
  --ntp-text: #fff;
}

body.light-mode {
  /* --- LIGHT MODE --- */
  --bg: #F0F0F4;
  --toolbar: #F9F9FB;
  --tab-text: #15141A;
  --tab-hover: rgba(0, 0, 0, 0.05);
  --tab-active: #FFFFFF;
  --urlbar: #F0F0F4;
  --urlbar-focus: #FFFFFF;
  --accent: #0060DF;
  --icon: #15141A;
  --border: #E0E0E6;
  --menu-bg: #FFFFFF;
  --menu-hover: #E0E0E6;
  --ntp-bg: #F9F9FB;
  --ntp-card: #FFFFFF;
  --ntp-text: #15141A;
  --ntp-input-text: #15141A;
}

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

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

/* --- UI CHROME --- */
#browser-ui {
  background: var(--bg);
  flex-shrink: 0;
  z-index: 100;
  box-shadow: 0 1px 0 var(--border);
}

/* Tabs */
#tabs-strip {
  display: flex; align-items: center; padding: 8px 6px 0 6px; height: 44px; gap: 4px;
}
#tabs-container {
  display: flex; flex: 1; overflow-x: auto; gap: 4px; scrollbar-width: none; align-items: center;
}
.tab {
  display: flex; align-items: center; height: 36px; padding: 0 10px;
  color: var(--tab-text); border-radius: 4px;
  min-width: 140px; max-width: 220px; font-size: 12px; cursor: pointer;
  background: transparent; transition: background 0.1s; position: relative;
  flex-shrink: 0;
}
.tab:hover:not(.active) { background: var(--tab-hover); }
.tab.active { background: var(--tab-active); box-shadow: 0 2px 6px rgba(0,0,0,0.1); }
.tab.active::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--accent); border-radius: 4px 4px 0 0;
}
.tab-icon-area { width: 16px; height: 16px; margin-right: 8px; flex-shrink: 0; display:flex; align-items:center; }
.tab-favicon { width: 16px; height: 16px; border-radius: 2px; }
.tab-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-right: 6px; }
.tab-close {
  width: 20px; height: 20px; border-radius: 4px; border: none;
  background: transparent; color: inherit; cursor: pointer;
  display: flex; align-items: center; justify-content: center; opacity: 0;
}
.tab:hover .tab-close { opacity: 0.7; }
.tab.active .tab-close { opacity: 0.7; }
.tab-close:hover { background: rgba(128,128,128,0.3); opacity: 1 !important; }

/* New Tab Button (Inside Strip) - Forced Color */
#new-tab-btn {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; 
  color: var(--tab-text) !important;
  fill: currentColor;
  border-radius: 4px; cursor: pointer; flex-shrink: 0;
  opacity: 0.7;
}
#new-tab-btn:hover { background: var(--tab-hover); opacity: 1; }
#new-tab-btn svg { width: 20px; height: 20px; }

/* Toolbar */
#nav-toolbar {
  display: flex; align-items: center; padding: 4px 8px 8px 8px; gap: 4px;
  background: var(--toolbar);
}
.nav-btn {
  width: 32px; height: 32px; border-radius: 4px; border: none;
  background: transparent; color: var(--icon);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.nav-btn:hover:not(:disabled) { background: var(--tab-hover); }
.nav-btn:disabled { opacity: 0.3; cursor: default; }
.nav-btn svg { width: 16px; height: 16px; fill: currentColor; }

/* Urlbar */
#urlbar-container { flex: 1; position: relative; margin: 0 6px; }
#urlbar-wrapper {
  display: flex; align-items: center; background: var(--urlbar);
  border: 1px solid transparent; border-radius: 4px; height: 34px; padding: 0 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
#urlbar-wrapper:focus-within {
  background: var(--urlbar-focus); box-shadow: 0 0 0 2px var(--accent);
}
#urlbar-input {
  flex: 1; background: transparent; border: none;
  color: var(--tab-text); font-size: 14px; outline: none; font-family: inherit;
}
#url-spinner {
  width: 14px; height: 14px; margin-right: 8px;
  border: 2px solid rgba(128,128,128,0.3); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite; display: none;
}
.loading #url-spinner { display: block; }
.urlbar-icon {
  background: transparent; border: none; color: var(--icon);
  padding: 4px; border-radius: 4px; cursor: pointer; display: flex; opacity: 0.7;
}
.urlbar-icon:hover { background: var(--tab-hover); opacity: 1; }

/* Bookmarks */
#bookmarks-bar {
  display: none; /* Changed: Hidden by default */
  align-items: center; padding: 4px 10px 6px 10px; gap: 4px;
  background: var(--toolbar); border-bottom: 1px solid var(--border);
}
#bookmarks-bar.show { display: flex; } /* NEW: Toggle class */

.bookmark {
  display: flex; align-items: center; gap: 6px; padding: 4px 8px;
  border-radius: 4px; color: var(--tab-text);
  cursor: pointer; border: none; background: transparent; white-space: nowrap; font-size: 11px;
}
.bookmark:hover { background: var(--tab-hover); }
.bookmark img { width: 14px; height: 14px; border-radius: 2px; }

/* Menu */
#menu-popup {
  position: absolute; top: 85px; right: 10px; width: 280px;
  background: var(--menu-bg); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  display: none; flex-direction: column; padding: 8px 0; z-index: 999;
}
#menu-popup.show { display: flex; animation: fadein 0.15s ease; }
.menu-item {
  padding: 8px 16px; display: flex; align-items: center; gap: 12px;
  color: var(--tab-text); cursor: pointer; font-size: 13px;
}
.menu-item:hover { background: var(--menu-hover); }
.menu-sep { height: 1px; background: var(--border); margin: 6px 0; }
.menu-item svg { width:16px; height:16px; fill:currentColor; opacity:0.8; }

/* 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; }
#status-bar {
  background: var(--toolbar); color: var(--icon); opacity: 0.7; font-size: 11px;
  padding: 3px 10px; border-top: 1px solid var(--border);
}

/* --- INTERNAL PAGE CSS (New Tab) --- */
.internal-page {
  background-color: var(--ntp-bg);
  color: var(--ntp-text);
  height: 100vh;
  width: 100vw;
  font-family: system-ui, -apple-system, sans-serif;
  display: flex; flex-direction: column; align-items: center;
  padding-top: 12vh;
  overflow: hidden;
}
.ff-logo { width: 90px; height: 90px; margin-bottom: 30px; display: block; }
.search-box {
  width: 90%; max-width: 600px; height: 52px;
  background: var(--ntp-card);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  display: flex; align-items: center; padding: 0 16px;
  margin-bottom: 40px;
}
.search-input {
  flex: 1; background: transparent; border: none; font-size: 16px;
  color: var(--ntp-text); outline: none; margin-left: 12px;
}

/* Homepage Grid - Forced Horizontal Layout */
.shortcuts-grid {
  display: flex; 
  flex-direction: row;
  justify-content: center;
  gap: 20px;
  width: 100%;
  max-width: 800px;
  flex-wrap: wrap;
}
.shortcut {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  cursor: pointer; padding: 12px; border-radius: 8px; transition: 0.1s;
  width: 110px;
}
.shortcut:hover { background: var(--menu-hover); }
.sc-icon-box {
  width: 64px; height: 64px; border-radius: 8px; background: var(--ntp-card);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1); padding: 12px;
}
.sc-icon-box img { width: 32px; height: 32px; object-fit: contain; }
.sc-label { font-size: 12px; color: var(--ntp-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(-5px); } to { opacity:1; transform:translateY(0); } }