:root {
  color-scheme: light;
  --ink: #16211f;
  --muted: #68736f;
  --paper: #f4f6f1;
  --panel: #ffffff;
  --line: #dfe5dd;
  --accent: #0d806c;
  --accent-dark: #075f51;
  --accent-soft: #dff4ed;
  --warm: #f0a962;
  --danger: #a33a31;
  --shadow: 0 18px 50px rgba(21, 42, 36, 0.13);
  --scrim: rgba(22, 33, 31, 0.42);
  --panel-width: 320px;
  --topbar-height: 68px;
  --motion-fast: 140ms;
  --motion-standard: 220ms;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --focus-ring: 0 0 0 3px rgba(13, 128, 108, 0.24);
  font-family: Inter, Pretendard, "Noto Sans KR", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
}

body[data-chrome-open="false"] {
  grid-template-rows: 0 minmax(0, 1fr);
}

body[data-viewer-immersive="true"] :is(.chrome-toggle, .panel-toggle-floating, .topbar, .control-panel, .panel-backdrop) {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 0;
  box-shadow: var(--focus-ring);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.topbar {
  min-height: var(--topbar-height);
  display: grid;
  grid-template-columns: minmax(290px, 330px) minmax(320px, 780px) 1fr;
  align-items: center;
  gap: 20px;
  padding: 8px 20px 8px 76px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
  position: relative;
  z-index: 5;
  overflow: visible;
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
  transition: transform var(--motion-standard) var(--ease-out), opacity var(--motion-fast) var(--ease-out), visibility 0s;
}

body[data-chrome-open="false"] .topbar {
  display: none;
}

.chrome-toggle {
  position: fixed;
  top: 12px;
  left: 16px;
  z-index: 12;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 13px;
  box-shadow: 0 8px 24px rgba(21, 42, 36, 0.14);
  backdrop-filter: blur(12px);
  transition: color var(--motion-fast) var(--ease-out), background var(--motion-fast) var(--ease-out);
}

.chrome-toggle:hover { color: var(--accent-dark); background: var(--accent-soft); }

.chrome-toggle svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform var(--motion-standard) var(--ease-out);
}

.panel-toggle-floating {
  position: fixed;
  top: 12px;
  left: 66px;
  z-index: 12;
  width: 44px;
  height: 44px;
  display: none;
  place-items: center;
  padding: 0;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 13px;
  box-shadow: 0 8px 24px rgba(21, 42, 36, 0.14);
  backdrop-filter: blur(12px);
  transition: color var(--motion-fast) var(--ease-out), background var(--motion-fast) var(--ease-out);
}

