:root {
  color-scheme: dark;
  --bg: #080d1a;
  --bg-elevated: #0e1526;
  --surface: rgba(18, 27, 47, 0.88);
  --surface-strong: #151f35;
  --surface-hover: #1b2944;
  --border: rgba(156, 177, 215, 0.16);
  --border-strong: rgba(156, 177, 215, 0.3);
  --text: #f5f7fb;
  --muted: #9ba9c2;
  --accent: #6d7cff;
  --accent-hover: #8290ff;
  --accent-soft: rgba(109, 124, 255, 0.14);
  --cyan: #59d8e8;
  --success: #55d6a9;
  --danger: #ff7f96;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 15% -10%, rgba(89, 216, 232, 0.1), transparent 35rem),
    radial-gradient(circle at 85% 0%, rgba(109, 124, 255, 0.16), transparent 34rem),
    var(--bg);
  font-size: 1rem;
  line-height: 1.55;
}

button,
input,
textarea {
  font: inherit;
}

button,
a,
label {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
}

[hidden] {
  display: none !important;
}

.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 {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  min-height: 76px;
  padding: 12px max(24px, calc((100vw - 1200px) / 2));
  border-bottom: 1px solid var(--border);
  background: rgba(8, 13, 26, 0.82);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  width: fit-content;
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid rgba(109, 124, 255, 0.55);
  border-radius: 11px;
  background: linear-gradient(145deg, rgba(109, 124, 255, 0.3), rgba(89, 216, 232, 0.12));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  color: #dce1ff;
  font-size: 0.95rem;
}

.main-nav {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: rgba(14, 21, 38, 0.7);
}

.main-nav a {
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
  text-decoration: none;
  transition: color 160ms ease, background 160ms ease;
}

.main-nav a:hover {
  color: var(--text);
}

.main-nav a[aria-current="page"] {
  color: var(--text);
  background: var(--surface-hover);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.local-badge {
  display: inline-flex;
  align-items: center;
  justify-self: end;
  gap: 8px;
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid rgba(85, 214, 169, 0.22);
  border-radius: 999px;
  background: rgba(85, 214, 169, 0.08);
  color: #b6f4dd;
  font-size: 0.82rem;
  font-weight: 700;
}

.local-badge span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(85, 214, 169, 0.12);
}

.app-shell {
  width: min(1200px, calc(100% - 48px));
  margin: 0 auto;
  padding: 54px 0 32px;
}

.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 28px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--cyan);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(2rem, 4vw, 3.25rem);
  line-height: 1.05;
  letter-spacing: -0.045em;
}

h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.page-heading p:last-child {
  max-width: 610px;
  margin: 0;
  color: var(--muted);
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, rgba(21, 31, 53, 0.94), rgba(14, 21, 38, 0.92));
  box-shadow: var(--shadow);
}

.key-card {
  margin-bottom: 18px;
  padding: 22px;
}

.card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 17px;
}

.card-heading > div {
  display: flex;
  align-items: center;
  gap: 11px;
}

.card-heading.compact {
  min-height: 30px;
  margin-bottom: 14px;
}

.step-number {
  display: inline-grid;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid rgba(109, 124, 255, 0.26);
  border-radius: 9px;
  background: var(--accent-soft);
  color: #b8c0ff;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.7rem;
  font-weight: 800;
}

.helper,
.counter {
  color: var(--muted);
  font-size: 0.8rem;
}

.key-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.input-wrap {
  position: relative;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  outline: none;
  background: rgba(5, 10, 20, 0.58);
  color: var(--text);
  caret-color: var(--cyan);
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

input {
  min-height: 48px;
  padding: 11px 94px 11px 14px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.92rem;
}

textarea {
  min-height: 270px;
  padding: 16px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.94rem;
  line-height: 1.65;
}

input::placeholder,
textarea::placeholder {
  color: #71809c;
}

input:focus,
textarea:focus {
  border-color: rgba(109, 124, 255, 0.82);
  background: rgba(5, 10, 20, 0.78);
  box-shadow: 0 0 0 4px rgba(109, 124, 255, 0.13);
}

textarea[readonly] {
  color: #d7def0;
}

.input-action {
  position: absolute;
  top: 50%;
  right: 8px;
  min-height: 34px;
  padding: 6px 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 700;
}

.input-action:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.key-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 720;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease, opacity 140ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:active:not(:disabled) {
  transform: translateY(0);
}

.button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.button-primary {
  border-color: rgba(141, 151, 255, 0.42);
  background: linear-gradient(135deg, #6272f3, #7c65e8);
  box-shadow: 0 8px 24px rgba(98, 114, 243, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.button-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #7382fa, #8a74ed);
}

.button-secondary,
.button-ghost,
.button-mode {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.035);
  color: #dbe1ed;
}

.button-secondary:hover:not(:disabled),
.button-ghost:hover:not(:disabled),
.button-mode:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.07);
}

