:root {
  color-scheme: light dark;

  --black: #000;
  --white: #fff;

  --bg: var(--white);
  --fg: var(--black);

  --bar-bg: var(--black);
  --bar-fg: var(--white);

  --border: 3px solid var(--black);

  --gray-300: #ddd;
  --gray-500: #888;
  --gray-700: #555;

  --deco-bg: var(--gray-300);
  --deco-symbol-bg: var(--black);
  --deco-label-fg: var(--black);

  --sub-title-fg: var(--gray-700);
  --status-sub-fg: var(--gray-500);

  --link-fg: var(--white);
  --link-hover-bg: var(--white);
  --link-hover-fg: var(--black);

  --grid-line: rgba(0, 0, 0, 0.12);
  --scanline-line: rgba(0, 0, 0, 0.05);
  --noise-invert: 0;
  --shape-border: var(--black);
  --shape-b-fill: rgba(0, 0, 0, 0.06);
  --shape-c-fill: rgba(0, 0, 0, 0.08);
}

@font-face {
  font-family: "Archivo Black";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/ArchivoBlack-Regular.woff2") format("woff2");
}

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

html, body { height: 100%; }

body {
  font-family: "Archivo Black", "Arial Black", Arial, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.bar {
  background: var(--bar-bg);
  color: var(--bar-fg);
  padding: 10px 16px;
  font-size: 13px;
  letter-spacing: 2px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.bar-top { border-bottom: var(--border); }

.bar-bottom { border-top: var(--border); }

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
}

.theme-option {
  font: inherit;
  font-size: 12px;
  letter-spacing: 1px;
  color: inherit;
  background: transparent;
  border: none;
  padding: 2px 4px;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.theme-option:hover,
.theme-option:focus-visible {
  text-decoration: underline;
}

.theme-option[aria-pressed="true"] {
  background: var(--bar-fg);
  color: var(--bar-bg);
}

.theme-sep {
  opacity: 0.6;
  font-size: 12px;
  pointer-events: none;
}

.grid {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: 1.618fr 1fr;
  grid-template-rows: 1.618fr 1fr;
  border-left: var(--border);
  border-right: var(--border);
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
}

.cell-title {
  border-right: var(--border);
  grid-row: 1 / 3;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  text-align: right;
}

.cell-links {
  border-bottom: var(--border);
  background: var(--deco-bg);
  padding: 0;
  flex-direction: column;
  align-items: stretch;
  justify-content: stretch;
  min-width: 0;
  overflow: hidden;
}

.link-panel {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: 0;
  padding: 20px 24px;
  color: var(--deco-label-fg);
  text-decoration: none;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.link-panel + .link-panel {
  border-top: var(--border);
}

.link-panel:hover,
.link-panel:focus-visible {
  background: var(--deco-symbol-bg);
  color: var(--deco-bg);
}

.link-mark {
  display: flex;
  flex-shrink: 0;
}

.link-label {
  display: block;
  font-size: 13px;
  letter-spacing: 2px;
  text-align: right;
  min-width: 0;
  flex-shrink: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cell-status { display: flex; flex-direction: column; gap: 8px; }

.logo {
  font-size: clamp(48px, 9vw, 96px);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: -2px;
}

.logo-sub {
  font-size: 14px;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: var(--sub-title-fg);
  margin-top: 12px;
  text-align: right;
}

.status-title { font-size: 24px; font-weight: 900; }

.status-sub { font-size: 11px; letter-spacing: 3px; color: var(--status-sub-fg); }

.bg-grid,
.bg-noise,
.bg-scanline,
.bg-shapes {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.bg-grid {
  background-image:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: 48px 48px;
  animation: grid-drift 12s linear infinite;
}

@keyframes grid-drift {
  0% { background-position: 0 0; }
  100% { background-position: 48px 48px; }
}

.bg-scanline {
  background: repeating-linear-gradient(
    to bottom,
    var(--scanline-line) 0px,
    var(--scanline-line) 1px,
    transparent 1px,
    transparent 4px
  );
  animation: scan-move 8s linear infinite;
}

@keyframes scan-move {
  0% { transform: translateY(-100%); }
  100% { transform: translateY(100%); }
}

.bg-noise {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='0.4'/%3E%3C/svg%3E");
  opacity: 0.06;
  filter: invert(var(--noise-invert));
  animation: noise-jump 0.4s steps(2) infinite;
}

@keyframes noise-jump {
  0% { transform: translate(0, 0); }
  50% { transform: translate(-2px, 2px); }
  100% { transform: translate(2px, -2px); }
}

.bg-shapes .shape {
  position: absolute;
  border: 2px solid var(--shape-border);
}

.shape-a {
  width: 105vmin;
  height: 105vmin;
  top: 10%;
  left: -115vmin;
  animation: flow-a 14s linear infinite;
}

.shape-b {
  width: 112.5vmin;
  height: 112.5vmin;
  bottom: 6%;
  right: -123vmin;
  background: var(--shape-b-fill);
  animation: flow-b 16s linear infinite;
}

.bg-shapes .shape-c {
  width: 0;
  height: 0;
  border: none;
  border-left: 105vmin solid transparent;
  border-right: 105vmin solid transparent;
  border-bottom: 112.5vmin solid var(--shape-c-fill);
  top: 38%;
  left: -220vmin;
  animation: flow-c 18s linear infinite;
}

@keyframes flow-a {
  0% { transform: translate(0, 0) rotate(0deg); }
  100% { transform: translate(320vw, 0) rotate(10deg); }
}

@keyframes flow-b {
  0% { transform: translate(0, 0); }
  100% { transform: translate(-320vw, 0); }
}

@keyframes flow-c {
  0% { transform: translate(0, 0) rotate(0deg); }
  100% { transform: translate(380vw, -8vh) rotate(8deg); }
}

.bar,
.grid,
.link-panel {
  position: relative;
  z-index: 1;
}

@media (max-width: 640px) {
  .grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  .cell-title {
    border-right: none;
    border-bottom: var(--border);
    grid-row: auto;
    align-items: flex-end;
    text-align: right;
    min-height: 60vh;
  }

  .logo { font-size: 52px; }

  .logo-sub { font-size: 10px; }

  .bar { font-size: 11px; padding: 8px 10px; }

  .link-panel { padding: 14px 16px; gap: 12px; }

  .link-mark svg { width: 32px; height: 32px; }

  .link-label { font-size: 12px; letter-spacing: 1px; }
}

@media (prefers-reduced-motion: reduce) {
  .bg-grid,
  .bg-scanline,
  .bg-noise,
  .bg-shapes {
    animation: none;
  }

  .bg-grid { background: none; }
  .bg-scanline { background: none; }
  .bg-noise { background-image: none; }
  .bg-shapes .shape { display: none; }
}

:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #000;
  --fg: #fff;

  --bar-bg: var(--white);
  --bar-fg: var(--black);

  --border: 3px solid var(--white);

  /* gray ramp is inverted in dark mode: 300 = darkest, 700 = lightest.
     Use the role wrappers (--deco-bg, --sub-title-fg, --status-sub-fg) directly. */
  --gray-300: #1a1a1a;
  --gray-500: #999;
  --gray-700: #aaa;

  --deco-bg: var(--gray-300);
  --deco-symbol-bg: var(--white);
  --deco-label-fg: var(--white);

  --sub-title-fg: var(--gray-700);
  --status-sub-fg: var(--gray-500);

  --link-fg: var(--black);
  --link-hover-bg: var(--black);
  --link-hover-fg: var(--white);

  --grid-line: rgba(255, 255, 255, 0.12);
  --scanline-line: rgba(255, 255, 255, 0.05);
  --noise-invert: 1;
  --shape-border: var(--white);
  --shape-b-fill: rgba(255, 255, 255, 0.06);
  --shape-c-fill: rgba(255, 255, 255, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #000;
    --fg: #fff;

    --bar-bg: var(--white);
    --bar-fg: var(--black);

    --border: 3px solid var(--white);

    /* gray ramp is inverted in dark mode: 300 = darkest, 700 = lightest.
       Use the role wrappers (--deco-bg, --sub-title-fg, --status-sub-fg) directly. */
    --gray-300: #1a1a1a;
    --gray-500: #999;
    --gray-700: #aaa;

    --deco-bg: var(--gray-300);
    --deco-symbol-bg: var(--white);
    --deco-label-fg: var(--white);

    --sub-title-fg: var(--gray-700);
    --status-sub-fg: var(--gray-500);

    --link-fg: var(--black);
    --link-hover-bg: var(--black);
    --link-hover-fg: var(--white);

    --grid-line: rgba(255, 255, 255, 0.12);
    --scanline-line: rgba(255, 255, 255, 0.05);
    --noise-invert: 1;
    --shape-border: var(--white);
    --shape-b-fill: rgba(255, 255, 255, 0.06);
    --shape-c-fill: rgba(255, 255, 255, 0.08);
  }
}
