:root {
  --bg: #111;
  --fg: #eee;
  --accent: #5aa9e6;
  --err: #ff6b6b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
               "Noto Sans TC", "PingFang TC", sans-serif;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  background: rgba(17, 17, 17, 0.9);
  backdrop-filter: blur(6px);
  z-index: 10;
}

header h1 { margin: 0; font-size: 18px; font-weight: 600; }

#refresh {
  background: transparent;
  color: var(--fg);
  border: 1px solid #444;
  border-radius: 8px;
  font-size: 20px;
  padding: 6px 12px;
  cursor: pointer;
}

#refresh:disabled { opacity: 0.5; cursor: wait; }

#grid {
  display: grid;
  gap: 8px;
  padding: 8px;
  grid-template-columns: 1fr 1fr;
}

@media (min-width: 600px) {
  #grid { grid-template-columns: repeat(3, 1fr); }
}

.cell {
  position: relative;
  margin: 0;
  aspect-ratio: 1 / 1;
  background: #222;
  overflow: hidden;
  border-radius: 8px;
}

.cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: zoom-in;
  display: block;
}

.del-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 18px;
  line-height: 28px;
  text-align: center;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.15s, background 0.15s;
}

.del-btn:hover,
.del-btn:focus {
  opacity: 1;
  background: var(--err);
  outline: none;
}

/* Lightbox */
#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#lightbox[hidden] { display: none; }

#lightbox img {
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
}

.lightbox-actions {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
}

.lightbox-actions a,
.lightbox-actions button {
  background: rgba(0, 0, 0, 0.6);
  color: var(--fg);
  border: 1px solid #555;
  border-radius: 24px;
  padding: 10px 20px;
  text-decoration: none;
  font-size: 16px;
  cursor: pointer;
}

.lightbox-del-btn {
  background: rgba(80, 0, 0, 0.7);
  border-color: var(--err);
}

.lightbox-del-btn:hover,
.lightbox-del-btn:focus {
  background: var(--err);
  outline: none;
}

/* Login page */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  margin: 0;
}

.login-card {
  width: min(360px, 90vw);
  padding: 32px;
  background: #1a1a1a;
  border-radius: 12px;
}

.login-card h1 { margin: 0 0 24px; text-align: center; }

.login-card label {
  display: block;
  margin-bottom: 16px;
}

.login-card label span { display: block; margin-bottom: 6px; }

.login-card input[type="password"] {
  width: 100%;
  padding: 12px;
  background: #222;
  color: var(--fg);
  border: 1px solid #444;
  border-radius: 6px;
  font-size: 16px;
}

.login-card .err {
  color: var(--err);
  margin: 8px 0;
  font-size: 14px;
}

.login-card button {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
}

/* Toast — 右下角浮動，3 秒自動消失 */
#toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 200px;
  max-width: 320px;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.85);
  color: var(--fg);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-size: 14px;
  line-height: 1.4;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
}

/* iOS 12 Safari 不支援 flex gap，改用 adjacent-sibling margin。 */
.toast + .toast { margin-top: 8px; }

.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-left-color: var(--err); }
