/* Web フォントは読み込まない（外部通信になるため）。OS のフォントだけを使う。 */

:root {
  color-scheme: light dark;

  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #d8dbe0;
  --text: #1b1d21;
  --muted: #61656d;
  --accent: #1c6fd0;
  --accent-text: #ffffff;
  --ok: #1a7f47;
  --warn: #a3600a;
  --err: #b3261e;
  --cell: #d8dbe0;
  --cell-on: #1a7f47;
  --radius: 10px;

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

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f25;
    --border: #333842;
    --text: #e6e8ec;
    --muted: #9aa0aa;
    --accent: #4d9bf0;
    --accent-text: #0d1117;
    --ok: #4cc38a;
    --warn: #e0a848;
    --err: #f2776b;
    --cell: #333842;
    --cell-on: #4cc38a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

/* ── ヘッダ ─────────────────────────────── */

.top {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.top-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 0;
}

h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}

.tagline {
  margin: 0.25rem 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.tabs {
  display: flex;
  gap: 0.25rem;
}

.tab {
  appearance: none;
  border: 1px solid var(--border);
  border-bottom: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 0.5rem 1.25rem;
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: pointer;
  position: relative;
  top: 1px;
}

.tab[aria-selected="true"] {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}

.tab:focus-visible,
button:focus-visible,
select:focus-visible,
textarea:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── レイアウト ─────────────────────────── */

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.panel.is-hidden { display: none; }

.col {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}

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

/* ── 部品 ───────────────────────────────── */

.field-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.text-area {
  width: 100%;
  min-height: 11rem;
  resize: vertical;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.5;
}

.stats {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 0.75rem;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.jump-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.jump-row input[type="number"] {
  width: 6rem;
  padding: 0.4rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.jump-row button {
  padding: 0.4rem 0.7rem;
}

.jump-total {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

select,
input[type="range"] {
  width: 100%;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
}

select {
  padding: 0.4rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

button {
  appearance: none;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

button:hover:not(:disabled) { border-color: var(--accent); }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

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

.note {
  margin: 0;
  font-size: 0.82rem;
  color: var(--warn);
}

.note.is-error { color: var(--err); }
.note.is-ok { color: var(--ok); }

code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05em 0.3em;
}

/* ── 送信側の QR ────────────────────────── */

.stage {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

/* 全画面では余計なものを消して QR だけを白地で最大化する。 */
.stage:fullscreen {
  background: #ffffff;
  border: none;
  border-radius: 0;
  justify-content: center;
  padding: 1.5rem;
}

.qr {
  width: 100%;
  max-width: 30rem;
  height: auto;
  aspect-ratio: 1 / 1;
  background: #ffffff;
  border-radius: 4px;
  /* 拡大時に升目がぼやけないようにする。読み取り成功率に効く。 */
  image-rendering: pixelated;
}

.stage:fullscreen .qr {
  max-width: min(92vw, 92vh);
}

.frame-label {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.stage:fullscreen .frame-label { color: #444444; }

/* ── 受信側 ─────────────────────────────── */

.video-wrap {
  position: relative;
  background: #000000;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.hint {
  position: absolute;
  inset: auto 0 0 0;
  margin: 0;
  padding: 0.5rem 0.75rem;
  background: rgba(0, 0, 0, 0.6);
  color: #f0f0f0;
  font-size: 0.8rem;
  text-align: center;
}

.progress {
  height: 0.6rem;
  background: var(--cell);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 100%;
  background: var(--ok);
  transform-origin: left center;
  transform: scaleX(var(--progress, 0));
  transition: transform 120ms linear;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(0.5rem, 1fr));
  gap: 2px;
}

.grid:empty { display: none; }

.grid .cell {
  aspect-ratio: 1 / 1;
  background: var(--cell);
  border-radius: 2px;
}

.grid .cell.is-on { background: var(--cell-on); }

/* ── 補足 ───────────────────────────────── */

.howto {
  margin-top: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.88rem;
}

.howto summary {
  cursor: pointer;
  font-weight: 600;
}

.howto ol { padding-left: 1.2rem; }

.foot {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.25rem 2rem;
  color: var(--muted);
  font-size: 0.8rem;
}