.panel-toggle-floating svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.panel-toggle-floating:hover {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.panel-toggle-floating:not([hidden]) {
  display: grid;
}

body[data-chrome-open="true"] .chrome-toggle svg {
  transform: rotate(180deg);
}

.brand-cluster {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.panel-toggle, .panel-close {
  min-width: 40px;
  min-height: 40px;
  display: inline-grid;
  place-items: center;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 11px;
  transition: color var(--motion-fast) var(--ease-out), background var(--motion-fast) var(--ease-out), border-color var(--motion-fast) var(--ease-out);
}

.panel-toggle {
  grid-template-columns: 20px auto;
  gap: 7px;
  padding: 0 11px;
  font-size: 12px;
  font-weight: 800;
}

.panel-toggle:hover, .panel-close:hover {
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-color: #c3e7db;
}

.panel-toggle svg, .panel-close svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand {
  color: inherit;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--ink);
  border-radius: 13px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; letter-spacing: -0.01em; }
.brand small { color: var(--muted); margin-top: 2px; font-size: 12px; }

.bookmark-menu { position: relative; flex: 0 0 auto; }
.bookmark-toggle {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 11px;
}
.bookmark-toggle:hover, .bookmark-toggle[aria-expanded="true"] { color: var(--accent-dark); background: var(--accent-soft); }
.bookmark-toggle svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.bookmark-panel {
  position: absolute;
  top: calc(100% + 12px);
  left: 0;
  z-index: 40;
  width: min(340px, calc(100vw - 28px));
  max-height: min(68vh, 540px);
  overflow: hidden;
  padding: 10px;
  background: rgba(250, 252, 249, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.94);
  border-radius: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.bookmark-panel[hidden] { display: none; }
.bookmark-save { width: 100%; padding: 11px 14px; color: white; background: var(--accent); border: 0; border-radius: 11px; font-size: 13px; font-weight: 800; }
.bookmark-list { max-height: min(52vh, 420px); overflow: auto; margin: 9px 0 0; padding: 0; list-style: none; }
.bookmark-empty { padding: 18px 10px; color: var(--muted); text-align: center; font-size: 12px; }
.bookmark-row { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 6px; padding: 5px 0; border-top: 1px solid rgba(22, 33, 31, 0.09); }
.bookmark-delete { width: 34px; min-height: 52px; padding: 0; color: var(--danger); background: transparent; border: 0; border-radius: 9px; font-size: 18px; font-weight: 700; }
.bookmark-open { min-width: 0; padding: 7px 9px; text-align: left; color: var(--ink); background: rgba(255, 255, 255, 0.58); border: 0; border-radius: 10px; }
.bookmark-open strong, .bookmark-open small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bookmark-open strong { font-size: 13px; line-height: 1.35; }
.bookmark-open small { margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.3; }

.url-form {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px;
  background: #edf0eb;
  border: 1px solid #e0e5de;
  border-radius: 14px;
}

.url-form:focus-within {
  border-color: #81b8aa;
  box-shadow: 0 0 0 3px rgba(13, 128, 108, 0.1);
}

.url-form input {
  min-width: 0;
  padding: 9px 11px;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 13px;
}

.primary-button, .secondary-button, .picker-button {
  border: 0;
  border-radius: 10px;
  font-weight: 700;
}

.primary-button {
  padding: 10px 17px;
  color: white;
  background: var(--accent);
}

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

.connection-status {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  color: var(--muted);
  background: var(--paper);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.connection-status::before {
  content: "";
  width: 7px;
  height: 7px;
  background: #9aa39f;
  border-radius: 50%;
}

.connection-status[data-tone="ready"]::before { background: var(--accent); }
.connection-status[data-tone="loading"]::before { background: var(--warm); animation: pulse 1.1s infinite; }
.connection-status[data-tone="error"]::before { background: var(--danger); }

.workspace {
  grid-row: 2;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--panel-width) minmax(0, 1fr);
  overflow: hidden;
}

.workspace[data-panel-open="false"] {
  grid-template-columns: 0 minmax(0, 1fr);
}

.control-panel {
  width: var(--panel-width);
  min-width: 0;
  overflow-y: auto;
  padding: 0 22px 30px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  transform: translateX(0);
  opacity: 1;
  visibility: visible;
  transition: transform var(--motion-standard) var(--ease-out), opacity var(--motion-fast) var(--ease-out), visibility 0s;
}

.workspace[data-panel-open="false"] .control-panel {
  transform: translateX(-100%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: transform var(--motion-standard) var(--ease-out), opacity var(--motion-fast) var(--ease-out), visibility 0s var(--motion-standard);
}

.control-panel-toolbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 8px 5px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  font-size: 12px;
  font-weight: 800;
}

.panel-close {
  width: 40px;
  padding: 0;
}

.panel-backdrop {
  display: none;
}

.panel-intro { padding: 22px 5px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 7px; color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: 0.15em; }
.panel-intro h1 { margin: 0; font-size: 21px; line-height: 1.25; letter-spacing: -0.04em; }
.site-address { overflow: hidden; margin: 9px 0 0; color: var(--muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }

.control-section { padding: 22px 5px; border-bottom: 1px solid var(--line); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.section-heading h2 { margin: 0; font-size: 15px; letter-spacing: -0.02em; }
.count-badge { min-width: 25px; padding: 4px 7px; color: var(--accent-dark); background: var(--accent-soft); border-radius: 99px; text-align: center; font-size: 11px; font-weight: 800; }

.vpn-status { padding: 4px 7px; color: var(--muted); background: #edf0eb; border-radius: 99px; font-size: 10px; font-weight: 800; }
.vpn-status[data-tone="ready"] { color: var(--accent-dark); background: var(--accent-soft); }
.vpn-status[data-tone="loading"] { color: #7a4b16; background: #fff0dc; }
.vpn-status[data-tone="error"] { color: var(--danger); background: #f8e5e2; }
.vpn-label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 11px; font-weight: 700; }
.vpn-select { width: 100%; padding: 10px 30px 10px 10px; color: var(--ink); background: white; border: 1px solid var(--line); border-radius: 9px; font-size: 12px; }
.vpn-detail { margin: 8px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }

.session-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 12px;
}

.session-restore, .session-clear {
  min-height: 40px;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 800;
}

.session-restore {
  color: white;
  background: var(--ink);
  border: 1px solid var(--ink);
}

.session-restore:hover { background: #263530; }
.session-clear { color: var(--muted); background: transparent; border: 1px solid var(--line); }
.session-clear:hover { color: var(--danger); border-color: #e9ccc8; }

.empty-state { margin: 0; padding: 14px; color: var(--muted); background: #f6f7f4; border-radius: 10px; font-size: 13px; line-height: 1.55; }
.empty-state.compact { padding: 10px 12px; }

.region-row, .manual-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 9px 10px;
  border-radius: 10px;
}
.region-row:hover, .manual-row:hover { background: #f5f7f3; }
.region-row label { flex: 1; display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; font-weight: 650; }
.region-row small { color: var(--muted); font-size: 11px; font-weight: 600; }
.region-row input { width: 17px; height: 17px; accent-color: var(--accent); }

.picker-button {
  width: 100%;
  padding: 11px 13px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border: 1px solid #c3e7db;
}
.picker-button[data-active="true"] { color: white; background: var(--accent); }
.manual-list { margin-top: 10px; }
.manual-row span { flex: 1; overflow: hidden; font-family: ui-monospace, monospace; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.manual-row button { padding: 5px 8px; color: var(--danger); background: transparent; border: 0; font-size: 11px; font-weight: 700; }

.safety-note { color: var(--muted); font-size: 12px; line-height: 1.55; }
.safety-note p { margin: 0; }
.safety-note p + p { margin-top: 5px; }
.safety-note strong { color: var(--ink); }

.reset-button { width: 100%; margin-top: 18px; padding: 10px; color: var(--danger); background: transparent; border: 1px solid #e9ccc8; border-radius: 10px; font-size: 13px; font-weight: 700; }

.preview-shell {
  grid-column: 2;
  min-width: 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: radial-gradient(circle at 72% 24%, #d9f0e6, transparent 29%), linear-gradient(145deg, #f2f5ef, #e7ece5);
}

#proxy-frame { width: 100%; height: 100%; border: 0; background: white; }

.welcome-card, .loading-card, .error-card {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: min(580px, calc(100% - 64px));
  text-align: center;
}

.welcome-card { padding: 48px; background: rgba(255, 255, 255, 0.76); border: 1px solid rgba(255, 255, 255, 0.9); border-radius: 28px; box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.welcome-card h2 { margin: 12px 0 16px; font-family: Georgia, "Noto Serif KR", serif; font-size: clamp(34px, 4vw, 54px); font-weight: 500; line-height: 1.08; letter-spacing: -0.05em; }
.welcome-card > p:not(.eyebrow) { max-width: 460px; margin: 0 auto 26px; color: var(--muted); font-size: 14px; line-height: 1.7; }
.welcome-orbit { width: 68px; height: 68px; display: grid; place-items: center; margin: 0 auto 22px; border: 1px solid #96cabb; border-radius: 50%; animation: rotate 8s linear infinite; }
.welcome-orbit::before { content: ""; width: 9px; height: 9px; background: var(--warm); border-radius: 50%; transform: translateY(-34px); }
.welcome-orbit span { position: absolute; width: 27px; height: 27px; background: var(--accent); border-radius: 9px; transform: rotate(12deg); }
.secondary-button { padding: 12px 18px; color: white; background: var(--ink); }

.loading-card, .error-card { max-width: 420px; padding: 30px; background: white; border-radius: 18px; box-shadow: var(--shadow); }
.loading-card strong, .loading-card small { display: block; }
.loading-card small { margin-top: 7px; color: var(--muted); }
.spinner { width: 31px; height: 31px; display: block; margin: 0 auto 15px; border: 3px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: rotate 0.75s linear infinite; }
.error-card strong { color: var(--danger); }
.error-card p { margin-bottom: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 20; max-width: 360px; padding: 12px 16px; color: white; background: var(--ink); border-radius: 11px; box-shadow: var(--shadow); font-size: 13px; font-weight: 700; }

.auth-gate { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; background: color-mix(in srgb, var(--paper) 92%, white); }
.auth-gate[hidden] { display: none; }
.auth-card { width: min(100%, 430px); padding: 34px; background: rgba(255, 255, 255, 0.94); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.auth-card h1 { margin: 14px 0 8px; color: var(--ink); font-size: 28px; letter-spacing: -0.04em; }
.auth-card > p:not(.eyebrow):not(.auth-error) { margin: 0 0 22px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.auth-card > label:not(.remember-row) { display: block; margin: 12px 0 6px; color: var(--ink); font-size: 12px; font-weight: 800; }
.auth-card > input { width: 100%; padding: 12px 13px; color: var(--ink); background: white; border: 1px solid var(--line); border-radius: 10px; font: inherit; }
.remember-row { display: flex; gap: 8px; align-items: center; margin: 15px 0; color: var(--muted); font-size: 13px; }
.auth-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.auth-error { margin: 0 0 12px; color: var(--danger); font-size: 12px; font-weight: 700; }
.account-menu { display: flex; gap: 8px; align-items: center; margin-left: 4px; color: var(--muted); font-size: 11px; }
.account-menu button { padding: 6px 8px; color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 8px; font-size: 11px; }
.admin-section { background: var(--accent-soft); }
.vpn-admin-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 10px; }
.vpn-admin-actions button { min-height: 38px; padding: 7px 9px; color: var(--accent-dark); background: rgba(255,255,255,.8); border: 1px solid #b8ded2; border-radius: 9px; font-size: 11px; font-weight: 800; }
.vpn-admin-actions button:last-child { color: white; background: var(--accent); border-color: var(--accent); }
.vpn-monitor-list { display: grid; gap: 6px; max-height: 280px; overflow: auto; margin: 10px 0 0; padding: 0; list-style: none; }
.vpn-monitor-row { display: grid; grid-template-columns: 1fr auto; gap: 3px 8px; padding: 8px; background: rgba(255,255,255,.68); border: 1px solid transparent; border-radius: 9px; }
.vpn-monitor-row[data-state="selected"] { border-color: var(--accent); background: white; }
.vpn-monitor-row[data-state="unavailable"] { opacity: .58; }
.vpn-monitor-row strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.vpn-monitor-row span { color: var(--muted); font-size: 10px; }
.vpn-monitor-row small { grid-column: 1/-1; color: var(--accent-dark); font-size: 10px; }

@keyframes rotate { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.35; } }

@media (max-width: 900px) {
  .topbar { min-height: 0; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 10px 12px 10px 64px; }
  .chrome-toggle { top: 10px; left: 12px; width: 40px; height: 40px; border-radius: 11px; }
  .panel-toggle-floating { top: 10px; left: 58px; width: 40px; height: 40px; border-radius: 11px; }
  .brand-cluster { grid-column: 1; grid-row: 1; gap: 8px; }
  .brand small { display: none; }
  .bookmark-panel { position: fixed; top: 58px; right: 10px; left: 10px; width: auto; }
  .brand-mark { width: 38px; height: 38px; border-radius: 11px; }
  .panel-toggle span { display: none; }
  .panel-toggle { grid-template-columns: 20px; padding: 0 9px; }
  .url-form { grid-column: 1 / -1; grid-row: 2; }
  .connection-status { grid-column: 2; grid-row: 1; }
  .workspace, .workspace[data-panel-open="false"] { grid-template-columns: minmax(0, 1fr); }
  .control-panel {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(88vw, 360px);
    height: 100dvh;
    border-right: 1px solid var(--line);
    box-shadow: var(--shadow);
  }
  .panel-backdrop {
    position: fixed;
    inset: 0;
    z-index: 25;
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    background: var(--scrim);
    border: 0;
    backdrop-filter: blur(3px);
    opacity: 1;
    transition: opacity var(--motion-fast) var(--ease-out);
  }
  .panel-backdrop[hidden] { display: none; }
  .preview-shell { grid-column: 1; min-height: 0; }
  .welcome-card { padding: 34px 24px; }
  .welcome-card h2 { font-size: clamp(30px, 9vw, 46px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
