:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --text: #172033;
  --muted: #667085;
  --line: #d7dce5;
  --line-strong: #aeb7c8;
  --primary: #2457d6;
  --primary-dark: #173f9d;
  --secondary: #0f766e;
  --danger: #b42318;
  --danger-bg: #fff1f0;
  --ok: #067647;
  --ok-bg: #ecfdf3;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --shadow: 0 10px 24px rgba(16, 24, 40, 0.08);
  --radius: 8px;
  --focus: 0 0 0 4px rgba(36, 87, 214, 0.18);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  height: 100%;
  min-height: 100%;
}

html { background: var(--bg); }

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
  overflow: hidden;
}

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

button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.56; }

:focus-visible { outline: none; box-shadow: var(--focus); }
[hidden] { display: none !important; }

a { color: inherit; }

.app-header {
  height: 76px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 12px clamp(14px, 3vw, 28px);
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.app-header__title { min-width: 0; }

.eyebrow,
.step-label {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.app-header h1,
.panel h2,
.saved-section h3 {
  margin: 0;
  line-height: 1.18;
  letter-spacing: 0;
}

.app-header h1 {
  font-size: clamp(1.15rem, 2.2vw, 1.7rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.key-pill,
.counter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.key-pill.is-set {
  color: var(--ok);
  background: var(--ok-bg);
  border-color: #abefc6;
}

.shell {
  height: calc(100dvh - 76px);
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 10px clamp(10px, 2vw, 18px) 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}

.notice {
  min-height: 34px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--muted);
  font-size: 0.86rem;
}

.status {
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
}

.status--working {
  color: var(--primary-dark);
  background: #eef4ff;
  border-color: #b2ccff;
}

.status--ok {
  color: var(--ok);
  background: var(--ok-bg);
  border-color: #abefc6;
}

.status--warn {
  color: var(--warn);
  background: var(--warn-bg);
  border-color: #fedf89;
}

.status--error {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: #fecdca;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(260px, 310px) minmax(250px, 320px) minmax(460px, 1fr);
  gap: 10px;
  overflow: hidden;
}

.panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel__head,
.saved-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.panel h2 { font-size: 1.05rem; }
.saved-section h3 { font-size: 0.95rem; }

.camera-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.camera-stage {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  max-width: 560px;
  max-height: min(60dvh, 480px);
  aspect-ratio: 4 / 3;
  margin: 0 auto;
  border-radius: var(--radius);
  overflow: hidden;
  background: #111827;
}

.camera-stage video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #111827;
}

.camera-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.camera-guide {
  min-height: 1.6em;
  margin: 8px auto 0;
  text-align: center;
  font-size: 0.95rem;
  color: #334155;
}

.camera-guide--ok {
  color: #15803d;
  font-weight: 700;
}

.camera-options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  justify-content: center;
  align-items: center;
  margin-top: 8px;
  font-size: 0.88rem;
  color: #334155;
}

.camera-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* 先生スマホ → サーバ → 生徒 PC の番号パネル */
.number-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.number-btn {
  min-width: 84px;
  padding: 10px 14px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.2;
}

.number-btn b { font-size: 1.6rem; }
.number-btn small { font-size: 0.75rem; opacity: 0.8; }

.upload-list { display: grid; gap: 6px; font-size: 0.95rem; }
.upload-row { display: flex; gap: 10px; align-items: baseline; }
.upload-pages { letter-spacing: 0.15em; font-size: 1.1rem; }

body.mode-teacher .panel--player { display: none; }

.camera-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 6px;
  padding: 18px;
  color: #f8fafc;
  text-align: center;
  background: linear-gradient(135deg, #111827, #2f3b52);
}

.camera-empty strong { font-size: 1.05rem; }
.camera-empty span { color: #d6deea; font-size: 0.88rem; }

.camera-actions,
.player-toolbar,
.modal__actions,
.thumb-card__actions,
.saved-card__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.camera-actions { justify-content: center; }

.file-drop {
  display: block;
  margin-top: 10px;
  padding: 10px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel-soft);
  color: var(--muted);
}

.file-drop span {
  display: block;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 800;
}

.file-drop strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 0.95rem;
}

.file-drop small {
  display: block;
  margin-top: 2px;
  font-size: 0.78rem;
}

input[type="file"] { display: none; }

.thumb-list,
.saved-list {
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
}

.thumb-list {
  flex: 1;
  display: grid;
  align-content: start;
  gap: 8px;
  padding-right: 2px;
}

.thumb-list:empty::before {
  content: "写真はまだありません";
  display: grid;
  place-items: center;
  min-height: 140px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--panel-soft);
}

.thumb-card {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 9px;
  align-items: stretch;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.thumb-card.is-replace-target {
  border-color: var(--primary);
  background: #eef4ff;
}

.thumb-card img {
  width: 84px;
  aspect-ratio: 3 / 4;
  height: auto;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #f1f5f9;
}

.thumb-card__body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}

