:root {
  color-scheme: dark;
  --bg: #101419;
  --panel: #161d25;
  --panel-soft: #1d2833;
  --code-bg: #0f151b;
  --text: #f4f7fa;
  --muted: #9cabba;
  --line: #2a3744;
  --line-soft: #1f2a35;
  --accent: #66c0f4;
  --accent-strong: #8fd3ff;
  --radius: clamp(6px, 1.5vw, 8px);
  --radius-sm: clamp(4px, 1vw, 6px);
  --main-max: 720px;
  --page-inline: clamp(0px, 3vw, 24px);
  --page-block: clamp(12px, 3.5vw, 32px);
  --main-pad: clamp(16px, 4.5vw, 32px);
  --gap-sm: clamp(6px, 1.5vw, 8px);
  --gap-md: clamp(10px, 2.5vw, 14px);
  --gap-lg: clamp(16px, 4vw, 24px);
  --text-base: clamp(0.9375rem, 2.4vw, 1rem);
  --text-sm: clamp(0.8125rem, 2.1vw, 0.875rem);
  --text-xs: clamp(0.75rem, 1.9vw, 0.85rem);
  --heading: clamp(1.35rem, 4.8vw, 1.75rem);
  --code-size: clamp(0.75rem, 2.3vw, 0.92rem);
  --touch: clamp(42px, 11vw, 48px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  padding:
    max(var(--page-block), env(safe-area-inset-top))
    max(var(--page-inline), env(safe-area-inset-right))
    max(var(--page-block), env(safe-area-inset-bottom))
    max(var(--page-inline), env(safe-area-inset-left));
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Aptos", system-ui, sans-serif;
  font-size: var(--text-base);
  line-height: 1.5;
}

main {
  width: 100%;
  max-width: var(--main-max);
  min-width: 0;
  padding: var(--main-pad);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.masthead {
  display: grid;
  gap: var(--gap-sm);
  margin-bottom: var(--gap-lg);
}

h1 {
  margin: 0;
  font-size: var(--heading);
  line-height: 1.15;
  font-weight: 700;
}

p {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-sm);
  max-width: 55ch;
}

form {
  display: grid;
  gap: var(--gap-md);
  margin-bottom: var(--gap-lg);
  container-type: inline-size;
  min-width: 0;
}

label,
.output span {
  color: var(--text);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.form-message {
  min-height: 1.5em;
  font-size: var(--text-sm);
  color: var(--muted);
}

.input-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-md);
  min-width: 0;
}

input,
button,
code {
  font: inherit;
}

input {
  flex: 1 1 12rem;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  min-height: var(--touch);
  padding: 0.65em 0.85em;
  font-size: max(16px, var(--text-base));
  color: var(--text);
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(102, 192, 244, 0.18);
}

.input-row > button {
  flex: 1 1 auto;
  min-height: var(--touch);
  padding: 0.65em 1.1em;
  white-space: nowrap;
}

button {
  color: #0b1116;
  background: var(--accent);
  border: 0;
  border-radius: var(--radius-sm);
  font-weight: 700;
  cursor: pointer;
  transition: background-color 120ms ease;
  -webkit-tap-highlight-color: transparent;
}

button:hover {
  background: var(--accent-strong);
}

.output {
  display: grid;
  gap: var(--gap-lg);
  padding: var(--gap-lg) 0;
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  min-width: 0;
}

.output div {
  display: grid;
  gap: var(--gap-sm);
  min-width: 0;
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--gap-sm);
  width: 100%;
}

code {
  display: block;
  min-width: 0;
  max-width: 100%;
  padding: 0.65em 0.75em;
  color: var(--text);
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: var(--code-size);
  line-height: 1.45;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  white-space: nowrap;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

nav {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 9.5rem), 1fr));
  gap: var(--gap-sm);
  margin-top: var(--gap-lg);
  font-size: var(--text-sm);
}

a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

a:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

.actions button,
.actions a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-width: 0;
  min-height: var(--touch);
  padding: 0.5em 0.75em;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 600;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.actions button {
  color: var(--text);
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.actions button:hover {
  border-color: var(--accent);
  background: var(--panel-soft);
}

.actions a {
  border: 1px solid var(--line);
}

.actions a:hover {
  border-color: var(--accent);
  text-decoration: none;
}

nav a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch);
  padding: 0.5em 0.65em;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: var(--text-xs);
}

nav a:hover {
  border-color: var(--accent);
  text-decoration: none;
}

/* Stack the form row only when the card itself is narrow */
@container (max-width: 26rem) {
  .input-row {
    flex-direction: column;
  }

  .input-row > button {
    width: 100%;
  }
}

/* Edge-to-edge card on very small phones — avoids double gutter squeeze */
@media (max-width: 30rem) {
  :root {
    --page-inline: 0px;
  }

  body {
    justify-content: flex-start;
  }

  main {
    border-inline: 0;
    border-radius: 0;
  }
}

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