:root {
  color-scheme: dark;

  --bg: #0b1524;
  --bg-elevated: #101d2f;
  --panel: #16263c;
  --panel-border: #223650;
  --text: #e7eef7;
  --text-muted: #9db0c8;
  --accent: #35e08a;
  --accent-strong: #16c874;
  --cyan: #45d6ee;
  --danger: #ff6b6b;
  --amber: #ffc857;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --tap: 44px;
  --shadow: 0 18px 40px rgba(3, 9, 18, 0.45);

  --font: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Yu Gothic",
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* display を持つ要素にも hidden を効かせる */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  padding: clamp(16px, 4vw, 32px) clamp(12px, 4vw, 32px) 48px;
  padding-left: max(clamp(12px, 4vw, 32px), env(safe-area-inset-left));
  padding-right: max(clamp(12px, 4vw, 32px), env(safe-area-inset-right));
  background:
    radial-gradient(1100px 620px at 12% -10%, #1b3350 0%, transparent 60%),
    radial-gradient(900px 520px at 100% 0%, #123b3a 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  overflow-x: hidden;
}

h1,
h2,
p,
dl,
dd,
ol {
  margin: 0;
}

ol {
  padding: 0;
  list-style: none;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: 10px 16px;
  background: var(--accent);
  color: #041b0f;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 20;
}

.skip-link:focus {
  left: 0;
}

:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 2px;
}

/* ---------- ヘッダー ---------- */

.site-header {
  max-width: 1180px;
  margin: 0 auto clamp(16px, 3vw, 28px);
}

.site-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: clamp(1.35rem, 4.6vw, 2.1rem);
  line-height: 1.25;
  letter-spacing: 0.01em;
}

.site-title__flag {
  color: var(--accent);
}

.site-lead {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.site-privacy {
  margin-top: 4px;
  color: #7d90a8;
  font-size: 0.82rem;
}

/* ---------- レイアウト ---------- */

.layout {
  max-width: 1180px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: clamp(14px, 2.2vw, 24px);
  align-items: start;
}

.side {
  display: grid;
  gap: clamp(14px, 2.2vw, 20px);
  min-width: 0;
}

@media (max-width: 800px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---------- カメラ ---------- */

.stage {
  min-width: 0;
  display: grid;
  gap: 12px;
}

.stage__frame {
  position: relative;
  touch-action: manipulation; /* スマホのダブルタップ拡大を防ぐ */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  aspect-ratio: 16 / 9;
  width: 100%;
  overflow: hidden;
  border-radius: var(--radius-lg);
  border: 1px solid var(--panel-border);
  background: #060d18;
  box-shadow: var(--shadow);
}

.stage__video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: scaleX(-1); /* 鏡像にして構えやすくする */
  background: #060d18;
}

.stage__mask {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* 映像と同じく鏡像にする */
  image-rendering: pixelated;
  background: #060d18;
}

.stage__mask--hidden {
  display: none;
}

.stage__guide {
  position: absolute;
  inset: 8% 22%;
  border: 2px dashed rgba(69, 214, 238, 0.55);
  border-radius: var(--radius-md);
  pointer-events: none;
}

/* 顔を枠に合わせたときの目もとの高さに置く */
.stage__shades {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 26%;
  width: 84%;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.55));
}

.stage__shades--hidden {
  display: none;
}