.thumb-card__meta strong,
.saved-card strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thumb-card__meta small,
.saved-card small,
.hint {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.main-action {
  flex: 0 0 auto;
  display: grid;
  gap: 7px;
  margin-top: 10px;
}

.player-toolbar { margin-bottom: 10px; }

.player-frame-wrap {
  position: relative;
  flex: 1;
  min-height: 220px;
  container-type: size;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #0f172a;
}

.player-frame-wrap iframe {
  width: min(100cqw, calc(100cqh * 4 / 3));
  height: min(100cqh, calc(100cqw * 3 / 4));
  aspect-ratio: 4 / 3;
  border: 0;
  background: #ffffff;
}

@supports not (width: 1cqw) {
  .player-frame-wrap iframe {
    width: 100%;
    height: auto;
    max-height: 100%;
  }
}

.empty-player {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 6px;
  padding: 20px;
  text-align: center;
  color: #f8fafc;
  background: linear-gradient(135deg, #0f172a, #26344c);
}

.empty-player span { color: #cbd5e1; }

.saved-section {
  flex: 0 0 138px;
  min-height: 0;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  overflow: hidden;
}

.saved-head { margin-bottom: 8px; }

.saved-list {
  display: grid;
  gap: 8px;
  max-height: 84px;
}

.saved-list:empty::before {
  content: "保存済みはまだありません";
  color: var(--muted);
  font-size: 0.82rem;
}

.saved-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.button {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

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

.button--primary {
  width: 100%;
  min-height: 46px;
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
  font-size: 1rem;
}

.button--primary:hover:not(:disabled) { background: var(--primary-dark); }

.button--secondary {
  border-color: #99d1cb;
  background: #ecfdfb;
  color: var(--secondary);
}

.button--ghost { background: var(--panel-soft); }

.button--danger {
  border-color: #fecdca;
  background: var(--danger-bg);
  color: var(--danger);
}

.button--tiny {
  min-height: 30px;
  padding: 4px 8px;
  font-size: 0.78rem;
}

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

.field + .field {
  margin-top: 12px;
}

.field span {
  font-size: 0.82rem;
  font-weight: 800;
}

.field input {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #ffffff;
}

.modal,
.busy-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.46);
}

.modal__panel {
  position: relative;
  z-index: 1;
  width: min(520px, calc(100% - 28px));
  margin: 8dvh auto 0;
  padding: 18px;
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
}

.modal__head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.modal__head h2 { margin: 0; }
.modal__text { margin: 0 0 14px; color: var(--muted); }

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  font-size: 1.15rem;
  line-height: 1;
}

.busy-overlay {
  z-index: 70;
  display: grid;
  place-items: center;
  background: rgba(245, 246, 248, 0.72);
  backdrop-filter: blur(3px);
}

.busy-card {
  width: min(360px, calc(100% - 32px));
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 24px;
  border: 1px solid #b2ccff;
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.2);
  text-align: center;
}

.busy-card strong { font-size: 1.35rem; }
.busy-card span { color: var(--muted); }

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid #d6e4ff;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

body.is-busy .workspace,
body.is-busy .app-header,
body.is-busy .notice,
body.is-busy .status {
  filter: saturate(0.88);
}

@media (max-width: 1180px) {
  .workspace { grid-template-columns: minmax(250px, 300px) minmax(230px, 300px) minmax(360px, 1fr); }
  .notice { font-size: 0.8rem; }
}

@media (max-width: 980px) {
  body { overflow: auto; }
  .app-header { height: auto; align-items: flex-start; flex-direction: column; }
  .app-header h1 { white-space: normal; }
  .shell { height: auto; overflow: visible; }
  .notice { flex-direction: column; align-items: flex-start; }
  .workspace { grid-template-columns: 1fr; overflow: visible; }
  .panel { overflow: visible; }
  .camera-stage { width: min(100%, 340px); max-height: none; }
  .player-frame-wrap { min-height: 360px; }
  .saved-section { flex-basis: auto; }
  .saved-list { max-height: 220px; }
}
.thumb-card.is-submitted {
  border-color: #d5d9e2;
  background: #f3f4f6;
}

.thumb-card.is-submitted img {
  filter: grayscale(0.92);
  opacity: 0.58;
}

.thumb-card.is-submitted .thumb-card__meta strong,
.thumb-card.is-submitted .thumb-card__meta small {
  color: var(--muted);
}

.thumb-status {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 24px;
  margin-top: 5px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.2;
}

.thumb-status--sent {
  color: var(--muted);
  background: #e5e7eb;
  border: 1px solid #d1d5db;
}

.thumb-status--pending {
  color: var(--primary-dark);
  background: #eef4ff;
  border: 1px solid #b2ccff;
}
