:root {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #20242b;
  background: #f3f5f8;
  --accent: #d83c3c;
  --panel: #fff;
  --muted: #697386;
}
* { box-sizing: border-box; }
body { margin: 0; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .42; }
.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 14px clamp(16px, 4vw, 44px); background: #fff;
  border-bottom: 1px solid #dce1e8;
}
h1 { font-size: 1.25rem; margin: 0; }
.identity { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.identity label, .settings label { font-size: .9rem; }
#username { width: 150px; padding: 7px 9px; border: 1px solid #c8ced8; border-radius: 7px; }
.hint { display: block; color: var(--muted); font-size: .78rem; }
.settings { margin-left: auto; position: relative; }
.settings summary { cursor: pointer; padding: 7px 10px; border: 1px solid #c8ced8; border-radius: 7px; }
.settings-panel {
  position: absolute; z-index: 5; right: 0; top: 38px; width: min(320px, 90vw);
  padding: 16px; background: white; border: 1px solid #dce1e8; border-radius: 10px;
  box-shadow: 0 8px 24px #1820331c; display: grid; gap: 12px;
}
.settings-panel label { display: grid; gap: 5px; }
.settings-panel select { padding: 7px; border: 1px solid #c8ced8; border-radius: 6px; }
main { width: min(1000px, 100%); margin: 0 auto; padding: 22px clamp(14px, 3vw, 28px) 30px; }
.game-area { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 8px 0 22px; }
.status { min-height: 1.5em; margin: 0 0 6px; color: #465064; }
.host-label { margin: 0 0 16px; font-weight: 700; }
.buzzer {
  width: clamp(190px, 35vw, 270px); aspect-ratio: 1; border: 0; border-radius: 50%;
  color: #fff; background: linear-gradient(145deg, #ef5555, #c92532);
  box-shadow: 0 10px 0 #8f1d27, 0 15px 24px #20242b26;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  transition: transform 110ms ease, box-shadow 110ms ease, filter 110ms ease;
  user-select: none; -webkit-tap-highlight-color: transparent;
}
.buzzer span { font-size: clamp(1.8rem, 5vw, 2.6rem); font-weight: 800; letter-spacing: .08em; }
.buzzer small { font-size: .75rem; letter-spacing: .18em; opacity: .85; }
.buzzer:not(:disabled):active, .buzzer.is-pressed {
  transform: translateY(7px) scale(.985);
  filter: brightness(.78);
  box-shadow: 0 3px 0 #8f1d27, 0 5px 10px #20242b26;
}
.buzzer-message { min-height: 1.4em; margin: 20px 0 0; color: var(--muted); font-size: .9rem; }
.lower-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(220px, .8fr); gap: 16px; }
.panel { background: var(--panel); border: 1px solid #e0e4eb; border-radius: 12px; padding: 16px; min-width: 0; }
.panel h2 { margin: 0 0 12px; font-size: 1.05rem; }
.history-list, .score-list { margin: 0; padding-left: 1.7rem; }
.history-list li, .score-list li { padding: 9px 8px; border-bottom: 1px solid #edf0f4; }
.history-list li:last-child, .score-list li:last-child { border-bottom: 0; }
.history-list li.current { background: #fff1bf; border-radius: 6px; font-weight: 700; }
.history-list li.correct { background: #d8f3df; border-radius: 6px; }
.history-list li.incorrect { background: #ffe0e0; border-radius: 6px; }
.history-list li .result, .score-value { float: right; font-weight: 700; }
.empty-state { color: #818999; list-style: none; margin-left: -1.7rem; }
.host-controls { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.control-button { min-width: 105px; padding: 10px 17px; border: 0; border-radius: 8px; color: white; font-weight: 700; box-shadow: 0 3px 0 #0002; }
.question-button { background: #344f80; }
.correct-button { background: #22834b; }
.incorrect-button { background: #b83b3b; }
.reset-button { background: #697386; }
.danger-button { background: #9c2633; color: white; border: 0; border-radius: 7px; padding: 9px 12px; cursor: pointer; }
.footer-note { color: var(--muted); font-size: .78rem; text-align: center; margin: 18px 0 0; }
dialog { border: 0; border-radius: 12px; max-width: min(420px, 90vw); box-shadow: 0 12px 40px #0003; }
dialog::backdrop { background: #10152280; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
@media (max-width: 640px) {
  .topbar { gap: 12px; }
  .settings { margin-left: 0; }
  .lower-layout { grid-template-columns: 1fr; }
  .buzzer { width: min(68vw, 245px); }
}

/* ルーム管理 */
.room-panel {
  margin-bottom: 24px;
}

.room-panel h2 {
  margin-top: 0;
}

.room-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0;
}

.room-actions label {
  margin-left: 4px;
}

#room-code-input {
  box-sizing: border-box;
  width: 150px;
  max-width: 100%;
  padding: 10px;
  font: inherit;
  text-transform: uppercase;
}

#connection-status,
#room-status {
  overflow-wrap: anywhere;
}

#room-info {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid #ccc;
}

#room-info h3 {
  margin-bottom: 8px;
}

#member-list {
  padding-left: 24px;
}

#member-list li {
  margin: 6px 0;
  overflow-wrap: anywhere;
}

#room-info[hidden] {
  display: none;
}

@media (max-width: 600px) {
  .room-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .room-actions label {
    margin-left: 0;
  }

  #room-code-input {
    width: 100%;
  }

  .room-actions button {
    width: 100%;
  }
}

/* ルーム参加ボタンを見やすくする */
#join-room-button {
  background-color: #2457a7;
  color: #fff;
  border: 1px solid #194681;
  font-weight: 600;
}

#join-room-button:hover:not(:disabled) {
  background-color: #194681;
}

#join-room-button:disabled {
  background-color: #aab8cc;
  color: #fff;
  border-color: #aab8cc;
  opacity: 1;
  cursor: not-allowed;
}

/* ルーム操作ボタン */
#create-room-button,
#join-room-button,
#leave-room-button {
  min-height: 44px;
  padding: 11px 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 3px 0 #0002;
}

#create-room-button {
  background: #187548;
  border-color: #125c38;
}

#create-room-button:hover:not(:disabled) {
  background: #125c38;
}

#join-room-button {
  background: #2457a7;
  border-color: #194681;
}

#join-room-button:hover:not(:disabled) {
  background: #194681;
}

#leave-room-button {
  background: #5b6472;
  border-color: #414957;
}

#leave-room-button:hover:not(:disabled) {
  background: #414957;
}

#create-room-button:disabled,
#join-room-button:disabled,
#leave-room-button:disabled {
  opacity: .55;
}

/* ルーム作成の確認ダイアログ */
#create-room-dialog {
  width: min(420px, 90vw);
  padding: 22px;
}

#create-room-dialog p {
  line-height: 1.6;
}

.create-confirm-button {
  background: #187548;
}

.cancel-button {
  background: #5b6472;
}

/* 問題リセット完了の表示 */
.status.reset-notice {
  padding: 12px 16px;
  margin: 8px 0 12px;
  border: 2px solid #187548;
  border-radius: 8px;
  background: #d8f3df;
  color: #125c38;
  font-weight: 800;
}