:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --ink: #121826;
  --muted: #64748b;
  --line: #d7dee9;
  --accent: #ff6b35;
  --accent-dark: #db4f1d;
  --good: #20a66a;
  --warn: #e2a216;
  --bad: #d64343;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.browser-shell {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  width: 100%;
  max-width: 100vw;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.toolbar {
  min-height: 64px;
  width: 100vw;
  max-width: 100vw;
  display: grid;
  grid-template-columns: auto auto auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 118px;
}

.brand-icon {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  object-fit: cover;
  flex: 0 0 auto;
  box-shadow: 0 2px 7px rgba(18, 24, 38, 0.14);
}

.brand-mark,
.blocked-icon {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  font-weight: 800;
  font-size: 14px;
}

.blocked-icon {
  width: 58px;
  height: 58px;
  border-radius: 13px;
  object-fit: cover;
  box-shadow: 0 10px 24px rgba(18, 24, 38, 0.18);
}

.brand-name {
  font-weight: 760;
  font-size: 16px;
  letter-spacing: 0;
  white-space: nowrap;
}

.nav-controls {
  display: inline-grid;
  grid-template-columns: repeat(3, 34px);
  gap: 6px;
  align-items: center;
}

.icon-button {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  color: var(--ink);
  cursor: pointer;
  padding: 0;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button:hover:not(:disabled) {
  border-color: #b8c3d4;
  background: #f3f7fc;
}

.icon-button:disabled {
  color: #a8b2c1;
  background: #f5f7fa;
  cursor: not-allowed;
}

.address-form {
  min-width: 0;
  width: 100%;
  display: block;
}

.input-wrap {
  overflow: hidden;
  min-width: 0;
}

.address-form input {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  color: var(--ink);
  font-size: 15px;
  outline: none;
}

.address-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.16);
}

.address-form button {
  float: right;
  min-width: 72px;
  height: 42px;
  margin-left: 8px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 750;
  font-size: 14px;
  cursor: pointer;
}

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

.mode-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.mode-button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.mode-badge {
  min-height: 34px;
  display: inline-grid;
  place-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.mode-badge.local {
  border-color: rgba(32, 166, 106, 0.28);
  background: rgba(32, 166, 106, 0.08);
  color: #11724b;
}

.mode-badge.remote {
  border-color: rgba(255, 107, 53, 0.35);
  background: rgba(255, 107, 53, 0.1);
  color: var(--accent-dark);
}

.mode-badge.limited {
  border-color: rgba(226, 162, 22, 0.38);
  background: rgba(226, 162, 22, 0.12);
  color: #8a5b00;
}

.mode-button.active {
  border-color: rgba(255, 107, 53, 0.35);
  background: rgba(255, 107, 53, 0.1);
  color: var(--accent-dark);
}

.mode-button.danger {
  color: var(--bad);
}

.mode-button:hover {
  border-color: #b8c3d4;
  background: #f3f7fc;
}

.remote-inputbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 14px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.remote-inputbar label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.remote-inputbar input {
  min-width: 0;
  height: 36px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  color: var(--ink);
  font-size: 15px;
  outline: none;
}

.remote-inputbar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.14);
}

.remote-inputbar button {
  height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
  white-space: nowrap;
}

.remote-inputbar button:hover {
  background: #273246;
}

.statusbar {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 0 18px;
  color: var(--muted);
  background: #f9fbfe;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--good);
  flex: 0 0 auto;
}

.status-dot.loading {
  background: var(--warn);
}

.status-dot.blocked {
  background: var(--bad);
}

.frame-wrap {
  position: relative;
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  background: #e8edf5;
  overflow: hidden;
}

#browser-frame {
  position: relative;
  width: 100%;
  max-width: 100%;
  height: 100%;
  min-height: 100%;
  border: 0;
  background: #ffffff;
  display: block;
}

.remote-stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0) 34%),
    #e7edf6;
  touch-action: none;
  cursor: crosshair;
  outline: none;
}

.remote-stage:focus {
  box-shadow: inset 0 0 0 3px rgba(255, 107, 53, 0.22);
}

#remote-screenshot {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

#remote-screenshot:not([src]) {
  visibility: hidden;
}

