/* ---------- Tokens (Apple semantic colors) ---------- */
:root {
  --bg: #f5f5f7;
  --window: #ffffff;
  --chrome: rgba(236, 236, 240, 0.9);
  --tab-active: #ffffff;
  --label: #1d1d1f;
  --label-secondary: rgba(60, 60, 67, 0.72);
  --label-tertiary: rgba(60, 60, 67, 0.72);
  --separator: rgba(60, 60, 67, 0.14);
  --fill: rgba(118, 118, 128, 0.12);
  --fill-hover: rgba(118, 118, 128, 0.08);
  --tint: #007aff;
  --window-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.03), 0 40px 90px -20px rgba(0, 0, 0, 0.22);
  --tab-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.08);

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-ios: cubic-bezier(0.32, 0.72, 0, 1);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --window: #1c1c1e;
    --chrome: rgba(44, 44, 46, 0.92);
    --tab-active: rgba(255, 255, 255, 0.12);
    --label: #f5f5f7;
    --label-secondary: rgba(235, 235, 245, 0.68);
    --label-tertiary: rgba(235, 235, 245, 0.68);
    --separator: rgba(84, 84, 88, 0.6);
    --fill: rgba(118, 118, 128, 0.24);
    --fill-hover: rgba(118, 118, 128, 0.16);
    --tint: #0a84ff;
    --window-shadow: 0 0 0 0.5px rgba(255, 255, 255, 0.12), 0 40px 90px -20px rgba(0, 0, 0, 0.9);
    --tab-shadow: inset 0 0 0 0.5px rgba(255, 255, 255, 0.08);
  }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--tint) 55%, transparent);
  outline-offset: 2px;
}

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 40px 56px;
}

/* ---------- Hero ---------- */
.hero {
  padding: 120px 0 80px;
  text-align: center;
}

.hero h1 {
  margin: 0 auto;
  max-width: 820px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", system-ui, sans-serif;
  font-size: clamp(40px, 6.4vw, 72px);
  font-weight: 700;
  letter-spacing: -0.032em;
  line-height: 1.04;
  text-wrap: balance;
}

.lede {
  margin: 20px auto 0;
  max-width: 540px;
  font-size: 19px;
  line-height: 1.45;
  color: var(--label-secondary);
  text-wrap: pretty;
}

/* ---------- Safari window ---------- */
.window {
  height: min(880px, calc(100dvh - 48px));
  min-height: 560px;
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  overflow: hidden;
  background: var(--window);
  box-shadow: var(--window-shadow);
}

.chrome {
  position: relative;
  flex: none;
  background: var(--chrome);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
}

.toolbar {
  height: 52px;
  display: grid;
  grid-template-columns: 1fr minmax(0, 480px) 1fr;
  align-items: center;
  gap: 12px;
  padding: 0 12px 0 18px;
}

