/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #1a1a2e;
  --bg-surface: #16213e;
  --bg-elevated: #0f3460;
  --text: #e8e8e8;
  --text-muted: #8892a4;
  --accent: #00d2ff;
  --accent-hover: #00b4d8;
  --danger: #e94560;
  --border: #2a2a4a;
  --radius: 10px;
  --toolbar-h: 52px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

button { cursor: pointer; font-family: inherit; }
input { font-family: inherit; }

.hidden { display: none !important; }

/* ===== Setup Panel ===== */
#setup-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg);
}

.setup-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px;
  max-width: 520px;
  width: 90%;
  text-align: center;
}

.setup-card h1 {
  font-size: 28px;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--accent), #7b2ff7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.setup-card p {
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.5;
}

.setup-card .input-group {
  display: flex;
  gap: 8px;
}

.setup-card input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.setup-card input:focus { border-color: var(--accent); }

.setup-card button {
  padding: 12px 24px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  transition: background 0.2s;
}

.setup-card button:hover { background: var(--accent-hover); }

.hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 16px;
}

/* ===== Toolbar ===== */
#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  height: var(--toolbar-h);
  flex-shrink: 0;
}

.toolbar-left, .toolbar-right {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.toolbar-center {
  flex: 1;
  min-width: 0;
}

.nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  transition: all 0.15s;
}

.nav-btn:hover:not(:disabled) {
  background: var(--bg-elevated);
  color: var(--text);
}

.nav-btn:disabled { opacity: 0.3; cursor: default; }

.url-bar {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 12px;
  transition: border-color 0.2s;
}

.url-bar:focus-within { border-color: var(--accent); }

.url-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

.url-bar input {
  flex: 1;
  padding: 8px 10px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.copy-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 6px;
  display: flex;
  align-items: center;
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.15s;
  flex-shrink: 0;
}

.copy-btn:hover { color: var(--accent); }

.copy-btn.copied { color: #4ade80; }

.go-btn {
  padding: 6px 16px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  font-size: 13px;
  transition: background 0.2s;
}

.go-btn:hover { background: var(--accent-hover); }

/* ===== Loading Bar ===== */
#loading-bar {
  height: 3px;
  background: var(--bg-surface);
  flex-shrink: 0;
  overflow: hidden;
}

.loading-progress {
  height: 100%;
  width: 30%;
  background: linear-gradient(90deg, var(--accent), #7b2ff7);
  border-radius: 2px;
  animation: loading 1.2s ease-in-out infinite;
}

@keyframes loading {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

/* ===== Welcome Screen ===== */
#welcome-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
}

.welcome-content {
  text-align: center;
  padding: 40px 20px;
  max-width: 640px;
  width: 100%;
}

.welcome-title {
  font-size: 56px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #7b2ff7, var(--danger));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
}

.welcome-subtitle {
  font-size: 18px;
  color: var(--text-muted);
  margin-bottom: 40px;
}

.welcome-search {
  display: flex;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 4px 4px 4px 20px;
  margin-bottom: 48px;
  transition: border-color 0.2s;
}

.welcome-search:focus-within { border-color: var(--accent); }

.welcome-search input {
  flex: 1;
  padding: 14px 8px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 16px;
  outline: none;
}

.welcome-search button {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.welcome-search button:hover { background: var(--accent-hover); }

.quick-links {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 16px;
}

.quick-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text-muted);
  transition: color 0.2s;
  width: 80px;
}

.quick-link:hover { color: var(--text); }

.quick-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
  color: #fff;
  transition: transform 0.15s;
}

.quick-link:hover .quick-icon { transform: scale(1.1); }

.quick-link span { font-size: 12px; }

.version {
  margin-top: 40px;
  font-size: 12px;
  color: var(--text-muted);
  opacity: 0.5;
}

/* ===== Welcome Footer ===== */
.welcome-footer {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-muted);
  opacity: 0.5;
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.welcome-footer a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s;
}

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

.version-info {
  margin-top: 20px;
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.5;
  text-align: center;
}

/* ===== History Panel ===== */
.history-panel {
  position: absolute;
  top: var(--toolbar-h);
  right: 12px;
  width: 400px;
  max-width: calc(100vw - 24px);
  max-height: 60vh;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  z-index: 500;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.history-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.history-header .btn-secondary {
  padding: 5px 12px;
  font-size: 12px;
}

#history-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.history-item:hover {
  background: var(--bg-elevated);
}

.history-url {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-time {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.history-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.history-item:hover .history-delete {
  opacity: 1;
}

.history-delete:hover {
  color: var(--danger);
  background: rgba(233, 69, 96, 0.15);
}

.history-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ===== Settings Help ===== */
.setting-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  opacity: 0.7;
}

.setting-hint code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
}

