:root {
  --bg: #f1eadc;
  --surface: rgba(255, 252, 246, 0.92);
  --surface-strong: #fffdf8;
  --ink: #263134;
  --muted: #6a7573;
  --line: #d7ccb8;
  --brand: #214f48;
  --brand-soft: #335f59;
  --accent: #d79042;
  --accent-soft: #eed9b0;
  --danger: #b85a44;
  --warning: #8d6a2f;
  --success: #416a51;
  --shadow: 0 18px 40px rgba(63, 58, 44, 0.12);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --font-sans: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-sans);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(215, 144, 66, 0.14), transparent 28%),
    linear-gradient(180deg, #f7f0e1 0%, #ede3cf 100%);
}

button,
input,
summary {
  font: inherit;
}

button,
summary {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
summary:focus-visible,
.class-tab:focus-visible {
  outline: 3px solid rgba(33, 79, 72, 0.24);
  outline-offset: 3px;
}

.app-shell {
  min-height: 100vh;
  max-width: 1320px;
  margin: 0 auto;
  padding: 10px 14px 18px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid rgba(215, 204, 184, 0.95);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand h1,
.panel-head h2,
.sheet-header h2,
.empty-state h2,
.student-name {
  margin: 0;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  font-weight: 700;
}

.eyebrow,
.panel-kicker,
.sheet-kicker,
.empty-kicker {
  margin: 0 0 6px;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.eyebrow {
  margin-bottom: 2px;
}

.brand h1 {
  font-size: 22px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
}

.class-menu,
.settings-menu {
  position: relative;
}

.class-menu summary,
.settings-menu summary {
  list-style: none;
}

.class-menu summary::-webkit-details-marker,
.settings-menu summary::-webkit-details-marker {
  display: none;
}

.class-menu-trigger {
  min-width: 128px;
  min-height: 38px;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
}

.class-menu-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.class-menu-value {
  color: var(--ink);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.class-menu-card,
.settings-card {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 10;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(255, 252, 246, 0.98);
  box-shadow: var(--shadow);
}

.class-menu-card {
  width: 180px;
}

.search-field {
  display: grid;
  gap: 4px;
  min-width: 180px;
}

.search-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
}

.search-field input {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  font-size: 13px;
}

.toolbar-btn {
  appearance: none;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.toolbar-btn:hover,
.settings-menu[open] > summary {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(44, 51, 45, 0.08);
  border-color: rgba(33, 79, 72, 0.24);
}

.toolbar-btn.primary {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-soft) 100%);
  border-color: transparent;
  color: #fff;
}

.toolbar-btn:disabled {
  opacity: 0.7;
  cursor: progress;
}

.settings-card {
  width: 220px;
}

.settings-title {
  margin: 0 0 6px;
  font-weight: 700;
}

.settings-note {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.settings-danger {
  width: 100%;
  color: var(--danger);
  border-color: rgba(184, 90, 68, 0.28);
}

.workspace {
  margin-top: 8px;
  min-height: calc(100vh - 88px);
}

.sheet-shell,
.empty-state {
  background: var(--surface);
  border: 1px solid rgba(215, 204, 184, 0.95);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.tab-list {
  display: grid;
  gap: 8px;
}

.tab-list.compact {
  gap: 6px;
}

.class-tab {
  appearance: none;
  position: relative;
  min-height: 72px;
  padding: 12px 12px 12px 16px;
  border: 1px solid rgba(215, 204, 184, 0.95);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(248, 244, 236, 0.95));
  text-align: left;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.tab-list.compact .class-tab {
  min-height: 60px;
  padding: 10px 10px 10px 14px;
  border-radius: 14px;
}

.class-tab::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 4px;
  border-radius: 999px;
  background: var(--tab-color);
}

.class-tab:hover,
.class-tab.active {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(40, 44, 41, 0.08);
  border-color: rgba(33, 79, 72, 0.18);
}

.class-tab.active {
  background: linear-gradient(135deg, color-mix(in srgb, var(--tab-color) 13%, white), rgba(255, 255, 255, 0.96));
}

.tab-grade {
  display: block;
  font-size: 16px;
  font-weight: 800;
}

.tab-course {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.main-stage {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.banner {
  margin-bottom: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 700;
}

.banner.info {
  background: #edf5f3;
  border-color: rgba(33, 79, 72, 0.18);
}

.banner.success {
  background: #edf5ef;
  border-color: rgba(65, 106, 81, 0.22);
}

.banner.warning {
  background: #fbf2e4;
  border-color: rgba(141, 106, 47, 0.24);
}

.banner.danger {
  background: #f9ece8;
  border-color: rgba(184, 90, 68, 0.26);
}

.content-stage {
  min-height: 100%;
}

.sheet-shell {
  padding: 18px;
  max-width: 1240px;
  margin: 0 auto;
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.sheet-heading {
  min-width: 0;
}

.sheet-header h2 {
  font-size: clamp(26px, 4vw, 40px);
  line-height: 1.08;
}

.sheet-meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.sheet-chip,
.search-status,
.badge,
.school-chip,
.legend-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
}

.sheet-chip {
  background: rgba(33, 79, 72, 0.08);
  color: var(--brand);
}

.search-status {
  background: rgba(215, 144, 66, 0.12);
  color: var(--warning);
}

.search-status.active {
  background: rgba(33, 79, 72, 0.12);
  color: var(--brand);
}

.sheet-count {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  min-height: 54px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--brand);
  font-size: 18px;
  font-weight: 900;
}

.inline-status {
  margin-bottom: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  background: rgba(33, 79, 72, 0.08);
  color: var(--brand);
  font-size: 11px;
}

.seat-canvas {
  padding: 14px;
  border: 1px solid rgba(215, 204, 184, 0.94);
  border-radius: 16px;
  background: rgba(255, 253, 248, 0.92);
}

.seat-grid {
  display: grid;
  gap: 14px;
}

.seat-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 56px minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
}

.seat-aisle {
  width: 56px;
}

.seat-card,
.guide-cell {
  min-width: 0;
  border: 1px solid rgba(54, 56, 60, 0.72);
  background-color: #fff;
  background-image:
    linear-gradient(rgba(205, 212, 216, 0.38) 1px, transparent 1px),
    linear-gradient(90deg, rgba(205, 212, 216, 0.38) 1px, transparent 1px);
  background-size: 18px 18px;
}

.seat-card {
  min-height: 320px;
  padding: 12px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
  transition: opacity 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.seat-card.matched {
  box-shadow: 0 0 0 2px rgba(215, 144, 66, 0.24);
}

.seat-card.dimmed {
  opacity: 0.32;
}

.seat-card.empty {
  min-height: 226px;
}

.is-guide-row .seat-card.empty,
.is-guide-row .guide-cell {
  min-height: 272px;
}

.guide-cell {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-color: #fffdfa;
}

.guide-room {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
}

.guide-sample {
  padding: 12px 12px 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 250, 239, 0.82);
}

.guide-reserve {
  max-width: none;
}

.guide-furi,
.guide-name {
  margin: 0;
}

.guide-furi {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.guide-name {
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.1;
}

.guide-sample-row {
  height: 12px;
  margin-top: 10px;
  border-radius: 999px;
  background: rgba(230, 236, 239, 0.92);
}

.guide-lines {
  display: grid;
  gap: 8px;
  align-content: start;
}

.guide-line {
  display: flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(215, 204, 184, 0.86);
  background: rgba(250, 245, 234, 0.88);
  font-size: 11px;
  font-weight: 700;
  color: #556361;
}

.guide-line.empty {
  color: #adb2aa;
}

.guide-line-text {
  display: block;
  width: 100%;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.seat-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
}

.seat-tags {
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.reserve-stack {
  display: grid;
  gap: 12px;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 68%;
  padding-top: 6px;
}

.reserve-line {
  display: block;
  width: 100%;
  border-top: 3px dashed rgba(215, 204, 184, 0.88);
}

.badge.sen,
.legend-pill.sen {
  background: #efd7d3;
  color: #934938;
}

.badge.ren,
.legend-pill.ren {
  background: #d9e7ef;
  color: #325f7c;
}

.school-chip {
  background: rgba(33, 79, 72, 0.08);
  color: var(--brand);
}

.furi {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.1;
}

.student-name {
  font-size: clamp(28px, 2.7vw, 38px);
  line-height: 1.08;
  letter-spacing: 0.01em;
  word-break: keep-all;
}

.score-stack {
  margin-top: auto;
  display: grid;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.score-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 100%;
  min-height: 34px;
  padding: 0 8px 0 10px;
  border-radius: 12px;
  background: rgba(230, 236, 239, 0.92);
  overflow: hidden;
}

.score-row.empty {
  background: rgba(235, 240, 243, 0.82);
}

.score-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1 1 auto;
}

.legend-pill.neutral {
  background: rgba(33, 79, 72, 0.1);
  color: var(--brand);
}

.legend-pill.rank-s {
  background: #edd7d2;
  color: #923f31;
}

.legend-pill.rank-t {
  background: #f5dfba;
  color: #996110;
}

.legend-pill.rank-a {
  background: #dae9d8;
  color: #44754d;
}

.score-values {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-result {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  white-space: nowrap;
}

.score-total {
  color: var(--brand);
  font-size: 13px;
  line-height: 1;
  font-weight: 900;
}

.score-placeholder {
  width: 100%;
  height: 100%;
  border-radius: 10px;
  background: rgba(233, 238, 241, 0.9);
}

.blackboard {
  margin-top: 14px;
  padding: 10px;
  background: #0b0b0b;
  color: #fff;
  text-align: center;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0.24em;
}

.empty-state {
  padding: 48px 36px;
  text-align: center;
}

.empty-state p {
  margin: 14px auto 0;
  max-width: 32rem;
  color: var(--muted);
  line-height: 1.7;
}

.error-state {
  border-color: rgba(184, 90, 68, 0.24);
}

.inline-action {
  margin-top: 18px;
}

.no-seat-data {
  padding: 40px;
  text-align: center;
  color: var(--muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 1280px) {
  .app-shell {
    max-width: 1180px;
  }

  .sheet-shell {
    max-width: 1120px;
  }

  .seat-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 36px minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
  }

  .seat-aisle {
    width: 36px;
  }

  .student-name {
    font-size: clamp(24px, 2.4vw, 34px);
  }

  .score-total {
    font-size: 18px;
  }
}

@media (max-width: 980px) {
  .app-shell {
    max-width: none;
    padding: 12px;
  }

  .topbar {
    display: block;
  }

  .toolbar {
    margin-top: 12px;
    justify-content: flex-start;
  }

  .sheet-shell {
    max-width: none;
  }

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

  .seat-aisle {
    display: none;
  }

  .seat-card,
  .guide-cell,
  .seat-card.empty {
    min-height: 260px;
  }
}

@media (max-width: 760px) {
  .brand h1 {
    font-size: 28px;
  }

  .class-menu-trigger {
    min-width: 100%;
  }

  .search-field {
    min-width: 100%;
  }

  .toolbar {
    gap: 8px;
  }

  .toolbar-btn,
  .settings-menu {
    flex: 1 1 auto;
  }

  .sheet-header {
    display: block;
  }

  .sheet-count {
    margin-top: 12px;
    min-width: 54px;
    min-height: 54px;
    font-size: 18px;
  }

  .seat-row {
    grid-template-columns: 1fr;
  }

  .seat-card,
  .guide-cell,
  .seat-card.empty {
    min-height: auto;
  }

  .guide-body {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    background: #fff;
  }

  .app-shell {
    padding: 0;
  }

  .topbar,
  .banner,
  .inline-status {
    display: none !important;
  }

  .workspace {
    display: block;
    margin: 0;
    min-height: auto;
  }

  .sheet-shell,
  .seat-canvas {
    padding: 0;
    background: #fff;
    border: 0;
    box-shadow: none;
  }

  .sheet-shell {
    border-radius: 0;
  }

  .sheet-header {
    margin-bottom: 10px;
  }

  .sheet-header h2 {
    font-size: 28px;
  }

  .sheet-chip,
  .search-status {
    background: #f2f2f2;
    color: #222;
  }

  .seat-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 24px minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
  }

  .seat-card,
  .guide-cell {
    min-height: 210px;
    box-shadow: none;
  }

  .is-guide-row .seat-card.empty,
  .is-guide-row .guide-cell {
    min-height: 170px;
  }

  .seat-card.dimmed {
    opacity: 1;
  }

  .student-name {
    font-size: 22px;
  }

  .blackboard {
    margin-top: 12px;
    font-size: 14px;
  }

  @page {
    size: A4 landscape;
    margin: 10mm;
  }
}
