/* セミナータイマー 共通スタイル */

:root {
  --bg: #10131a;
  --panel: #191e28;
  --panel-2: #212836;
  --line: #2c3444;
  --text: #eef2f8;
  --muted: #94a0b4;
  --accent: #4a9eff;
  --ok: #35c76a;
  --warn: #f5c542;
  --danger: #ff8f3d;
  --over: #ff3b30;
  --radius: 14px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', 'Yu Gothic UI',
    Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

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

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 0.5em 1em;
  transition: background 0.12s ease, border-color 0.12s ease;
}

button:hover:not(:disabled) {
  background: #2b3546;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #06121f;
  font-weight: 700;
}

button.primary:hover:not(:disabled) {
  background: #63adff;
}

button.ghost {
  background: transparent;
}

input[type='text'],
input[type='number'],
input[type='time'],
input[type='password'] {
  background: #0c0f15;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.5em 0.7em;
  width: 100%;
}

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

.tnum {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

.muted {
  color: var(--muted);
}

.hidden {
  display: none !important;
}

/* ===== 子機（表示画面）のレイアウト ===== */

/*
  上段は「進行表｜タイマー」の2列。チャットと返信は下に横いっぱいで置く。
  上段が伸び縮みするので、タイマーは残った高さをぜんぶ使う。
*/
.screen {
  display: grid;
  grid-template-columns: minmax(240px, 22vw) 1fr;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 12px;
  height: 100dvh;
  padding: 12px;
}

.screen > .schedule {
  grid-column: 1;
  grid-row: 1;
}

.screen > .timer-panel {
  grid-column: 2;
  grid-row: 1;
}

.screen > .chat {
  grid-column: 1 / -1;
  grid-row: 2;
}

.screen > .reply {
  grid-column: 1 / -1;
  grid-row: 3;
}

/* 左：進行表 */

.schedule {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 12px;
  overflow-y: auto;
  min-height: 0;
}

.schedule h2 {
  margin: 0 0 10px;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}

/* 進行表の開閉つまみ。畳めるのはスマホのときだけなので、
   広い画面では三角を出さない */
.schedule summary {
  list-style: none;
  margin-bottom: 8px;
}

.schedule summary::-webkit-details-marker {
  display: none;
}

.sched-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: baseline;
  padding: 9px 10px;
  border-radius: 10px;
  border-left: 3px solid transparent;
}

.sched-item + .sched-item {
  margin-top: 2px;
}

.sched-time {
  color: var(--muted);
  font-size: 0.95rem;
}

.sched-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.sched-min {
  color: var(--muted);
  font-size: 0.8rem;
  margin-left: 0.4em;
  font-weight: 400;
}

.sched-item.done {
  opacity: 0.42;
}

.sched-item.current {
  background: #263349;
  border-left-color: var(--accent);
}

.sched-item.current .sched-time {
  color: #bcd8ff;
}

.sched-item.current .sched-title::after {
  content: '  ←現在';
  color: var(--accent);
  font-size: 0.8rem;
  white-space: nowrap;
}

/* 右：タイマーとチャット */

.timer-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px 22px;
  display: grid;
  grid-template-rows: auto auto auto;
  justify-items: center;
  align-content: center;
  gap: 6px;
  min-height: 0;
  transition: background 0.4s ease, border-color 0.4s ease;
}

.clock {
  font-size: clamp(1.5rem, 3.4vw, 2.6rem);
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.clock-label {
  font-size: 0.62em;
  letter-spacing: 0.12em;
  margin-right: 0.1em;
  opacity: 0.85;
}

/* 枠いっぱいまで大きく。幅と高さの両方から、はみ出さない大きさを選ぶ */
.remain {
  font-size: clamp(3.6rem, min(19vw, 34vh), 18rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  margin: 0.04em 0;
  white-space: nowrap;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.14em;
}

.remain-label {
  font-size: 0.24em;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--muted);
}

/* 1時間を超えると桁が増えるので、その分だけ小さくする */
.remain.long {
  font-size: clamp(2.8rem, min(13.5vw, 26vh), 13rem);
}

.now-title {
  font-size: clamp(1.1rem, 2.6vw, 2rem);
  font-weight: 700;
  text-align: center;
}

.next-title {
  color: var(--muted);
  font-size: clamp(0.9rem, 1.6vw, 1.1rem);
  text-align: center;
}

.state-badge {
  font-size: 0.85rem;
  color: var(--muted);
}

/* まだ動いていないときは、数字を控えめにして「止まっている」と分かるようにする */
.timer-panel.idle .remain {
  color: var(--muted);
  opacity: 0.45;
}

/* 残り時間による色の変化 */

.timer-panel.warn {
  background: #3d3413;
  border-color: var(--warn);
}
.timer-panel.warn .clock,
.timer-panel.warn .remain-label,
.timer-panel.warn .next-title {
  color: #e8d79a;
}

.timer-panel.danger {
  background: #4a2c12;
  border-color: var(--danger);
}
.timer-panel.danger .clock,
.timer-panel.danger .remain-label,
.timer-panel.danger .next-title {
  color: #f2cba6;
}

.timer-panel.over {
  background: #5c1512;
  border-color: var(--over);
  animation: pulse-over 1.6s ease-in-out infinite;
}
.timer-panel.over .remain {
  color: #ffd9d6;
}
.timer-panel.over .clock,
.timer-panel.over .remain-label,
.timer-panel.over .next-title {
  color: #f5b5b1;
}

@keyframes pulse-over {
  0%,
  100% {
    background: #5c1512;
  }
  50% {
    background: #8b1c17;
  }
}

@media (prefers-reduced-motion: reduce) {
  .timer-panel.over {
    animation: none;
    background: #7a1a15;
  }
}

/* チャット */

.chat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  height: clamp(130px, 26vh, 280px);
  overflow: hidden;
}

