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

/* Color tokens — dark mode default. */
:root {
  --color-bg:          #0f0f13;
  --color-surface:     #1a1a24;
  --color-surface-hover: #22222e;
  --color-border:      #2a2a38;
  --color-border-hover: #3a3a50;
  --color-ring:        #1a1a24;
  --color-text:        #e8e8f0;
  --color-text-strong: #f0f0fa;
  --color-text-muted:  #e0e0ee;
  --color-footer:      #50505e;
  --color-footer-link: #70708e;
  --color-footer-link-hover: #9090b0;
  --color-accent:      #8b8bf5;
  --color-accent-soft: rgba(139, 139, 245, 0.12);
}

@media (prefers-color-scheme: light) {
  :root {
    --color-bg:          #f2f2f7;
    --color-surface:     #ffffff;
    --color-surface-hover: #f7f7fb;
    --color-border:      #e0e0e8;
    --color-border-hover: #c8c8d4;
    --color-ring:        #e5e5ea;
    --color-text:        #1c1c1e;
    --color-text-strong: #1c1c1e;
    --color-text-muted:  #1c1c1e;
    --color-footer:      #8e8e93;
    --color-footer-link: #636366;
    --color-footer-link-hover: #3a3a3c;
    --color-accent:      #5856d6;
    --color-accent-soft: rgba(88, 86, 214, 0.08);
  }
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

main {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 3rem 1rem 2rem;
}

@media (min-width: 600px) {
  main {
    align-items: center;
    padding: 2rem 1rem;
  }
}

.card {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  transition: max-width 0.2s ease;
}

@media (min-width: 700px) {
  .card--wide {
    max-width: 1400px;
  }
}

/* Profile section. */
.profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.avatar {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--color-border);
  box-shadow: 0 0 0 4px var(--color-ring);
  touch-action: manipulation;
}

.profile-name {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--color-text-strong);
}

/* Links. */
.links {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Hidden links with groups use multi-column layout on desktop. */
.links--hidden {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (min-width: 700px) {
  .links--hidden:not(.links--filtered) {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1200px) {
  .links--hidden:not(.links--filtered) {
    grid-template-columns: repeat(3, 1fr);
  }
}

.link-group-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.link-group-heading {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  opacity: 0.7;
}

/* "Recent" sub-section on the public panel, set apart from the main links above. */
.link-group-wrapper--recent {
  padding-top: 0.5rem;
  border-top: 1px solid var(--color-border);
}

.link-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Highlighted links span the full width above the other groups. */
.link-group-wrapper--highlight {
  grid-column: 1 / -1;
}

/* Highlighted links share one row on wide screens and stack while filtering. */
.link-group-wrapper--highlight .link-group {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem 1.5rem;
}

/* Fixed steps of 1, 2 and 4 columns, so the row never breaks into an uneven 3 + 1. */
@media (min-width: 700px) {
  .links--hidden:not(.links--filtered) .link-group-wrapper--highlight .link-group {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1200px) {
  .links--hidden:not(.links--filtered) .link-group-wrapper--highlight .link-group {
    grid-template-columns: repeat(4, 1fr);
  }
}

.link-group-wrapper--highlight .link-item {
  background: var(--color-accent-soft);
  border-color: var(--color-accent);
}

.link-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.link-item:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-border-hover);
  transform: translateY(-1px);
}

.link-item:active {
  transform: translateY(0);
}

.link-item:focus-visible {
  outline: 2px solid var(--color-border-hover);
  outline-offset: -2px;
  background: var(--color-surface-hover);
  border-color: var(--color-border-hover);
}

.link-thumb {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--color-border);
}

.link-label {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--color-text-muted);
}

.link-arrow {
  margin-left: auto;
  opacity: 0.35;
  flex-shrink: 0;
}

/* Remove arrow margin when badge is present */
.link-badge ~ .link-arrow {
  margin-left: 0;
}

/* Restore native hidden semantics overridden by display:flex on .links. */
[hidden] { display: none !important; }

/* Update banner shown when config.yaml has changed. */
.update-banner {
  width: 100%;
  padding: 0.6rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  font-size: 0.875rem;
  color: var(--color-text-muted);
  text-align: center;
}

.update-banner button {
  background: none;
  border: none;
  color: var(--color-text-strong);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

/* Notice shown when JS is unavailable or links fail to load. */
.notice {
  text-align: center;
  font-size: 0.9rem;
  color: var(--color-text-muted);
  padding: 0.5rem 0;
}

/* Status badges shown inline with links. */
.link-badge {
  height: 18px;
  width: auto;
  margin-left: auto;
  border-radius: 3px;
  opacity: 0.85;
  transition: opacity 0.15s;
}

.link-item:hover .link-badge {
  opacity: 1;
}

/* Search input shown above the internal links panel. */
.internal-search {
  width: 100%;
  padding: 0.65rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  color: var(--color-text);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.internal-search:focus {
  border-color: var(--color-border-hover);
}

/* Hidden links panel — shown on keypress, no thumbnails. */
.links--hidden .link-item {
  padding: 0.6rem 1.1rem;
  gap: 0;
  opacity: 0.8;
}

.links--hidden .link-item:hover {
  opacity: 1;
}

/* Unlock form shown in the internal panel before the password is entered. */
.unlock-form {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  grid-column: 1 / -1;
}

.unlock-input {
  width: 100%;
  padding: 0.65rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  color: var(--color-text);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.unlock-input:focus {
  border-color: var(--color-border-hover);
}

.unlock-btn {
  align-self: flex-start;
  padding: 0.5rem 1.1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  color: var(--color-text-muted);
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

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

.unlock-error {
  font-size: 0.875rem;
  color: #e06060;
  padding: 0 0.2rem;
}

/* Footer. */
footer {
  padding: 1rem;
  text-align: center;
  font-size: 0.78rem;
  color: var(--color-footer);
}

footer a {
  color: var(--color-footer-link);
  text-decoration: none;
}

footer a:hover {
  color: var(--color-footer-link-hover);
}
