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

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --overlay: rgba(15, 23, 42, 0.5);
  --radius: 12px;
  --shadow: 0 20px 40px -12px rgba(15, 23, 42, 0.25);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #334155;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --danger: #f87171;
    --overlay: rgba(0, 0, 0, 0.6);
  }
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body.modal-open {
  overflow: hidden;
}

/* ---------- Page ---------- */
.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 4rem 1.5rem;
}

h1 {
  font-size: 1.75rem;
  margin: 0 0 0.5rem;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 2rem;
}

code {
  background: var(--border);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.9em;
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.output {
  min-height: 1.5rem;
  padding: 1rem;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.6rem 1.1rem;
  border-radius: 8px;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}

.btn:hover {
  border-color: var(--primary);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 50%, transparent);
  outline-offset: 2px;
}

.btn--primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn--primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn--ghost {
  background: transparent;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal[hidden] {
  display: none;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
  animation: fade-in 0.15s ease-out;
}

.modal__panel {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  animation: pop-in 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .modal__backdrop,
  .modal__panel {
    animation: none;
  }
}

.modal__title {
  margin: 0 0 1rem;
  font-size: 1.15rem;
}

.modal__message {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.modal__message[hidden] {
  display: none;
}

.modal__input {
  width: 100%;
  font: inherit;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.modal__input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
}

.modal__input[aria-invalid="true"] {
  border-color: var(--danger);
}

.modal__error {
  margin: 0.5rem 0 0;
  color: var(--danger);
  font-size: 0.875rem;
}

.modal__error[hidden] {
  display: none;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.25rem;
}