.remote-loading {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  gap: 11px;
  min-height: 46px;
  max-width: min(420px, calc(100vw - 44px));
  padding: 0 18px;
  border: 1px solid rgba(215, 222, 233, 0.86);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
  text-align: left;
  pointer-events: none;
  box-shadow: 0 16px 40px rgba(18, 24, 38, 0.12);
  backdrop-filter: blur(12px);
}

.remote-spinner {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  border: 2px solid rgba(100, 116, 139, 0.22);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: remote-spin 0.72s linear infinite;
}

.remote-loading.error {
  color: #8f1f1f;
  border-color: rgba(214, 67, 67, 0.24);
  background: rgba(255, 248, 247, 0.94);
}

.remote-loading.error .remote-spinner {
  animation: none;
  border-color: rgba(214, 67, 67, 0.18);
  border-top-color: var(--bad);
}

.remote-loading-text {
  min-width: 0;
}

@keyframes remote-spin {
  to {
    transform: rotate(360deg);
  }
}

.remote-loading[hidden] {
  display: none !important;
}

.browser-debug-overlay {
  position: fixed;
  right: 10px;
  bottom: 10px;
  z-index: 2147483647;
  width: min(520px, calc(100vw - 20px));
  max-height: min(42vh, 320px);
  padding: 10px;
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(17, 24, 39, 0.9);
  color: #e5edf8;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  box-shadow: 0 18px 44px rgba(18, 24, 38, 0.26);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (prefers-reduced-motion: reduce) {
  .remote-spinner {
    animation-duration: 1.8s;
  }
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 28px;
  text-align: center;
  background: #ffffff;
}

.empty-state h1,
.blocked-card h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.empty-state p,
.blocked-card p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.blocked-page,
.search-page {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.blocked-card,
.search-card {
  width: min(460px, 100%);
  display: grid;
  gap: 14px;
  justify-items: center;
  padding: 30px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
  box-shadow: 0 18px 45px rgba(18, 24, 38, 0.09);
}

.reason {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.search-query {
  max-width: 100%;
  word-break: break-word;
  font-weight: 700;
  color: var(--ink);
}

.search-link {
  display: inline-grid;
  place-items: center;
  min-height: 40px;
  padding: 0 18px;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  text-decoration: none;
  font-size: 15px;
  font-weight: 750;
}

.search-link:hover {
  background: var(--accent-dark);
}

.debug-page {
  min-height: 100%;
  height: auto;
  overflow: auto;
  background: #eef3fa;
  -webkit-overflow-scrolling: touch;
}

.debug-shell {
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.debug-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
  padding: 10px 0;
  background: rgba(238, 243, 250, 0.94);
  backdrop-filter: blur(10px);
}

.debug-header h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.debug-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.debug-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.debug-actions button,
.debug-header button {
  height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.debug-actions button:not(#debug-rerun) {
  background: #111827;
}

.debug-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
  gap: 14px;
}

.debug-card {
  margin-bottom: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 32px rgba(18, 24, 38, 0.07);
}

.debug-card h2 {
  margin: 0 0 10px;
  font-size: 16px;
}

.debug-tests-panel {
  max-height: calc(100vh - 132px);
  max-height: calc(100dvh - 132px);
  min-height: 360px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

#debug-env {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 7px 10px;
  margin: 0;
  font-size: 13px;
}

#debug-env dt {
  color: var(--muted);
  font-weight: 800;
}

#debug-env dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.debug-tests {
  display: grid;
  gap: 9px;
  margin: 0;
  padding-left: 20px;
}

.debug-test {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafd;
  scroll-margin-top: 72px;
}

.debug-test.active {
  outline: 3px solid rgba(255, 107, 53, 0.28);
  outline-offset: 2px;
}

.debug-test strong,
.debug-test span {
  display: block;
}

.debug-test strong {
  margin-bottom: 4px;
}

.debug-test span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.debug-test pre,
.debug-log {
  max-height: 150px;
  margin: 8px 0 0;
  padding: 10px;
  overflow: auto;
  border-radius: 8px;
  background: #111827;
  color: #e5edf8;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.debug-test pre:empty {
  display: none;
}

.debug-test.pass {
  border-color: rgba(32, 166, 106, 0.32);
  background: rgba(32, 166, 106, 0.07);
}

.debug-test.fail {
  border-color: rgba(214, 67, 67, 0.32);
  background: rgba(214, 67, 67, 0.07);
}

