:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --field: #f9fafb;
  --text: #16181d;
  --muted: #5d6470;
  --border: #e1e4e9;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-text: #ffffff;
  --accent-soft: #eef0fe;
  --danger: #b42318;
  --danger-soft: #fef1f0;
  --focus: #818cf8;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.04), 0 6px 20px rgb(16 24 40 / 0.06);
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #161920;
    --field: #0e1014;
    --text: #e7e9ee;
    --muted: #98a0ad;
    --border: #282d37;
    --accent: #8b93f8;
    --accent-hover: #a7adfa;
    --accent-text: #0e1014;
    --accent-soft: #1f2340;
    --danger: #f97066;
    --danger-soft: #2a1715;
    --shadow: none;
  }
}

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

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
}

code,
pre {
  font-family: var(--mono);
  font-size: 0.875em;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.page {
  display: grid;
  /* minmax(0, …) so an 8,000-character URL on one line, truncated with an
     ellipsis, cannot widen the column past the page. */
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
  max-width: 760px;
  margin: 0 auto;
  padding: 56px 20px 72px;
}

.masthead h1 {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo {
  width: 36px;
  height: 36px;
  flex: none;
}

.logo-tile {
  fill: var(--accent);
}

.logo-glyph {
  fill: none;
  stroke: var(--accent-text);
  stroke-width: 2.4;
  stroke-linecap: round;
}

.tagline {
  margin: 6px 0 0;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

.label {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

h2.label {
  line-height: 1.5;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

/* ----------------------------------------------------------------- form --- */

textarea {
  display: block;
  width: 100%;
  min-height: 6.2em;
  max-height: 45vh;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--field);
  color: var(--text);
  font: 14px/1.5 var(--mono);
  word-break: break-all;
  resize: vertical;
  field-sizing: content;
}

textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.count {
  min-height: 1.5em;
  margin-top: 4px;
  text-align: right;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-top: 4px;
}

.inline {
  display: flex;
  gap: 8px;
}

select,
input[type="number"] {
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
}

input[type="number"] {
  width: 84px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 120ms, border-color 120ms, color 120ms;
}

.button:disabled {
  cursor: progress;
  opacity: 0.7;
}

.primary {
  background: var(--accent);
  color: var(--accent-text);
}

.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.secondary {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.submit {
  min-width: 128px;
  margin-left: auto;
}

.error {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 14px;
}

/* --------------------------------------------------------------- result --- */

.result {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: center;
}

.short-link {
  display: inline-block;
  max-width: 100%;
  color: var(--accent);
  font: 600 21px/1.35 var(--mono);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.short-link:hover {
  text-decoration: underline;
}

.original {
  margin: 8px 0 4px;
  overflow: hidden;
  color: var(--muted);
  font: 13px/1.4 var(--mono);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.expired {
  color: var(--danger);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.qr {
  width: 176px;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

.qr svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* -------------------------------------------------------------- history --- */

.history-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.history h2 {
  margin: 0;
  font-size: 17px;
}

.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.link-button:hover {
  color: var(--danger);
}

.empty {
  margin: 18px 0 4px;
  color: var(--muted);
  font-size: 14px;
}

.history-list {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.history-main {
  flex: 1;
  min-width: 0;
}

.history-short {
  font: 600 15px/1.4 var(--mono);
  text-decoration: none;
  word-break: break-all;
}

.history-short:hover {
  text-decoration: underline;
}

.history-item.expired .history-short {
  color: var(--muted);
  text-decoration: line-through;
}

.history-original,
.history-meta {
  margin: 2px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-original {
  font-family: var(--mono);
  font-size: 12.5px;
}

.history-item.expired .history-meta {
  color: var(--danger);
}

.history-actions {
  display: flex;
  flex: none;
  gap: 6px;
}

.button.small {
  height: 32px;
  padding: 0 11px;
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}

.button.small:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.button.small.ghost {
  border-color: transparent;
  color: var(--muted);
  font-size: 18px;
}

.button.small.ghost:hover {
  color: var(--danger);
}

/* ------------------------------------------------------------------ API --- */
/* The link on the main page. */

.api-link h2 {
  margin: 0 0 4px;
  font-size: 17px;
}

.api-link a {
  font-family: var(--mono);
  overflow-wrap: anywhere;
}

/* The instructions page, GET /gen. */

.brand {
  display: inline-flex;
  border-radius: 8px;
}

.doc h2 {
  margin: 0 0 12px;
  font-size: 19px;
  letter-spacing: -0.01em;
}

.doc h3 {
  margin: 20px 0 8px;
  font-size: 14px;
}

.doc p {
  margin: 0 0 12px;
  font-size: 15px;
}

.doc .note {
  color: var(--muted);
  font-size: 14px;
}

.doc pre {
  margin: 0 0 12px;
  padding: 12px 14px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--field);
  line-height: 1.55;
}

.doc :not(pre) > code {
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--accent-soft);
  white-space: nowrap;
}

.doc .card > :last-child {
  margin-bottom: 0;
}

.table-scroll {
  overflow-x: auto;
}

.doc table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.doc th,
.doc td {
  padding: 9px 12px 9px 0;
  border-top: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.doc thead th {
  border-top: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

/* ---------------------------------------------------------------- other --- */

.offscreen {
  position: fixed;
  top: -1000px;
  left: -1000px;
  opacity: 0;
}

.narrow {
  max-width: 520px;
  padding-top: 15vh;
}

.notfound h1 {
  margin: 0 0 8px;
  font-size: 22px;
}

.notfound p {
  margin: 0 0 12px;
  color: var(--muted);
}

@media (max-width: 600px) {
  .page {
    padding-top: 32px;
  }

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

  .short-link {
    font-size: 18px;
  }

  .qr {
    justify-self: center;
    width: 220px;
  }

  .submit {
    width: 100%;
    margin-left: 0;
  }

  /* stretch, not flex-start: a stacked item must take the card's width rather
     than its own, or a long URL on one line widens the whole page. */
  .history-item {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .history-actions {
    align-self: flex-start;
  }
}
