:root {
  color-scheme: dark;
  --bg: #0a0b0c;
  --panel: #131517;
  --panel-2: #1a1d20;
  --line: #2a2e33;
  --text: #c8cbc6;
  --muted: #7d827d;
  --accent: #c9a54a;
  --rec: #d23a3a;
  --ok: #8fb38a;
  --near: #c9a54a;
  --off: #c86a5a;
  --osd: "Courier New", "Osaka-Mono", "MS Gothic", monospace;
  --sans: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  --serif: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.7;
}

#app {
  min-height: 100vh;
  transition: filter 2s ease;
}

#screen {
  max-width: 1000px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  animation: fadein 0.8s ease;
}
#screen.center {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

h1, h2 { font-weight: normal; letter-spacing: 0.12em; }

.btn {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 10px 28px;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.btn:hover { background: #22262a; border-color: #444a50; }
.btn:focus-visible { outline: 1px solid var(--accent); outline-offset: 3px; }
.btn[hidden] { display: none; }
.btn:disabled { opacity: 0.5; cursor: default; }

.actions { margin-top: 28px; text-align: center; }

.fatal { padding: 40px; color: var(--off); }

/* ---------- タイトル ---------- */
.title { text-align: center; }
.title h1 {
  font-family: var(--serif);
  font-size: clamp(40px, 8vw, 72px);
  margin: 0 0 24px;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
}
.title-sub { color: var(--muted); letter-spacing: 0.3em; margin: 0 0 8px; }
.title-note { color: var(--muted); font-size: 13px; margin: 0 0 40px; }
.title h1 + .btn { margin-top: 24px; }
.debug { margin-top: 24px; color: var(--accent); font-size: 12px; font-family: var(--osd); }

/* ---------- 日付カード ---------- */
.intro { text-align: center; max-width: 560px; }
.intro-day { font-family: var(--serif); font-size: 44px; margin: 0; letter-spacing: 0.2em; }
.intro-date { color: var(--muted); margin: 4px 0 32px; letter-spacing: 0.15em; }
.intro-text { text-align: left; margin: 0 auto 36px; color: var(--text); }

/* ---------- 調査画面 ---------- */
/* 映像と数取器が1画面に収まるよう、高さから幅を決める */
.survey { width: min(100%, max(320px, calc((100dvh - 390px) * 16 / 9))); margin: 0 auto; }
.survey-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
  font-variant-numeric: tabular-nums;
}

.monitor {
  position: relative;
  aspect-ratio: 16 / 9;
  max-width: 100%;
  background: #000;
  border: 1px solid var(--line);
  overflow: hidden;
  user-select: none;
}
.feed, .feed video, .placeholder {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.feed { transition: opacity 1.2s ease; }
.feed video { object-fit: cover; background: #000; pointer-events: none; }
.monitor.ended .feed { opacity: 0; }

.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--osd);
  color: #8a8f8a;
  text-align: center;
  padding: 16px;
}
.placeholder[hidden] { display: none; }
.ph-title { font-size: clamp(18px, 3vw, 28px); letter-spacing: 0.15em; color: #b8bcb6; }
.ph-sub { font-size: 12px; }
.ph-note { font-size: 11px; color: #555a55; }

.standby {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(0,0,0,0.88);
  z-index: 3;
}
.standby-label { margin: 0; letter-spacing: 0.15em; }
.standby-note { margin: 0; font-size: 12px; color: var(--muted); }

.progress { height: 2px; background: var(--line); margin-top: 6px; }
.progress-bar { height: 100%; width: 0; background: #6b706b; }

/* 4日目：映像の揺らぎ */
.monitor.haunted .feed { filter: url(#haunt) contrast(1.05) brightness(0.94); }
.monitor.haunted.glitch .feed { transform: translateX(-2px) skewX(-0.6deg); }

/* ---------- 数取器 ---------- */
.counters {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px clamp(12px, 3vw, 28px);
  margin-top: 18px;
}
.counter {
  --metal-hi: #f4f6f7;
  --metal: #b9bfc3;
  --metal-lo: #6c7377;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  font: inherit;
  font-size: clamp(9.5px, 2.5vw, 14px);
  color: inherit;
  background: none;
  border: 0;
  padding: 0 0 4px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.counter:disabled { cursor: default; opacity: 0.55; }
.counter:focus-visible { outline: 1px solid var(--accent); outline-offset: 4px; }

.tally-plunger {
  position: relative;
  z-index: 0;
  width: 2.2em;
  height: 1.5em;
  margin-bottom: -0.35em;
  border-radius: 0.45em 0.45em 0.15em 0.15em;
  background: linear-gradient(90deg, var(--metal-lo), var(--metal-hi) 38%, var(--metal) 65%, var(--metal-lo));
  box-shadow: inset 0 2px 1px rgba(255,255,255,0.7), 0 2px 3px rgba(0,0,0,0.5);
  transition: transform 0.05s ease-out;
}
.counter:not(:disabled):active .tally-plunger,
.counter.hit .tally-plunger { animation: plunge 0.13s ease-out; }
@keyframes plunge { 0%, 40% { transform: translateY(0.45em); } 100% { transform: none; } }

.tally-body {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 9.2em;
  height: 7em;
  padding-bottom: 1.4em;
  border-radius: 3em 3em 2.6em 2.6em;
  background:
    radial-gradient(ellipse 80% 60% at 32% 22%, rgba(255,255,255,0.95), rgba(255,255,255,0) 60%),
    linear-gradient(160deg, var(--metal-hi), var(--metal) 40%, var(--metal-lo) 75%, var(--metal) 100%);
  box-shadow:
    inset 0 2px 2px rgba(255,255,255,0.8),
    inset 0 -5px 10px rgba(0,0,0,0.35),
    0 10px 22px rgba(0,0,0,0.65);
}
.tally-window {
  display: flex;
  gap: 0.12em;
  padding: 0.18em 0.25em;
  font-size: 1.6em;
  background: #0b0b0b;
  border-radius: 0.12em;
  box-shadow: inset 0 3px 6px #000, 0 1px 0 rgba(255,255,255,0.7), 0 -1px 0 rgba(0,0,0,0.4);
}
.wheel {
  position: relative;
  width: 0.68em;
  height: 1em;
  overflow: hidden;
  background: linear-gradient(#141414, #2c2c2c 50%, #141414);
  border-radius: 0.06em;
}
.wheel::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(rgba(0,0,0,0.75), rgba(0,0,0,0) 32%, rgba(0,0,0,0) 68%, rgba(0,0,0,0.75));
  pointer-events: none;
}
.strip {
  display: flex;
  flex-direction: column;
  transition: transform 0.13s cubic-bezier(0.3, 1.35, 0.6, 1);
}
.strip span {
  height: 1em;
  line-height: 1em;
  text-align: center;
  font-family: var(--osd);
  font-weight: bold;
  color: #f1eee4;
  font-variant-numeric: tabular-nums;
}
.tally-screw {
  position: absolute;
  right: -0.45em;
  top: 2.4em;
  width: 0.7em;
  height: 1.3em;
  border-radius: 0.2em;
  background: repeating-linear-gradient(var(--metal-hi) 0 2px, var(--metal-lo) 2px 4px);
  box-shadow: 0 1px 2px rgba(0,0,0,0.5);
  z-index: -1;
}
.tally-ring {
  width: 2.8em;
  height: 2.1em;
  margin-top: -0.9em;
  border: 0.42em solid var(--metal);
  border-top-color: var(--metal-lo);
  border-radius: 50%;
  box-shadow: 0 3px 5px rgba(0,0,0,0.5), inset 0 1px 1px rgba(255,255,255,0.5);
}
.tally-tag {
  position: absolute;
  z-index: 2;
  top: 6.25em;
  padding: 0.05em 0.8em;
  font-family: "Yomogi", var(--sans);
  font-size: 1.05em;
  color: #2b2a26;
  background: rgba(232, 220, 181, 0.94);
  transform: rotate(-3deg);
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
  white-space: nowrap;
}
.counter kbd {
  position: absolute;
  top: 0.2em;
  left: 0;
  font-family: var(--osd);
  font-size: 0.75em;
  color: var(--muted);
}

.hint { text-align: center; color: var(--muted); font-size: 12px; margin-top: 14px; }

/* ---------- 集計表 ---------- */
.sheet {
  width: min(360px, 100%);
  margin: 0 auto;
  background: #d9d6cc;
  color: #1d1d1b;
  padding: 28px 28px 24px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}
.sheet-title { margin: 0 0 14px; font-size: 20px; text-align: center; letter-spacing: 0.5em; text-indent: 0.5em; border-bottom: 2px solid #1d1d1b; padding-bottom: 6px; }
.sheet-table { width: 100%; border-collapse: collapse; }
.sheet-table th, .sheet-table td { border: 1px solid #1d1d1b; padding: 6px 12px; }
.sheet-table tbody th { font-weight: normal; text-align: left; width: 50%; }
.sheet-table td { text-align: right; font-family: var(--osd); font-size: 20px; }
.sheet .btn { background: #1d1d1b; color: #e4e1d8; border-color: #1d1d1b; }
.sheet .btn:hover { background: #333; }

/* ---------- 調査結果 ---------- */
.result { width: 100%; max-width: 640px; text-align: center; }
.result h2 { margin: 0 0 4px; }
.result-date { color: var(--muted); font-size: 13px; margin: 0 0 24px; }
.result-table { width: 100%; border-collapse: collapse; }
.result-table th, .result-table td { border-bottom: 1px solid var(--line); padding: 10px 8px; }
.result-table thead th { color: var(--muted); font-weight: normal; font-size: 13px; }
.result-table tbody th { font-weight: normal; text-align: left; }
.v-ok { color: var(--ok); }
.v-near { color: var(--near); }
.v-off { color: var(--off); }
.result-comment { margin-top: 24px; color: var(--muted); }

/* ---------- スマホ ---------- */
.phone-wrap { display: flex; flex-direction: column; align-items: center; width: 100%; }
.phone-day { color: var(--muted); letter-spacing: 0.15em; margin: 0 0 16px; }
.phone {
  position: relative;
  width: min(340px, 100%);
  height: 560px;
  background: #0e1012;
  border: 10px solid #1c1f22;
  border-radius: 36px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.phone-status { display: flex; justify-content: space-between; padding: 8px 20px 4px; font-size: 12px; color: #aaa; }
.phone-icons { letter-spacing: 0.1em; }
.phone-head { padding: 8px 16px 10px; border-bottom: 1px solid #23272b; font-size: 13px; text-align: center; color: #ddd; }
.phone-thread { flex: 1; padding: 16px 14px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.bubble { align-self: flex-start; max-width: 85%; animation: fadein 0.4s ease; }
.bubble p { margin: 0; background: #24282c; padding: 8px 12px; border-radius: 14px 14px 14px 4px; font-size: 14px; }
.bubble time { font-size: 10px; color: var(--muted); margin-left: 6px; }
.bubble.gone { opacity: 0; transition: opacity 0.2s; }
.retracted { margin: 0; text-align: center; font-size: 11px; color: #5c615c; animation: fadein 1s ease; }

/* ---------- メール ---------- */
.mail-wrap { width: 100%; max-width: 640px; }
.mailer { background: var(--panel); border: 1px solid var(--line); min-height: 360px; }
.mailer-bar {
  display: flex;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}
.mailer-count { color: var(--accent); }
.mail-list[hidden] { display: none; }
.mail-item {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "from time" "subj subj";
  gap: 0 12px;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
}
.mail-from { grid-area: from; font-size: 14px; }
.mail-subj { grid-area: subj; font-size: 13px; color: var(--muted); }
.mail-time { grid-area: time; font-size: 12px; color: var(--muted); }
.mail-item.read { opacity: 0.55; }
.mail-item.unread { cursor: pointer; background: #181b1e; }
.mail-item.unread .mail-from { font-weight: bold; }
.mail-item.unread .mail-from::before { content: "● "; color: var(--accent); font-size: 10px; vertical-align: 2px; }
.mail-item.unread:hover { background: #1f2326; }
.mail-item.arrive { animation: fadein 0.6s ease; }
.mail-body { padding: 16px 20px 28px; animation: fadein 0.6s ease; }
.mail-body[hidden] { display: none; }
.mail-body dl { margin: 0 0 20px; font-size: 13px; border-bottom: 1px solid var(--line); padding-bottom: 12px; }
.mail-body dl div { display: flex; gap: 12px; }
.mail-body dt { color: var(--muted); min-width: 4em; }
.mail-body dd { margin: 0; }
.mail-text { font-family: var(--serif); font-size: 16px; line-height: 2; white-space: normal; }

/* ---------- Webニュース ---------- */
#screen.night-screen { animation: none; }
.news-interlude { text-align: center; }
.news-interlude-text {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(20px, 3vw, 28px);
  letter-spacing: 0.16em;
  opacity: 0;
  animation: night-caption var(--night-duration) ease-in-out forwards;
}
@keyframes night-caption {
  0%, 8% { opacity: 0; }
  28%, 72% { opacity: 1; }
  94%, 100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .news-interlude-text { animation: none; opacity: 1; }
}
#screen.news-screen { max-width: 860px; padding-top: 32px; }
.news-wrap { width: 100%; margin: 0 auto; }
.news-context {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 14px;
}
.news-site {
  color-scheme: light;
  background: #fff;
  color: #202124;
  border: 1px solid #d8dce2;
  box-shadow: 0 16px 48px rgba(0,0,0,0.24);
  font-family: var(--sans);
}
.news-masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 20px;
  padding: 20px 30px 18px;
  border-bottom: 1px solid #e5e8ec;
}
.news-logo { color: #145ca8; font-size: clamp(24px, 4.5vw, 32px); font-weight: 800; letter-spacing: -0.04em; }
.news-edition { color: #737881; font-size: 14px; }
.news-category {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 30px;
  background: #f5f7fa;
  border-bottom: 1px solid #e2e6ec;
  font-size: 14px;
}
.news-category > span:first-child { padding: 11px 3px 8px; border-bottom: 3px solid #145ca8; color: #145ca8; font-weight: 700; }
.news-topic { color: #5d6470; }
.news-list { padding: 24px 30px 32px; }
.news-list-title { margin: 0; font-size: clamp(20px, 3vw, 26px); line-height: 1.65; }
.news-headline-link {
  display: flex;
  align-items: center;
  gap: 24px;
  width: 100%;
  padding: 12px 0;
  border: 0;
  border-bottom: 1px solid #e2e6ec;
  background: none;
  color: #145ca8;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.news-headline-link > span { margin-left: auto; font-size: 30px; }
.news-headline-link:hover { text-decoration: underline; }
.news-headline-link:focus-visible { outline: 2px solid #145ca8; outline-offset: 5px; }
.news-article { padding: 24px 36px 28px; }
.news-breadcrumb { display: flex; gap: 12px; color: #6b7480; font-size: 13px; margin-bottom: 18px; }
.news-article h1 {
  margin: 0 0 16px;
  font-family: var(--sans);
  font-size: clamp(24px, 3.5vw, 34px);
  font-weight: 700;
  line-height: 1.5;
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
}
.news-date { margin: 0 0 8px; color: #6b7480; font-size: 14px; }
.news-source { margin: 0 0 25px; color: #145ca8; font-size: 14px; font-weight: 600; }
.news-body { padding-top: 24px; border-top: 1px solid #e7e9ed; font-size: 17px; line-height: 1.95; overflow-wrap: anywhere; }
.news-body p { margin: 0 0 24px; }
.news-body p:last-child { margin-bottom: 0; }
.news-lead { font-weight: 500; }
.news-footer { margin-top: 28px; padding-top: 16px; border-top: 1px solid #e7e9ed; color: #717780; font-size: 13px; }
.ph-sub, .ph-note { font-size: 14px; }

/* ---------- 終幕 ---------- */
.finale { width: 100%; max-width: 640px; text-align: center; }
.end-mark { text-align: center; margin: 0; color: var(--muted); letter-spacing: 0.3em; font-family: var(--serif); }
.thanks-title { margin: 32px 0 20px; font-size: clamp(20px, 4vw, 26px); font-weight: normal; }
.thanks-text { margin: 0; line-height: 2; overflow-wrap: anywhere; }
.creator { margin: 24px 0 0; }
.creator a { color: var(--accent); text-underline-offset: 4px; }
.creator a:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.finale-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; margin-top: 36px; }
.finale-actions a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

@media (max-width: 560px) {
  .sheet { padding: 20px 16px; }
  .phone { height: 500px; }
  #screen.news-screen { padding: 18px 12px 36px; }
  .news-masthead { padding: 16px 18px; }
  .news-category { padding: 0 18px; }
  .news-list { padding: 20px 18px 28px; }
  .news-article { padding: 20px 18px 24px; }
  .news-body { font-size: 16px; }
}
