:root {
  color-scheme: light;
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  --bg: #f7f8f5;
  --ink: #1f2520;
  --muted: #69726a;
  --line: #d9ded5;
  --paper: #ffffff;
  --accent: #247565;
  --accent-strong: #14584b;
  --ok: #1d8c47;
  --warn: #c16b29;
  --header-height: 76px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  background: rgba(247, 248, 245, 0.94);
  backdrop-filter: blur(10px);
}

.app-header > div:first-child {
  flex: 1 1 auto;
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 34px);
  line-height: 1.1;
  letter-spacing: 0;
  overflow-wrap: normal;
  white-space: nowrap;
}

p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.header-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

@media (orientation: landscape) and (max-height: 560px) {
  .app-header {
    gap: 10px;
    padding: 8px 12px;
  }

  .app-header > div:first-child {
    flex: 0 1 auto;
    min-width: 124px;
  }

  h1 {
    font-size: 20px;
    line-height: 1.15;
  }

  p {
    margin-top: 2px;
    font-size: 11px;
    line-height: 1.25;
    white-space: nowrap;
  }

  .header-actions {
    flex: 1 1 auto;
    flex-wrap: nowrap;
    gap: 6px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
  }

  .secondary-button {
    min-height: 34px;
    padding: 0 10px;
    font-size: 13px;
    white-space: nowrap;
  }

  .sound-toggle {
    min-width: 74px;
    gap: 5px;
  }

  .sound-icon {
    width: 22px;
    height: 20px;
  }

  .sound-icon svg {
    width: 18px;
    height: 18px;
  }

  .meter-panel {
    grid-template-columns: minmax(92px, auto) minmax(120px, 1fr) 42px;
    gap: 10px;
    padding: 9px 12px;
  }
}

.secondary-button,
.answer-toggle {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid #bfc7bc;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}

.secondary-button:hover,
.answer-toggle:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

a.secondary-button.nav-button {
  display: flex;
  align-items: center;
  justify-content: center;
}

.sound-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 88px;
}

.sound-toggle[aria-pressed="true"] {
  border-color: rgba(36, 117, 101, 0.52);
  background: #eef8f3;
  color: var(--accent-strong);
}

.sound-toggle[aria-pressed="false"] {
  background: #f5f2ef;
  color: #7b675d;
}

.sound-icon {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 24px;
}

.sound-icon::after {
  content: "";
  position: absolute;
  right: -3px;
  top: 1px;
  width: 8px;
  height: 8px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--ok);
}

.sound-toggle[aria-pressed="false"] .sound-icon::after {
  background: #a96b4f;
}

.sound-icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.sound-off-icon,
.sound-toggle[aria-pressed="false"] .sound-on-icon {
  display: none;
}

.sound-toggle[aria-pressed="false"] .sound-off-icon {
  display: block;
}

.sound-state {
  min-width: 24px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

#bgmButton[aria-pressed="true"] {
  border-color: rgba(36, 117, 101, 0.52);
  background: #eef8f3;
  color: var(--accent-strong);
  font-weight: 800;
}

.settings-dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}

.settings-dialog::backdrop {
  background: rgba(31, 37, 32, 0.32);
}

.settings-panel {
  display: grid;
  gap: 18px;
  padding: 18px;
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-head h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0;
}

.icon-close {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid #bfc7bc;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 22px;
  cursor: pointer;
}

.volume-control {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 48px;
  align-items: center;
  gap: 12px;
}

.volume-control input {
  height: auto;
  padding: 0;
}

.volume-control input[type="number"] {
  height: 40px;
  padding: 0 10px;
}