.debug-test.info,
.debug-test.pending {
  border-color: rgba(226, 162, 22, 0.34);
  background: rgba(226, 162, 22, 0.08);
}

.debug-shot-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.debug-shot-wrap {
  position: relative;
  min-height: 240px;
  margin: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e7edf6;
}

.debug-shot-wrap figcaption {
  position: absolute;
  left: 9px;
  top: 8px;
  z-index: 1;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.82);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

#debug-direct-img,
#debug-blob-img,
#debug-canvas {
  max-width: 100%;
  max-height: 440px;
  display: block;
}

#debug-direct-placeholder,
#debug-blob-placeholder,
#debug-canvas-placeholder {
  padding: 34px 14px 14px;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

@media (max-width: 760px), (orientation: portrait) {
  .toolbar {
    min-height: 0;
    width: 100vw;
    max-width: 100vw;
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 10px;
    padding: 12px;
    overflow: hidden;
  }

  .brand {
    display: grid;
    justify-items: center;
    gap: 6px;
    min-width: 0;
  }

  .brand-icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
  }

  .brand-name {
    font-size: 17px;
    text-align: center;
  }

  .nav-controls {
    grid-template-columns: repeat(3, 38px);
    justify-content: center;
    order: 3;
  }

  .mode-controls {
    order: 4;
    justify-content: center;
    flex-wrap: wrap;
  }

  .icon-button {
    width: 38px;
    height: 36px;
  }

  .address-form {
    width: calc(100vw - 24px);
    max-width: 520px;
    justify-self: center;
    display: block;
    order: 5;
  }

  .address-form input {
    min-height: 44px;
    font-size: 16px;
  }

  .address-form button {
    height: 44px;
    width: 70px;
    margin-left: 6px;
  }

  .statusbar {
    padding: 0 12px;
    font-size: 12px;
    line-height: 1.35;
  }

  .remote-inputbar {
    grid-template-columns: 1fr auto auto;
    gap: 7px;
    padding: 8px 10px;
  }

  .remote-inputbar label {
    grid-column: 1 / -1;
    text-align: center;
  }

  .remote-inputbar input {
    height: 42px;
    font-size: 16px;
  }

  .remote-inputbar button {
    height: 42px;
    padding: 0 10px;
  }

  .frame-wrap,
  #browser-frame {
    min-height: 0;
    width: 100vw;
    max-width: 100vw;
  }

  .empty-state h1,
  .blocked-card h1 {
    font-size: 20px;
  }

  .empty-state p,
  .blocked-card p {
    font-size: 14px;
  }

  .debug-shell {
    width: min(100% - 20px, 1120px);
    padding-top: 12px;
  }

  .debug-header {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .debug-header h1 {
    font-size: 20px;
  }

  .debug-header p {
    font-size: 12px;
  }

  .debug-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: stretch;
  }

  .debug-actions button {
    height: 36px;
    padding: 0 8px;
    font-size: 12px;
  }

  .debug-grid {
    grid-template-columns: 1fr;
  }

  .debug-tests-panel {
    max-height: calc(100dvh - 170px);
    min-height: 300px;
  }

  .debug-test pre,
  .debug-log {
    max-height: 108px;
    font-size: 11px;
  }

  .debug-shot-grid {
    grid-template-columns: 1fr;
  }

  #debug-env {
    grid-template-columns: 1fr;
  }

  #debug-env dt {
    margin-top: 6px;
  }
}

@media (max-width: 380px), (orientation: portrait) and (max-width: 430px) {
  .toolbar {
    padding: 10px;
  }

  .address-form {
    width: calc(100vw - 20px);
  }

  .nav-controls {
    grid-template-columns: repeat(3, 36px);
  }

  .icon-button {
    width: 36px;
    height: 34px;
  }

  .address-form input {
    padding-left: 11px;
    padding-right: 11px;
  }

  .address-form button {
    width: 62px;
  }

  .mode-button {
    min-height: 32px;
    padding: 0 8px;
    font-size: 12px;
  }

  .mode-badge {
    min-height: 32px;
    padding: 0 8px;
    font-size: 12px;
  }

  .remote-inputbar {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .remote-inputbar button {
    padding: 0 8px;
    font-size: 12px;
  }

  #remote-enter-button {
    grid-column: 1 / -1;
  }
}