.stage__placeholder {
  position: absolute;
  inset: 0 0 38% 0; /* 下部の信号表示と重ならないようにする */
  display: grid;
  place-content: center;
  text-align: center;
  padding: 16px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.stage__placeholder--hidden {
  display: none;
}

.stage__video--blur {
  filter: blur(18px);
}

.stage__video--silhouette {
  filter: grayscale(1) brightness(0.42) contrast(4.5);
}

.stage__video--hidden {
  visibility: hidden;
}

/* ---------- 信号 ---------- */

.signal {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 14px clamp(12px, 3vw, 22px) clamp(14px, 3vw, 20px);
  display: grid;
  gap: 2px;
  background: linear-gradient(to top, rgba(6, 13, 24, 0.94), rgba(6, 13, 24, 0));
  transition: background-color 140ms ease;
}

.signal__title {
  font-size: clamp(1.3rem, 5.2vw, 2.2rem);
  font-weight: 700;
  line-height: 1.15;
}

.signal__detail {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.signal--countdown .signal__title {
  color: var(--amber);
}

.signal--go {
  background: linear-gradient(to top, rgba(21, 160, 96, 0.96), rgba(21, 160, 96, 0.25));
  animation: signal-pop 220ms ease-out;
}

.signal--go .signal__title {
  color: #eafff3;
  font-size: clamp(2rem, 9vw, 3.4rem);
  letter-spacing: 0.08em;
}

.signal--go .signal__detail {
  color: #d3ffe8;
}

.signal--false-start {
  background: linear-gradient(to top, rgba(170, 40, 46, 0.95), rgba(170, 40, 46, 0.2));
}

.signal--false-start .signal__title {
  color: #ffe2e2;
}

.signal--false-start .signal__detail {
  color: #ffd0d0;
}

.signal--finished .signal__title {
  color: var(--cyan);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

@keyframes signal-pop {
  from {
    transform: scale(0.97);
    opacity: 0.4;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* ---------- 動きメーター ---------- */

.meter {
  display: grid;
  gap: 6px;
}

.meter__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.meter__value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.meter__track {
  position: relative;
  height: 12px;
  border-radius: 999px;
  background: #16263c;
  border: 1px solid var(--panel-border);
  overflow: hidden;
}

.meter__bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--cyan), var(--accent));
  transition: width 90ms linear;
}

.meter__bar--over {
  background: linear-gradient(90deg, var(--amber), var(--danger));
}

.meter__threshold {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  left: 0%;
  background: rgba(231, 238, 247, 0.7);
}

/* ---------- パネル ---------- */

.panel {
  min-width: 0;
  padding: clamp(14px, 2.6vw, 20px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--panel-border);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  align-content: start;
}

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.panel__title {
  font-size: 1rem;
  letter-spacing: 0.04em;
  color: var(--text);
}

/* ---------- フォーム ---------- */

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field__label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.field__control {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
}

.field__control:disabled {
  opacity: 0.55;
}

.field__range {
  width: 100%;
  min-height: var(--tap);
  accent-color: var(--accent);
  background: transparent;
}

.field__help {
  color: #7d90a8;
  font-size: 0.78rem;
}

/* ---------- ボタン ---------- */

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.button-row--end {
  justify-content: flex-end;
}

.button {
  min-height: var(--tap);
  min-width: 96px;
  flex: 1 1 auto;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 120ms ease, filter 120ms ease, background-color 120ms ease;
}

.button:hover:not(:disabled) {
  filter: brightness(1.12);
}

.button:active:not(:disabled) {
  transform: translateY(1px);
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.button--primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  border-color: transparent;
  color: #052416;
}

.button--accent {
  background: rgba(69, 214, 238, 0.14);
  border-color: rgba(69, 214, 238, 0.5);
  color: #cdf3fb;
}

.button--secondary {
  background: rgba(69, 214, 238, 0.16);
  border-color: rgba(69, 214, 238, 0.42);
}

.button--ghost {
  background: transparent;
}

.button--wide {
  width: 100%;
  flex: none;
}

.button--small {
  min-width: 0;
  min-height: 36px;
  flex: none;
  padding: 6px 14px;
  font-size: 0.82rem;
  font-weight: 500;
}

/* ---------- トグル ---------- */

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  cursor: pointer;
  touch-action: manipulation;
}

.toggle__input {
  width: 20px;
  height: 20px;
  flex: none;
  accent-color: var(--accent);
  cursor: pointer;
}

.toggle__label {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ---------- 結果 ---------- */

.result {
  display: grid;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--panel-border);
}

.result__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-top: 8px;
}

.result__key {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.result__value {
  margin: 0;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--cyan);
}

.result__value--muted {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* ---------- ランキング ---------- */

.ranking {
  display: grid;
  gap: 6px;
}

.ranking__item {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  background: var(--panel);
  border: 1px solid var(--panel-border);
}

.ranking__item--top {
  border-color: rgba(53, 224, 138, 0.45);
}

.ranking__rank {
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-size: 0.9rem;
}

.ranking__item--top .ranking__rank {
  color: var(--accent);
  font-weight: 700;
}

.ranking__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking__time {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--cyan);
}

.ranking__empty {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.ranking__empty--hidden {
  display: none;
}

/* ---------- 通知 ---------- */

.notice {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 107, 107, 0.45);
  background: rgba(255, 107, 107, 0.12);
  color: #ffd9d9;
  font-size: 0.86rem;
}

.notice--info {
  border-color: rgba(69, 214, 238, 0.4);
  background: rgba(69, 214, 238, 0.1);
  color: #d2f3fb;
}

.notice--hidden {
  display: none;
}

/* ---------- ダイアログ ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(4, 9, 17, 0.72);
  backdrop-filter: blur(3px);
}

.overlay--hidden {
  display: none;
}

.modal {
  width: min(420px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: clamp(18px, 4vw, 26px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--panel-border);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
}

.modal__title {
  font-size: 1.1rem;
}

.modal__result {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.9rem, 8vw, 2.6rem);
  font-weight: 700;
  color: var(--accent);
}

.modal__description {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.modal__form {
  display: grid;
  gap: 12px;
}

.modal__error {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 107, 107, 0.14);
  border: 1px solid rgba(255, 107, 107, 0.45);
  color: #ffd9d9;
  font-size: 0.84rem;
}

.modal__error--hidden {
  display: none;
}

/* ---------- フッター ---------- */

.site-footer {
  max-width: 1180px;
  margin: clamp(20px, 4vw, 32px) auto 0;
  color: #6f8299;
  font-size: 0.78rem;
}

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