.volume-control select {
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0 10px;
  border: 1px solid #bfc7bc;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.switch-control input[type="checkbox"] {
  justify-self: start;
  width: 48px;
  height: 28px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.volume-control strong {
  color: var(--accent-strong);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.range-summary {
  padding: 8px 10px;
  border: 1px solid rgba(36, 117, 101, 0.24);
  border-radius: 6px;
  background: #eef8f3;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.4;
}

.meter-panel {
  position: sticky;
  top: var(--header-height);
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(112px, auto) minmax(140px, 1fr) 48px;
  align-items: center;
  gap: 14px;
  padding: 14px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  background: #eef2ec;
}

.meter-label {
  display: flex;
  align-items: baseline;
  gap: 10px;
  white-space: nowrap;
}

.meter-label span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.meter-label strong,
.meter-percent {
  font-variant-numeric: tabular-nums;
}

.meter-track {
  height: 12px;
  overflow: hidden;
  border: 1px solid #b9c7bd;
  border-radius: 999px;
  background: #fff;
}

.meter-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--warn), var(--accent));
  transition: width 180ms ease;
}

.meter-percent {
  text-align: right;
  color: var(--accent-strong);
  font-weight: 800;
}

.student-list {
  display: grid;
  gap: 10px;
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 22px clamp(12px, 3vw, 28px) 40px;
}

.student-row {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  align-items: start;
  gap: 18px;
  min-height: 146px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.student-row.is-speaking,
.seat-card.is-speaking {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(36, 117, 101, 0.16);
  animation: speakingPulse 900ms ease-in-out infinite;
}

.student-row.is-speaking {
  background: #f3fbf5;
}

@keyframes speakingPulse {
  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-2px);
  }
}

.student-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 4px;
}

.number {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #edf0ea;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.gender-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  cursor: pointer;
}

.gender-icon:focus-visible {
  outline: 3px solid rgba(36, 117, 101, 0.32);
  outline-offset: 3px;
}

.answer-area {
  display: grid;
  gap: 10px;
}

.answer-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

label {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 24px;
  align-items: center;
  gap: 8px;
}

label span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input,
textarea,
select {
  width: 100%;
  min-width: 0;
  padding: 0 12px;
  border: 1px solid #bfc7bc;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 17px;
}

input,
select {
  height: 42px;
}

textarea {
  min-height: 56px;
  padding-top: 8px;
  padding-bottom: 8px;
  resize: vertical;
  font-size: 15px;
  line-height: 1.45;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(36, 117, 101, 0.16);
}

input.correct {
  border-color: rgba(29, 140, 71, 0.65);
  background: #f3fbf5;
}

b {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  color: var(--ok);
  font-size: 20px;
  line-height: 1;
}

b.is-correct::before {
  content: "●";
}