.chat-head {
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.chat-log {
  overflow-y: auto;
  padding: 10px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.msg {
  border-radius: 12px;
  padding: 8px 12px;
  max-width: min(46rem, 92%);
}

.msg .who {
  font-size: 0.72rem;
  color: var(--muted);
  display: flex;
  gap: 0.6em;
}

.msg .body {
  overflow-wrap: anywhere;
}

.msg.admin {
  background: #223452;
  border: 1px solid #35507c;
  align-self: flex-start;
}

.msg.admin .body {
  font-size: 1.15rem;
  font-weight: 700;
}

.msg.client {
  background: var(--panel-2);
  align-self: flex-end;
}

.msg.latest.admin {
  background: #2a4f8a;
  border-color: #5b8fd6;
  box-shadow: 0 0 0 2px rgba(91, 143, 214, 0.28);
}

.msg.latest.admin .body {
  font-size: clamp(1.25rem, 2.4vw, 1.9rem);
}

.chat-empty {
  color: var(--muted);
  font-size: 0.9rem;
  margin: auto;
}

/* 返信 */

.reply {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.reply .quick {
  font-weight: 600;
}

.reply form {
  display: flex;
  gap: 8px;
  flex: 1 1 220px;
  min-width: 180px;
}

.reply form button,
.reply .quick {
  white-space: nowrap;
  flex: 0 0 auto;
}

/* 上部の小さな操作列 */

.topbar {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.topbar .me {
  font-size: 0.85rem;
  color: var(--muted);
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  margin-right: 0.4em;
  vertical-align: middle;
}

.dot.off {
  background: var(--over);
}

/* 名前を聞く画面 */

.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 20;
  padding: 20px;
}

.gate-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px;
  width: min(420px, 100%);
}

.gate-box h1 {
  margin: 0 0 4px;
  font-size: 1.3rem;
}

.gate-box p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

.gate-box .row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.name-picks {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.error {
  color: #ff9b95;
  font-size: 0.88rem;
  min-height: 1.4em;
}

/* ===== 画面が狭いとき（スマホ） ===== */

@media (max-width: 860px) {
  /* 縦に積む。上からタイマー・チャット・返信・進行表 */
  .screen {
    grid-template-columns: 1fr;
    /* 上からタイマー・チャット・返信・進行表。余った高さはタイマーが受け取る */
    grid-template-rows: minmax(44vh, 1fr) auto auto auto;
    height: auto;
    min-height: 100dvh;
    padding: 10px;
  }

  .screen > .timer-panel,
  .screen > .chat,
  .screen > .reply,
  .screen > .schedule {
    grid-column: 1;
    grid-row: auto;
  }

  .screen > .timer-panel {
    order: 1;
    padding: 16px 10px;
  }
  .screen > .chat {
    order: 2;
  }
  .screen > .reply {
    order: 3;
  }
  .screen > .schedule {
    order: 4;
    overflow: visible;
  }

  .remain {
    font-size: clamp(3.4rem, 24vw, 8rem);
  }

  .remain.long {
    font-size: clamp(2.4rem, 16vw, 5rem);
  }

  .schedule details > summary {
    cursor: pointer;
    color: var(--muted);
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    list-style: none;
  }

  .schedule details > summary::after {
    content: ' ▾';
  }

  .schedule details[open] > summary::after {
    content: ' ▴';
  }
}
