:root {
  --bg: #6f819d;            /* 原片背景取樣色，與 /gaze/ 相同 */
  --bg-deep: #56657c;
  --ivory: #f6f1e7;
  --muted: #d9d3c7;
  --muted-2: rgba(233, 227, 214, 0.62);
  --cream: #eadcc2;
  --line: rgba(246, 241, 231, 0.22);
  --gutter: clamp(20px, 5.5vw, 96px);        /* 與 /gaze/ 相同，切換時頁首不跳動 */
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --sans: "Noto Sans JP", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  color-scheme: dark;
}

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

html { -webkit-text-size-adjust: 100%; }
body {
  min-height: 100vh;
  min-height: 100svh;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%) fixed;
  color: var(--ivory);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
body.is-loading { overflow: hidden; }

.mono { font-family: var(--mono); letter-spacing: 0.08em; }
a { color: inherit; text-decoration: none; }

/* ---------- Loader ---------- */
.loader {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  background: var(--bg);
  transition: opacity 0.8s var(--ease), visibility 0.8s;
}
.loader__inner { display: grid; gap: 14px; width: min(220px, 60vw); }
.loader__pct { font-size: 11px; }
.loader__bar { position: relative; height: 1px; background: rgba(246, 241, 231, 0.2); overflow: hidden; }
.loader__fill {
  position: absolute; inset: 0; background: var(--ivory);
  transform-origin: left center; transform: scaleX(0);
  transition: transform 0.25s linear;
}
body.is-ready .loader { opacity: 0; visibility: hidden; }

/* ---------- Header / Footer ---------- */
.header, .footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 var(--gutter);
  font-size: 11px;
}
.header { height: 88px; border-bottom: 1px solid var(--line); margin: 0 var(--gutter); padding: 0; }
@media (max-width: 1100px) { .header { height: 80px; } }
@media (max-width: 720px), (max-aspect-ratio: 5/4) { :root { --gutter: 20px; } .header { height: 64px; } }
.brand { font-weight: 500; letter-spacing: 0.14em; }
.brand sup { font-size: 0.7em; }
.status { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--cream); animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

.footer {
  margin: 0 var(--gutter); padding: 18px 0 calc(18px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  font-size: 10px; color: var(--muted-2);
}

/* ---------- ONE / SIXTEEN 切換 ---------- */
.header__left { display: flex; align-items: center; gap: 18px; }
.views { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; font-size: 10px; letter-spacing: 0.12em; }
.views a { padding: 6px 12px; color: var(--muted); touch-action: manipulation; transition: background-color 0.3s var(--ease), color 0.3s var(--ease); }
.views a[aria-current="page"] { background: var(--ivory); color: #1d2533; }
.views a:not([aria-current]):hover { background: rgba(246, 241, 231, 0.12); color: var(--ivory); }

/* ---------- Layout ---------- */
.lab {
  flex: 1;
  display: grid;
  gap: 20px;
  padding: 22px var(--gutter) 28px;
  align-content: start;
}

.label { font-size: 12px; letter-spacing: 0.18em; color: var(--cream); margin-bottom: 10px; }
.title {
  font-weight: 900;
  font-size: clamp(30px, 8.6vw, 76px);
  line-height: 1.08;
  letter-spacing: -0.02em;
}
.title span { display: block; white-space: nowrap; }
.title .solid { color: var(--ivory); }
.title .outline { color: transparent; -webkit-text-stroke: 1px rgba(246, 241, 231, 0.92); }

/* ---------- Mode buttons ---------- */
.modes {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-top: 20px;
  border: 1px solid var(--line);
}
.modes button {
  appearance: none;
  border: 0;
  border-left: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  padding: 13px 0;
  min-height: 44px;           /* iPhone 觸控最小尺寸 */
  cursor: pointer;
  touch-action: manipulation; /* 取消雙擊縮放造成的點擊延遲 */
  transition: background-color 0.3s var(--ease), color 0.3s var(--ease);
}
.modes button:first-child { border-left: 0; }
.modes button[aria-selected="true"] { background: var(--ivory); color: #1d2533; }
.modes button:focus-visible { outline: 1px solid var(--ivory); outline-offset: 2px; }
@media (hover: hover) {
  .modes button:not([aria-selected="true"]):hover { background: rgba(246, 241, 231, 0.08); color: var(--ivory); }
}

.mode-note {
  margin-top: 12px;
  min-height: 3.4em;
  font-size: 13px;
  line-height: 1.7;
  color: var(--muted);
}
.mode-note b { font-family: var(--mono); font-weight: 500; font-size: 11px; letter-spacing: 0.1em; color: var(--cream); margin-right: 8px; }

/* ---------- Camera（選擇性開啟，樣式同 /gaze/） ---------- */
.cam { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: 16px; }
.cam__btn {
  display: inline-flex; align-items: center; gap: 10px; min-height: 40px;
  padding: 8px 16px 8px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: rgba(24, 32, 48, 0.18); color: var(--ivory); font-size: 11px;
  cursor: pointer; touch-action: manipulation;
  transition: background-color 0.35s var(--ease), border-color 0.35s var(--ease);
}
.cam__btn:hover, .cam__btn:focus-visible { background: rgba(246, 241, 231, 0.12); border-color: rgba(246, 241, 231, 0.45); }
.cam__icon { color: var(--cream); font-size: 13px; line-height: 1; }
.cam__preview { display: none; width: 24px; height: 24px; border-radius: 50%; overflow: hidden; background: #1d2533; }
.cam__preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
.cam.is-on .cam__preview { display: block; box-shadow: 0 0 0 1px var(--cream); }
.cam.is-on .cam__icon { display: none; }
.cam.is-on.is-lost .cam__preview { box-shadow: 0 0 0 1px rgba(246, 241, 231, 0.3); opacity: 0.6; }
.cam.is-loading .cam__icon, .cam.is-loading .cam__preview { animation: pulse 1.2s ease-in-out infinite; }
.cam__note { font-size: 10px; line-height: 1.6; color: var(--muted-2); max-width: 300px; }

/* ---------- Grid ---------- */
.stage { display: grid; gap: 10px; justify-items: center; }
.grid {
  position: relative;
  width: 100%;
  max-width: 560px;
  touch-action: none;         /* 只有貓的格子裡手指拖曳＝移動視線；其他地方照常捲動 */
  -webkit-touch-callout: none;
}
#cats { display: block; width: 100%; height: auto; }
.grid__labels {
  position: absolute; inset: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap, 2px);
  pointer-events: none;
}
.grid__labels li {
  font-size: 8px;
  color: rgba(246, 241, 231, 0.55);
  padding: 5px 6px;
}
.hint { font-size: 10px; color: var(--muted-2); }
.hint--touch { display: none; }
@media (hover: none) { .hint--mouse { display: none; } .hint--touch { display: inline; } }

/* ---------- Desktop ---------- */
@media (min-width: 960px) {
  .lab {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: clamp(32px, 5vw, 96px);
    padding-top: 32px;
  }
  .intro { max-width: 460px; }
  .title { font-size: clamp(44px, 4.6vw, 76px); }
  .grid { width: min(560px, calc((100svh - 190px) * 0.86)); }
  .grid__labels li { font-size: 9px; }
}

@media (prefers-reduced-motion: reduce) { .dot { animation: none; } }