.answer-tools,
.comment-field {
  display: grid;
  grid-template-columns: 88px 132px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.answer-toggle,
.answer-reset {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.answer-text {
  color: var(--accent-strong);
  font-weight: 800;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.answer-reset {
  border: 1px solid #bfc7bc;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.answer-reset:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.comment-field {
  grid-template-columns: 44px minmax(0, 1fr);
}

.speech-mode-field {
  grid-template-columns: 44px minmax(0, 240px);
}

.seating-page {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 22px clamp(12px, 3vw, 28px) 44px;
}

.seating-chart {
  padding: clamp(16px, 3vw, 28px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
}

.screen-label {
  width: min(460px, 72%);
  margin: 0 auto 34px;
  padding: 14px 18px;
  border: 2px solid #8d958c;
  text-align: center;
  color: #303831;
  font-size: clamp(20px, 3vw, 30px);
  font-weight: 800;
  letter-spacing: 0;
}

.seat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 1fr)) minmax(24px, 72px) repeat(2, minmax(150px, 1fr));
  gap: clamp(14px, 2vw, 22px) 0;
}

.seat-card {
  min-width: 0;
  min-height: 158px;
  padding: 10px;
  border: 1.5px solid #5c625b;
  background: #fff;
}

.seat-card:nth-child(4n + 1),
.seat-card:nth-child(4n + 3) {
  border-right-width: 0;
}

.seat-top {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  margin-bottom: 8px;
}

.seat-top .gender-icon {
  width: 30px;
  height: 30px;
}

.seat-reveal,
.seat-reset {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid #bfc7bc;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}

.seat-reveal {
  margin-left: auto;
}

.seat-reveal:hover,
.seat-reset:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.seat-answer {
  min-height: 28px;
  margin-bottom: 8px;
  color: var(--accent-strong);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.seat-input-row {
  grid-template-columns: 38px minmax(0, 1fr) 22px;
  gap: 6px;
  margin-top: 7px;
}

.seat-speech-field {
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 6px;
  margin-top: 7px;
}

.seat-input-row span {
  font-size: 12px;
}

.seat-input-row input,
.seat-speech-field select {
  height: 36px;
  padding: 0 9px;
  font-size: 15px;
}

@media (max-width: 720px) {
  .app-header {
    align-items: flex-start;
    padding: 14px 16px;
  }

  .meter-panel {
    grid-template-columns: 1fr 48px;
    gap: 10px;
    padding: 12px 16px;
  }

  .meter-label {
    grid-column: 1 / -1;
  }

  .student-row {
    grid-template-columns: 1fr;
    gap: 12px;
    min-height: 0;
    padding: 14px;
  }

  .student-meta {
    padding-top: 0;
  }

  .answer-fields {
    grid-template-columns: 1fr;
  }

  .answer-tools {
    grid-template-columns: 88px 132px minmax(0, 1fr);
  }

  .seating-page {
    padding: 14px 10px 32px;
  }

  .seating-chart {
    padding: 14px 10px;
  }

  .screen-label {
    width: min(360px, 82%);
    margin-bottom: 22px;
  }

  .seat-grid {
    grid-template-columns: repeat(2, minmax(132px, 1fr)) 18px repeat(2, minmax(132px, 1fr));
    overflow-x: auto;
    padding-bottom: 6px;
  }

  .seat-card {
    min-height: 156px;
  }
}

@media (max-width: 420px) {
  .app-header {
    flex-direction: column;
    gap: 10px;
  }

  .header-actions,
  .secondary-button {
    width: 100%;
  }

  .header-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .secondary-button {
    min-height: 38px;
    padding: 0 8px;
    font-size: 13px;
  }

  .student-list {
    gap: 12px;
    padding: 14px 10px 28px;
  }

  label {
    grid-template-columns: 40px minmax(0, 1fr) 22px;
    gap: 6px;
  }

  .answer-tools {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .answer-text {
    grid-column: 1 / -1;
  }

  .comment-field {
    grid-template-columns: 40px minmax(0, 1fr);
  }

  .seat-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px 0;
    overflow-x: visible;
  }

  .seat-card {
    grid-column: auto !important;
    min-height: 150px;
  }

  .seat-card:nth-child(4n + 1),
  .seat-card:nth-child(4n + 3) {
    border-right-width: 0;
  }

  .seat-card:nth-child(4n + 2) {
    margin-right: 12px;
  }

  .seat-card:nth-child(4n + 3) {
    margin-left: 12px;
  }

  .seat-top .number {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  .seat-top .gender-icon {
    width: 28px;
    height: 28px;
  }

  .seat-reveal,
  .seat-reset {
    min-height: 28px;
    padding: 0 6px;
    font-size: 11px;
  }

  .seat-input-row {
    grid-template-columns: 34px minmax(0, 1fr) 18px;
  }
}

@media (max-width: 360px) {
  .header-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (orientation: portrait) and (max-width: 540px) {
  h1 {
    font-size: 24px;
  }

  p {
    font-size: 12px;
    line-height: 1.45;
  }

  .meter-panel {
    grid-template-columns: 1fr;
  }

  .meter-label {
    grid-column: auto;
    justify-content: space-between;
  }

  .meter-percent {
    text-align: left;
  }

  input {
    height: 44px;
    font-size: 16px;
  }

  textarea {
    font-size: 14px;
  }
}