.settings-help {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.settings-help h3 {
  font-size: 14px;
  margin-bottom: 10px;
  margin-top: 16px;
  color: var(--text);
}

.settings-help h3:first-child {
  margin-top: 0;
}

.help-intro {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
  line-height: 1.5;
}

.help-steps {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.8;
  padding-left: 20px;
  margin-bottom: 8px;
}

.help-steps li {
  margin-bottom: 8px;
}

.help-steps a {
  color: var(--accent);
  text-decoration: none;
}

.help-steps a:hover {
  text-decoration: underline;
}

.help-code {
  display: block;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  margin-top: 4px;
  color: var(--accent);
  word-break: break-all;
  user-select: all;
}

.help-shortcuts {
  list-style: none;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 2;
}

.settings-help kbd {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-family: inherit;
  color: var(--text);
}

.settings-links {
  margin-top: 12px;
  font-size: 12px;
  display: flex;
  gap: 8px;
  color: var(--text-muted);
}

.settings-links a {
  color: var(--accent);
  text-decoration: none;
}

.settings-links a:hover {
  text-decoration: underline;
}

/* ===== Secure Icon ===== */
.secure-icon {
  color: var(--accent);
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

/* ===== Content Frame ===== */
#content-frame {
  flex: 1;
  overflow: hidden;
}

#proxy-frame {
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}

/* ===== Error Screen ===== */
#error-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.error-content {
  text-align: center;
  color: var(--text-muted);
}

.error-content svg {
  color: var(--danger);
  margin-bottom: 16px;
}

.error-content h2 {
  color: var(--text);
  margin-bottom: 8px;
}

.error-content p { margin-bottom: 24px; }

.retry-btn {
  padding: 10px 24px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
  transition: background 0.2s;
}

.retry-btn:hover { background: var(--accent-hover); }

/* ===== Settings Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
}

.modal-card {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  max-width: 540px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  z-index: 1;
}

.modal-card h2 {
  margin-bottom: 24px;
  font-size: 20px;
}

.setting-group {
  margin-bottom: 20px;
}

.setting-group label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.setting-group input[type="url"] {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.setting-group input[type="url"]:focus { border-color: var(--accent); }

.setting-group input[type="checkbox"] {
  margin-right: 8px;
  accent-color: var(--accent);
}

.setting-group label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  color: var(--text);
  cursor: pointer;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 28px;
}

.btn-secondary {
  padding: 10px 20px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 14px;
  transition: all 0.15s;
}

.btn-secondary:hover { border-color: var(--text-muted); color: var(--text); }

.btn-primary {
  padding: 10px 20px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #000;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.2s;
}

.btn-primary:hover { background: var(--accent-hover); }

/* ===== Responsive ===== */
@media (max-width: 600px) {
  :root { --toolbar-h: 46px; }
  .welcome-title { font-size: 36px; }
  .welcome-subtitle { font-size: 15px; margin-bottom: 28px; }
  .quick-links { gap: 12px; }
  .quick-link { width: 64px; }
  .quick-icon { width: 40px; height: 40px; font-size: 16px; }
  .setup-card { padding: 28px 20px; }
  .setup-card .input-group { flex-direction: column; }

  /* Toolbar: compact for mobile */
  #toolbar { padding: 4px 6px; gap: 3px; }
  .nav-btn { width: 32px; height: 32px; }
  .nav-btn svg { width: 18px; height: 18px; }

  /* Hide back/forward on small screens — save space for URL bar */
  .toolbar-left .nav-btn:nth-child(2),
  .toolbar-left .nav-btn:nth-child(3) { display: none; }

  /* Address bar: more compact */
  .url-bar { padding: 0 8px; border-radius: 8px; }
  .url-bar input { padding: 6px 6px; font-size: 13px; }
  .secure-icon { display: none; }
  .go-btn { padding: 5px 10px; font-size: 12px; border-radius: 5px; }
  .copy-btn { padding: 4px; }

  /* History panel full-width */
  .history-panel { width: 100%; right: 0; left: 0; border-radius: 0 0 12px 12px; }

  /* Settings modal full-screen on mobile */
  .modal-card { max-width: 100%; width: 100%; max-height: 100vh; border-radius: 0; }
}

@media (max-width: 380px) {
  /* Very small screens: hide copy button, shrink further */
  .copy-btn { display: none; }
  .go-btn { padding: 5px 8px; }
  .url-bar input { font-size: 12px; }
  .toolbar-right .nav-btn:nth-child(1) { display: none; } /* hide history btn */
}
