* { box-sizing: border-box; }
:root {
  --sticky-offset: 0px;
}
body {
  margin: 0;
  min-height: 100vh;
  background: #f6f7f8;
  color: #161616;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif;
}
.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-gate[hidden] { display: none; }
.auth-card {
  width: min(380px, 100%);
  background: #fff;
  border: 1px solid #d7dadd;
  border-radius: 12px;
  padding: 28px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.08);
  text-align: center;
}
.auth-card h1 { margin: 0 0 10px; }
.auth-card p { margin: 0 0 22px; color: #565f68; font-size: 14px; }
.auth-label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 700; }
.auth-status { min-height: 28px; padding-top: 8px; color: #c62d2d; font-size: 13px; }
.auth-card input {
  text-align: center;
}
.auth-card input::placeholder {
  text-align: center;
}
.auth-submit {
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 10px 16px;
  background: #1f6feb;
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
.auth-submit:hover { background: #195fc9; }
header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(246, 247, 248, 0.94);
  border-bottom: 1px solid #d7dadd;
  backdrop-filter: blur(12px);
  padding: 22px 24px 28px;
}
h1 {
  margin: 0 0 22px;
  font-size: 22px;
  font-weight: 700;
}
.controls {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 160px;
  gap: 10px;
  max-width: 690px;
}
input, select {
  width: 100%;
  border: 1px solid #c8ccd0;
  border-radius: 6px;
  background: #fff;
  color: #161616;
  font: inherit;
  padding: 8px 10px;
}
main { padding: 18px 24px 32px; }
.summary {
  margin-bottom: 12px;
  color: #565f68;
  font-size: 13px;
}
table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid #d7dadd;
}
th, td {
  border-bottom: 1px solid #e5e7e9;
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}
tbody tr:nth-child(even) td { background: #f6f8fa; }
tbody tr:nth-child(odd) td { background: #fff; }
th {
  position: sticky;
  top: var(--sticky-offset);
  z-index: 1;
  background: #eef0f2;
  font-size: 12px;
  color: #4d5660;
  white-space: nowrap;
}
.sortable {
  appearance: none;
  display: inline-flex;
  align-items: center;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  padding: 0;
  cursor: pointer;
}
.sortable:hover { color: #111; }
.sort-hint {
  display: flex;
  align-items: center;
  margin-left: 4px;
}
.sort-hint img {
  height: 0.9em;
  width: auto;
  display: block;
  opacity: 0.85;
}
.title {
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.muted { color: #6a737d; font-size: 12px; }
.col-date { white-space: nowrap; width: 1%; color: #4d5660; }
.col-pw .pw { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.col-fav { width: 36px; text-align: center; }
.url-link {
  color: #1f6feb;
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
}
.url-link:hover { text-decoration: underline; }
.thumbnail-link {
  display: block;
  width: 160px;
}
.thumbnail {
  display: block;
  width: 160px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 6px;
  background: #e5e7e9;
}
.empty {
  padding: 32px;
  text-align: center;
  color: #6a737d;
  background: #fff;
}
.header-icons {
  position: absolute;
  top: 14px;
  right: 24px;
  display: flex;
  gap: 8px;
}
.icon-btn {
  appearance: none;
  border: 1px solid #c8ccd0;
  border-radius: 50%;
  background: #fff;
  color: #4d5660;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  font-size: 18px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.icon-btn:hover { background: #eef2f6; border-color: #9aa3ad; }
.icon-btn img { width: 24px; height: 24px; display: block; filter: invert(1); opacity: 0.7; }
.fav-btn {
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 2px;
  font-size: 18px;
  line-height: 1;
  color: #c8ccd0;
  transition: transform 0.2s ease, color 0.2s ease;
}
.fav-btn:hover { color: #e57373; }
.fav-btn.active { color: #e53935; }
.fav-btn.pop { animation: fav-pop 0.35s ease; }
@keyframes fav-pop {
  0% { transform: scale(1); }
  30% { transform: scale(1.35); }
  60% { transform: scale(0.9); }
  100% { transform: scale(1); }
}
.copy-btn {
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0 2px;
  font-size: 26px;
  line-height: 1;
  color: #b0b6be;
  transition: color 0.15s ease;
  flex-shrink: 0;
}
.copy-btn:hover { color: #4d5660; }
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(22, 22, 22, 0.88);
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  justify-content: center;
  align-items: center;
}
.overlay.open { display: flex; }
.dialog {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  max-width: 420px;
  width: calc(100% - 32px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.18);
}
.dialog h2 { margin: 0 0 16px; font-size: 18px; text-align: center; }
.dialog dt { font-weight: 700; margin-top: 12px; }
.dialog dt:first-child { margin-top: 0; }
.dialog dd { margin: 4px 0 0 0; color: #565f68; font-size: 14px; }
.dialog-close {
  appearance: none;
  border: 1px solid #c8ccd0;
  border-radius: 8px;
  background: #f7f8f9;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  padding: 8px 20px;
  margin-top: 20px;
  display: block;
  width: 100%;
}
.dialog-close:hover { background: #eef2f6; }
.fav-list { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow-y: auto; }
.fav-list li {
  padding: 10px 0;
  border-bottom: 1px solid #e5e7e9;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.fav-list li:last-child { border-bottom: 0; }
.fav-list .fav-title { font-weight: 600; }
.fav-list .fav-artist { color: #565f68; font-size: 13px; }
.fav-list .fav-remove {
  appearance: none;
  border: 0;
  background: transparent;
  color: #e53935;
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
  flex-shrink: 0;
}
.fav-empty { color: #6a737d; text-align: center; padding: 24px 0; }

/* Dark mode */
body.dark {
  background: #1a1a1a;
  color: #e0e0e0;
}
body.dark .auth-card {
  background: #2a2a2a;
  border-color: #444;
  box-shadow: 0 8px 30px rgba(0,0,0,0.28);
}
body.dark .auth-card p { color: #aaa; }
body.dark .auth-status { color: #ff8c8c; }
body.dark .auth-submit { background: #3478db; }
body.dark .auth-submit:hover { background: #4385e6; }
body.dark header {
  background: rgba(26, 26, 26, 0.94);
  border-bottom-color: #333;
}
body.dark input, body.dark select {
  background: #2a2a2a;
  color: #e0e0e0;
  color-scheme: dark;
  border-color: #444;
}
body.dark .summary { color: #999; }
body.dark table { background: #222; border-color: #333; }
body.dark th { background: #2a2a2a; color: #999; border-bottom-color: #333; }
body.dark td { border-bottom-color: #333; }
body.dark tbody tr:nth-child(even) td { background: #252525; }
body.dark tbody tr:nth-child(odd) td { background: #222; }
body.dark .empty { background: #222; color: #999; }
body.dark .icon-btn { background: #2a2a2a; color: #ccc; border-color: #555; }
body.dark .icon-btn:hover { background: #333; border-color: #777; }
body.dark .icon-btn img { filter: none; opacity: 0.8; }
body.dark .fav-btn { color: #555; }
body.dark .fav-btn:hover { color: #e57373; }
body.dark .copy-btn { color: #555; }
body.dark .copy-btn:hover { color: #ccc; }
body.dark .muted { color: #888; }
body.dark .col-date { color: #aaa; }
body.dark .sortable:hover { color: #fff; }
body.dark .url-link { color: #79b8ff; }
body.dark .dialog { background: #2a2a2a; color: #e0e0e0; }
body.dark .dialog dd { color: #999; }
body.dark .dialog-close { background: #333; border-color: #555; color: #e0e0e0; }
body.dark .dialog-close:hover { background: #444; }
body.dark .overlay.open { background: rgba(0,0,0,0.6); }
body.dark .fav-list li { border-bottom-color: #333; }
body.dark .fav-list .fav-artist { color: #888; }
body.dark .toast { background: rgba(255,255,255,0.9); color: #1a1a1a; }

@media (max-width: 760px) {
  body { font-size: 14px; }
  header { position: static; padding: 14px 12px 20px; }
  h1 { margin-bottom: 10px; font-size: 19px; }
  main { padding: 12px; }
  .controls { grid-template-columns: 1fr; }
  input, select { min-height: 40px; font-size: 16px; }
  .header-icons { top: 10px; right: 12px; gap: 6px; }
  .icon-btn { width: 36px; height: 36px; font-size: 15px; }
  .icon-btn img { width: 17px; height: 17px; }
  .copy-btn { font-size: 32px; }

  /* convert table to card layout */
  table, thead, tbody, tr, th, td { display: block; width: 100%; }
  thead {
    display: block;
    position: sticky;
    top: 0;
    z-index: 4;
  }
  thead tr {
    display: flex;
    gap: 16px;
    padding: 10px 12px;
    background: #eef0f2;
    border: 1px solid #d7dadd;
    border-bottom: 0;
  }
  th {
    position: static;
    width: auto;
    padding: 0;
    border-bottom: 0;
    background: transparent;
  }
  th:nth-child(n+3) { display: none; }
  tbody tr {
    padding: 12px;
    border-bottom: 1px solid #e5e7e9;
    position: relative;
  }
  tbody tr:nth-child(even) { background: #f6f8fa; }
  tbody tr:nth-child(odd) { background: #fff; }
  tbody tr:nth-child(even) td,
  tbody tr:nth-child(odd) td { background: transparent; }
  td { border-bottom: 0; padding: 2px 0; }
  .col-date { color: #565f68; font-size: 12px; }
  .col-title { font-size: 15px; }
  .col-fav {
    position: absolute;
    top: 10px;
    right: 12px;
    width: auto;
  }
  body.dark tbody tr { border-bottom-color: #333; }
  body.dark tbody tr:nth-child(even) { background: #252525; }
  body.dark tbody tr:nth-child(odd) { background: #222; }
  body.dark thead tr { background: #2a2a2a; border-color: #333; }
}