.button-ghost {
  background: transparent;
  color: var(--muted);
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.editor-card {
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: 22px;
}

.editor-card textarea {
  flex: 1;
}

.action-stack {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.button-large {
  min-height: 64px;
  flex-direction: column;
  align-items: flex-start;
  padding: 11px 14px;
  text-align: left;
}

.button-large span {
  font-size: 0.92rem;
}

.button-large small {
  color: rgba(245, 247, 251, 0.65);
  font-size: 0.72rem;
  font-weight: 550;
}

.button-mode {
  align-items: flex-start;
}

.single-action {
  width: 100%;
  margin-top: 14px;
}

.copy-button {
  width: 100%;
  margin-top: 14px;
}

.output-card {
  position: relative;
  overflow: hidden;
}

.output-card::before {
  position: absolute;
  top: 0;
  right: 28px;
  width: 100px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--cyan), transparent);
  content: "";
  opacity: 0.7;
}

.footer {
  width: min(1200px, calc(100% - 48px));
  margin: 0 auto;
  padding: 12px 0 max(32px, env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 0.82rem;
}

.footer p {
  margin: 0;
}

.footer strong {
  color: #cbd3e3;
}

.toast {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 50;
  max-width: min(390px, calc(100vw - 40px));
  padding: 12px 15px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: #182238;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.38);
  color: var(--text);
  font-size: 0.88rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  border-color: rgba(255, 127, 150, 0.42);
  color: #ffd8df;
}

:focus-visible {
  outline: 3px solid rgba(89, 216, 232, 0.72);
  outline-offset: 3px;
}

@media (max-width: 820px) {
  .topbar {
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 10px 18px;
  }

  .main-nav {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
  }

  .main-nav a {
    flex: 1;
    text-align: center;
  }

  .local-badge {
    grid-column: 2;
    grid-row: 1;
  }

  .app-shell {
    width: min(100% - 32px, 680px);
    padding-top: 36px;
  }

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

  .editor-card textarea {
    min-height: 230px;
  }

  .footer {
    width: min(100% - 32px, 680px);
  }
}

@media (max-width: 560px) {
  .topbar {
    padding-right: max(14px, env(safe-area-inset-right));
    padding-left: max(14px, env(safe-area-inset-left));
  }

  .brand {
    font-size: 1rem;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .local-badge {
    padding: 6px 10px;
  }

  .app-shell {
    width: calc(100% - 24px);
    padding-top: 28px;
  }

  .page-heading {
    display: block;
    margin-bottom: 22px;
  }

  .page-heading .clear-page {
    width: 100%;
    margin-top: 18px;
  }

  h1 {
    font-size: 2.15rem;
  }

  .card,
  .key-card,
  .editor-card {
    border-radius: 17px;
  }

  .key-card,
  .editor-card {
    padding: 16px;
  }

  .card-heading {
    align-items: flex-start;
  }

  .card-heading:not(.compact) {
    flex-direction: column;
    gap: 5px;
  }

  .helper {
    padding-left: 39px;
  }

  .key-row {
    grid-template-columns: 1fr;
  }

  .key-row > .button,
  .key-tools > .button {
    width: 100%;
  }

  .action-stack {
    grid-template-columns: 1fr;
  }

  textarea {
    min-height: 210px;
    font-size: 1rem;
  }

  .footer {
    width: calc(100% - 24px);
  }

  .toast {
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    max-width: calc(100vw - 24px);
  }
}

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