.lights { display: flex; gap: 8px; }
.lights span { width: 12px; height: 12px; border-radius: 50%; box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.12); }
.lights span:nth-child(1) { background: #ff5f57; }
.lights span:nth-child(2) { background: #febc2e; }
.lights span:nth-child(3) { background: #28c840; }

.bar { display: flex; align-items: center; gap: 8px; min-width: 0; }

.address {
  flex: 1;
  height: 32px;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 14px;
  border-radius: 9px;
  background: var(--fill);
  color: var(--label);
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
  transition: background 150ms ease, transform 160ms var(--ease-out);
}
.address svg { flex: none; color: var(--label-tertiary); }
.address .url { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.address .url .path { color: var(--label-tertiary); }

.go {
  flex: none;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--label);
  color: var(--window);
  transition: transform 160ms var(--ease-out), opacity 150ms ease;
}
.go svg { transition: transform 200ms var(--ease-out); }

.actions { display: flex; justify-content: flex-end; align-items: center; gap: 2px; }

.tool {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--label-secondary);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease, transform 160ms var(--ease-out);
}
.tool[aria-pressed="true"] { background: var(--fill); color: var(--tint); }

.address:active, .tool:active { transform: scale(0.97); }
.go:active { transform: scale(0.92); }

@media (hover: hover) and (pointer: fine) {
  .address:hover { background: var(--fill-hover); }
  .tool:hover { background: var(--fill); color: var(--label); }
  .go:hover { opacity: 0.85; }
  .go:hover svg { transform: translateX(2px); }
}

/* Tab bar: equal-width tabs, the active one raised. Switching is instant,
   like Safari — tabs get flipped through too often to animate. */
.tabbar {
  display: flex;
  gap: 2px;
  padding: 0 8px 7px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabbar::-webkit-scrollbar { display: none; }

.tab {
  flex: 1 1 0;
  min-width: 128px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--label-secondary);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: default;
  position: relative;
}
.tab span { overflow: hidden; text-overflow: ellipsis; }
.favicon { width: 16px; height: 16px; flex: none; border-radius: 4px; }

/* Hairline between inactive tabs, hidden next to the active one */
.tab + .tab::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 8px;
  bottom: 8px;
  width: 1px;
  background: var(--separator);
}
.tab[aria-selected="true"]::before,
.tab[aria-selected="true"] + .tab::before { display: none; }

.tab[aria-selected="true"] {
  background: var(--tab-active);
  box-shadow: var(--tab-shadow);
  color: var(--label);
}

@media (hover: hover) and (pointer: fine) {
  .tab:not([aria-selected="true"]):hover { background: var(--fill-hover); }
  .tab:hover::before, .tab:hover + .tab::before { display: none; }
}

/* Progress bar under the chrome, like Safari's */
.progress {
  position: absolute;
  left: 0;
  bottom: -0.5px;
  height: 2px;
  width: 100%;
  background: var(--tint);
  transform-origin: left;
  transform: scaleX(0);
  opacity: 0;
}
.loading .progress { opacity: 1; animation: progress 2.4s var(--ease-ios) forwards; }
.loaded .progress { transform: scaleX(1); opacity: 0; transition: transform 200ms ease-out, opacity 300ms ease 200ms; }
@keyframes progress { from { transform: scaleX(0); } to { transform: scaleX(0.85); } }

/* ---------- Viewport ---------- */
.viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
}
.frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
  transition: opacity 260ms var(--ease-out),
    width 500ms var(--ease-ios), height 500ms var(--ease-ios), border-radius 500ms var(--ease-ios);
}
.loading .frame { opacity: 0; transition-duration: 120ms, 500ms, 500ms, 500ms; }

/* Phone-width preview mode */
.window.phone .frame {
  width: 390px;
  height: min(844px, calc(100% - 48px));
  border-radius: 44px;
  box-shadow: 0 0 0 10px #1d1d1f, 0 0 0 11px #3a3a3c, 0 30px 60px rgba(0, 0, 0, 0.25);
}

/* Fallback card for sites that can't be embedded */
.blocked {
  display: none;
  text-align: center;
  padding: 32px;
  max-width: 360px;
}
.window.no-embed .frame { display: none; }
.window.no-embed .blocked { display: block; animation: rise 400ms var(--ease-out) both; }
.blocked .icon { width: 88px; height: 88px; margin: 0 auto 18px; border-radius: 22.37%; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18); }
.blocked h2 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.blocked p { margin: 6px 0 22px; color: var(--label-secondary); }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 22px;
  border-radius: 999px;
  background: var(--tint);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  transition: filter 150ms ease, transform 160ms var(--ease-out);
}
.btn:active { transform: scale(0.97); }
@media (hover: hover) and (pointer: fine) {
  .btn:hover { filter: brightness(1.08); }
}

/* ---------- First load: settle in, top to bottom ---------- */
.hero h1, .lede, .window { animation: rise 700ms var(--ease-out) both; }
.lede { animation-delay: 50ms; }
.window { animation-delay: 150ms; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

/* ---------- Small screens ---------- */
@media (max-width: 820px) {
  main { padding: 0 16px 24px; }
  .hero { padding: 64px 0 40px; }
  .lede { font-size: 17px; }
  .window { height: 78dvh; min-height: 480px; border-radius: 16px; }
  .lights, #device { display: none; }
  .window.phone .frame { width: 100%; height: 100%; border-radius: 0; box-shadow: none; } /* already phone-sized */
  .toolbar { grid-template-columns: minmax(0, 1fr) auto; padding: 0 8px 0 10px; }
  .tab { flex: none; min-width: 0; width: 132px; }
}

/* Reduced motion: keep fades, drop movement */
@media (prefers-reduced-motion: reduce) {
  .hero h1, .lede, .window, .window.no-embed .blocked { animation: fade 300ms ease both; animation-delay: 0ms; }
  .frame { transition-property: opacity; }
  .go:hover svg { transform: none; }
}
@keyframes fade { from { opacity: 0; } }
