:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #ffffff;
  --text: #18202f;
  --muted: #647084;
  --line: rgba(111, 123, 145, 0.22);
  --shadow: 0 20px 50px rgba(42, 50, 70, 0.12);
  --primary: #176df3;
  --primary-contrast: #ffffff;
  --danger: #d83c52;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #10131a;
  --surface: rgba(29, 34, 45, 0.8);
  --surface-solid: #1a1f2a;
  --text: #f4f7fb;
  --muted: #a5afc0;
  --line: rgba(199, 210, 229, 0.16);
  --shadow: 0 22px 56px rgba(0, 0, 0, 0.34);
  --primary: #7bb0ff;
  --primary-contrast: #0b1220;
  --danger: #ff7084;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: linear-gradient(180deg, var(--bg), color-mix(in srgb, var(--bg) 92%, var(--text)));
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
textarea,
select {
  font: inherit;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 3rem);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(22px);
  animation: fade-down 420ms ease both;
}

.back-link,
.admin-link {
  min-height: 2.5rem;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-weight: 700;
}

.back-link {
  color: var(--primary);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.admin-link {
  padding: 0 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
}

.icon-button {
  width: 2.75rem;
  height: 2.75rem;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.sun-icon,
.moon-icon {
  position: absolute;
  width: 1.1rem;
  height: 1.1rem;
  transition: transform 180ms ease, opacity 180ms ease;
}

.sun-icon {
  border: 2px solid currentColor;
  border-radius: 50%;
  box-shadow: 0 -0.55rem 0 -0.42rem currentColor, 0 0.55rem 0 -0.42rem currentColor, 0.55rem 0 0 -0.42rem currentColor, -0.55rem 0 0 -0.42rem currentColor;
  opacity: 0;
  transform: rotate(80deg) scale(0.72);
}

.moon-icon {
  border-radius: 50%;
  box-shadow: -0.26rem 0 0 0 currentColor;
  transform: translateX(0.18rem) rotate(-10deg);
  opacity: 1;
}

:root[data-theme="dark"] .sun-icon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

:root[data-theme="dark"] .moon-icon {
  opacity: 0;
  transform: translateX(0.18rem) rotate(-10deg) scale(0.72);
}

main {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
}

.hero {
  min-height: 27rem;
  display: flex;
  align-items: flex-end;
  padding: clamp(3rem, 8vw, 6rem) 0 2rem;
}

.hero-copy {
  animation: fade-up 560ms ease 80ms both;
}

.eyebrow {
  margin: 0 0 0.7rem;
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(2.55rem, 7vw, 5.7rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.hero-text {
  max-width: 42rem;
  margin: 1.4rem 0 0;
  color: var(--muted);
  font-size: clamp(1.05rem, 2.4vw, 1.35rem);
  line-height: 1.7;
}

.toolbar {
  display: grid;
  gap: 1rem;
  padding: 1rem 0 2rem;
  animation: fade-up 520ms ease 220ms both;
}

.side-ad {
  position: fixed;
  top: 8rem;
  z-index: 2;
  width: 160px;
  height: 600px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-solid) 78%, transparent);
}

.side-ad-left {
  left: max(1rem, calc((100vw - 1560px) / 2));
}

.side-ad-right {
  right: max(1rem, calc((100vw - 1560px) / 2));
}

.ad-preview-mode .side-ad {
  display: grid;
  place-items: center;
}

.ad-preview-mode .adsbygoogle {
  display: grid !important;
  place-items: center;
}

.ad-preview-mode .adsbygoogle::before {
  content: "AdSense 160 x 600";
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  writing-mode: vertical-rl;
}

.search-wrap {
  min-height: 3.4rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  border: 1px solid var(--line);
  border-radius: 1.4rem;
  background: var(--surface);
}

.search-wrap input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.chips {
  display: flex;
  gap: 0.6rem;
  overflow-x: auto;
  padding-bottom: 0.2rem;
}

.chip {
  flex: 0 0 auto;
  min-height: 2.35rem;
  padding: 0 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.chip.active {
  background: var(--text);
  color: var(--bg);
}

.gem-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  padding-bottom: 4rem;
}

.gem-card,
.login-panel,
.editor-form,
.admin-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.gem-card {
  position: relative;
  min-height: 22rem;
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  overflow: hidden;
  animation: card-in 520ms ease both;
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.gem-card:hover {
  border-color: color-mix(in srgb, var(--accent) 52%, var(--line));
  box-shadow: 0 24px 58px rgba(42, 50, 70, 0.16);
  transform: translateY(-4px);
}

.gem-card:nth-child(2) { animation-delay: 55ms; }
.gem-card:nth-child(3) { animation-delay: 110ms; }
.gem-card:nth-child(4) { animation-delay: 165ms; }
.gem-card:nth-child(5) { animation-delay: 220ms; }
.gem-card:nth-child(6) { animation-delay: 275ms; }

.gem-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 0.35rem;
  background: var(--accent);
}

.accent-blue { --accent: #3b82f6; }
.accent-pink { --accent: #ec4899; }
.accent-orange { --accent: #f97316; }
.accent-purple { --accent: #8b5cf6; }
.accent-green { --accent: #22c55e; }
.accent-teal { --accent: #14b8a6; }

.card-topline,
.item-actions,
.form-actions,
.admin-heading {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.card-topline,
.admin-heading {
  justify-content: space-between;
}

.category-pill,
.featured-pill {
  display: inline-flex;
  align-items: center;
  min-height: 1.85rem;
  padding: 0 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
}

.category-pill {
  background: color-mix(in srgb, var(--accent, var(--primary)) 15%, transparent);
  color: var(--text);
}

.featured-pill {
  background: var(--text);
  color: var(--bg);
}

.gem-card h2,
.admin-item h2 {
  margin: 1.25rem 0 0.75rem;
  font-size: 1.25rem;
  line-height: 1.25;
}

.gem-card p,
.admin-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.open-button {
  min-height: 3rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: auto;
  padding: 0 1rem;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-contrast);
  font-weight: 850;
  transition: transform 160ms ease, filter 160ms ease;
}

.open-button:not(.disabled):hover {
  filter: brightness(1.04);
  transform: translateY(-1px);
}

.open-button.disabled {
  background: color-mix(in srgb, var(--muted) 18%, transparent);
  color: var(--muted);
}

.empty-state {
  padding-bottom: 4rem;
  color: var(--muted);
  text-align: center;
}

.admin-shell {
  padding: clamp(2rem, 6vw, 4rem) 0 5rem;
}

.login-panel {
  width: min(28rem, 100%);
  margin: 4rem auto;
  padding: 2rem;
  animation: fade-up 520ms ease both;
}

.login-panel h1,
.admin-heading h1 {
  font-size: clamp(2rem, 5vw, 3.5rem);
}

.stack-form,
.editor-form {
  display: grid;
  gap: 1rem;
}

.stack-form {
  margin-top: 1.6rem;
}

.editor-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 1.6rem 0;
  padding: 1.25rem;
  animation: fade-up 520ms ease 80ms both;
}

.wide-field {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 0.45rem;
  color: var(--muted);
  font-weight: 750;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background: var(--surface-solid);
  color: var(--text);
  outline: 0;
  padding: 0.9rem 1rem;
}

textarea {
  resize: vertical;
}

.toggle-row {
  grid-auto-flow: column;
  grid-template-columns: auto 1fr;
  align-items: center;
}

.toggle-row input {
  width: 1.15rem;
  height: 1.15rem;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 2.85rem;
  border: 0;
  border-radius: 999px;
  padding: 0 1.1rem;
  font-weight: 850;
  cursor: pointer;
}

.primary-button {
  background: var(--primary);
  color: var(--primary-contrast);
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface-solid);
  color: var(--text);
}

.danger-button {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
}

.form-message {
  min-height: 1.5rem;
  margin: 0;
  color: var(--danger);
}

.admin-list {
  display: grid;
  gap: 0.8rem;
}

.admin-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  padding: 1rem;
  animation: card-in 420ms ease both;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fade-down {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}

@media (max-width: 880px) {
  .hero,
  .gem-grid,
  .admin-item {
    grid-template-columns: 1fr;
  }

  .hero {
    min-height: 0;
  }
}

@media (max-width: 1560px) {
  .side-ad {
    display: none;
  }
}

@media (max-width: 620px) {
  .site-header {
    padding-inline: 1rem;
  }

  .back-link {
    font-size: 0.9rem;
  }

  .admin-link {
    padding-inline: 0.8rem;
  }

  .hero {
    padding-top: 2rem;
  }

  h1 {
    font-size: 2.65rem;
  }

  .editor-form {
    grid-template-columns: 1fr;
  }

  .item-actions {
    align-items: stretch;
    flex-direction: column;
  }
}
