/* ken — minimal, dark, monospace, mobile-first.
 * palette kept to 5 custom properties. single accent (warm amber) so the
 * page has one clear interaction color. sizing via clamp() throughout so
 * the layout breathes from 360px phones up to wide desktops with no
 * breakpoints. soft radii, subtle transitions.
 */

:root {
  --bg: #0d0d0f;
  --fg: #e6e2d7;
  --fg-mute: #7a766c;
  --accent: #d4a76a;
  --accent-dim: #8a6b40;
  --border: #242329;
  --surface: #16161a;
  --surface-hover: #1c1c22;
  --danger: #e08872;
  --danger-dim: #4a2a22;

  --radius: clamp(6px, 0.6vmin, 10px);
  --gap: clamp(10px, 2vmin, 16px);
  --pad: clamp(14px, 3vmin, 22px);
  --text-body: clamp(13px, 1.6vmin, 15px);
  --text-small: clamp(11px, 1.3vmin, 12px);
  --text-h: clamp(15px, 2vmin, 18px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--fg);
  font: var(--text-body) / 1.5 ui-monospace, "SF Mono", Menlo, "Cascadia Code", monospace;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s;
}
a:hover { border-bottom-color: var(--accent); }

button {
  font: inherit;
  cursor: pointer;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  padding: clamp(8px, 1.4vmin, 10px) clamp(12px, 2vmin, 16px);
  border-radius: var(--radius);
  transition: all 0.15s;
  min-height: 44px;
}
button:hover:not(:disabled) {
  border-color: var(--fg-mute);
}
button:disabled { opacity: 0.5; cursor: wait; }

.hidden { display: none !important; }
.muted { color: var(--fg-mute); }

/* ------- header ------- */

header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--gap);
  padding: clamp(14px, 2.5vmin, 22px) var(--pad);
}

.brand {
  font-size: var(--text-h);
  color: var(--fg);
  border-bottom: none;
  letter-spacing: -0.01em;
}
.brand:hover { border-bottom: none; color: var(--accent); }

.signed-nav {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: var(--text-small);
  color: var(--fg-mute);
  font-variant-numeric: tabular-nums;
}
.session-handle { color: var(--accent); }
.sep { color: var(--fg-mute); opacity: 0.4; }

.text-btn {
  background: transparent;
  border: none;
  padding: 0;
  min-height: 0;
  color: var(--fg-mute);
  font: inherit;
  font-size: var(--text-small);
  cursor: pointer;
  transition: color 0.15s;
}
.text-btn:hover { color: var(--fg); }

/* ------- footer ------- */

footer {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 8px;
  padding: clamp(20px, 4vmin, 40px) var(--pad);
  font-size: var(--text-small);
  color: var(--fg-mute);
}
footer .text-btn { color: var(--fg-mute); }
footer .text-btn:hover { color: var(--accent); }
footer a { color: var(--fg-mute); }
footer a:hover { color: var(--accent); }

/* ------- main ------- */

main {
  max-width: 820px;
  margin: 0 auto;
  padding: var(--pad);
  padding-bottom: clamp(40px, 8vmin, 80px);
}

.row {
  position: relative;
  margin-bottom: var(--gap);
  display: flex;
  gap: var(--gap);
}

.row input[type="text"],
#search-form input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: clamp(12px, 2vmin, 16px);
  font: inherit;
  /* 16px floor — iOS Safari auto-zooms into any text input rendered
     smaller than that, which is obnoxious on phones. max() keeps the
     desktop clamp behavior intact when --text-body ever exceeds 16. */
  font-size: max(16px, var(--text-body));
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s;
  min-height: 44px;
}
.row input[type="text"]:focus,
#search-form input:focus { border-color: var(--accent-dim); }
.row input[type="text"]::placeholder,
#search-form input::placeholder { color: var(--fg-mute); }

/* share view: search input is locked to the shared query. visually
   signal that the input is fixed — no focus outline, muted fill, text
   is still selectable/copyable but not editable (readonly, not disabled). */
#search-form input[readonly] {
  background: transparent;
  border-style: dashed;
  border-color: var(--border);
  color: var(--fg-mute);
  cursor: default;
}
#search-form input[readonly]:focus {
  border-color: var(--border);
  outline: none;
}

#signed-out .row button {
  background: var(--accent-dim);
  color: var(--fg);
  border-color: var(--accent-dim);
}
#signed-out .row button:hover {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* ------- typeahead ------- */

.typeahead {
  position: relative;
  flex: 1;
  display: flex;
}
.typeahead input { flex: 1; }

.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  z-index: 10;
  max-height: 320px;
  overflow-y: auto;
}
.suggestions li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: clamp(8px, 1.5vmin, 12px) clamp(10px, 2vmin, 14px);
  cursor: pointer;
  font-size: var(--text-small);
  border-bottom: 1px solid var(--border);
  min-height: 44px;
}
.suggestions li:last-child { border-bottom: none; }
.suggestions li.active,
.suggestions li:hover { background: var(--surface-hover); }
.suggestions img,
.suggestions .avatar-placeholder {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
  object-fit: cover;
}
.suggestions .handle { color: var(--fg); }
.suggestions .display { color: var(--fg-mute); }

/* ------- status / progress ------- */

.status {
  font-size: var(--text-small);
  color: var(--fg-mute);
  margin-bottom: var(--gap);
  padding: clamp(10px, 1.8vmin, 14px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.status.error { color: var(--danger); border-color: var(--danger-dim); }

.progress {
  margin-bottom: var(--gap);
  padding: clamp(12px, 2vmin, 16px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 10px;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.4s ease-out;
  position: relative;
}
.progress-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.12), transparent);
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: var(--gap);
  font-size: var(--text-small);
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
  flex-wrap: wrap;
}
.progress-flavor {
  font-size: var(--text-small);
  min-height: 1.4em;
  transition: opacity 0.2s;
}

/* ------- pack meta (single compact line) ------- */

.pack-meta {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  font-size: var(--text-small);
  padding: clamp(10px, 1.5vmin, 14px) clamp(2px, 1vmin, 6px);
  font-variant-numeric: tabular-nums;
}

.text-btn-accent {
  color: var(--accent);
  font-size: var(--text-small);
}
.text-btn-accent:hover { color: var(--fg); }

.text-btn-danger {
  color: var(--danger);
  font-size: var(--text-small);
}
.text-btn-danger:hover { color: var(--fg); }

#share-btn { margin-left: auto; }

#share-modal input[type="text"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 10px 12px;
  font: inherit;
  /* same 16px floor — iOS zooms on anything smaller */
  font-size: max(16px, var(--text-small));
  border-radius: var(--radius);
  margin-top: clamp(10px, 2vmin, 14px);
  outline: none;
}
#share-modal input[type="text"]:focus { border-color: var(--accent-dim); }
#share-modal .share-actions {
  display: flex;
  gap: 8px;
  margin-top: clamp(12px, 2vmin, 16px);
}
#share-modal .share-actions button { flex: 1; }
#share-modal #share-copy {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  color: var(--fg);
}
#share-modal #share-copy:hover {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* ------- results ------- */

.results {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(10px, 1.8vmin, 14px);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  transition: background 0.1s, border-color 0.1s;
}
.result:hover {
  background: var(--surface-hover);
  border-color: var(--fg-mute);
}

.result .head {
  grid-column: 1;
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.result .collection-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.result .collection-name {
  font-size: var(--text-small);
  color: var(--fg-mute);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.result .collection-logo-slot {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: var(--border);
  flex-shrink: 0;
  display: inline-flex;
  overflow: hidden;
}
.result .collection-logo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.result .date {
  font-size: var(--text-small);
  color: var(--fg-mute);
  margin-left: auto;
  white-space: nowrap;
}

.result .body {
  grid-column: 1;
  font-size: var(--text-body);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.result .body-second {
  grid-column: 1;
  font-size: var(--text-small);
  color: var(--fg-mute);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.result .actions {
  grid-column: 2;
  grid-row: 1 / span 3;
  display: flex;
  align-items: start;
}
.result .pdsls-link {
  color: var(--fg-mute);
  font-size: var(--text-small);
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid transparent;
}
.result .pdsls-link:hover {
  color: var(--accent);
  border-color: var(--border);
}

/* ------- about modal ------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(20px, 4vmin, 32px);
  max-width: min(92vw, 460px);
  z-index: 101;
}
.modal h2 {
  font-size: var(--text-h);
  margin-bottom: clamp(10px, 2vmin, 14px);
  color: var(--fg);
  font-weight: 500;
}
.modal p {
  font-size: var(--text-small);
  line-height: 1.6;
  color: var(--fg);
  margin-bottom: clamp(8px, 1.5vmin, 12px);
}
.modal p:last-of-type { color: var(--fg-mute); }
.modal ul.about-links {
  list-style: none;
  margin: clamp(14px, 2.5vmin, 20px) 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.modal ul.about-links a { font-size: var(--text-small); }
.modal button {
  margin-top: clamp(10px, 2vmin, 14px);
  font-size: var(--text-small);
}

/* ------- mobile layout tweaks ------- */

@media (max-width: 520px) {
  header { gap: 8px; }
  .stats { flex-basis: 100%; order: 5; margin-left: 0; }
  #signed-out .row { flex-direction: column; }
  #signed-out .row button { width: 100%; }
  .pack-actions-row { flex-direction: column; align-items: stretch; }
  .pack-btn { width: 100%; }
  .result {
    grid-template-columns: 1fr;
  }
  .result .actions {
    grid-column: 1;
    grid-row: auto;
    justify-content: flex-end;
  }
}
