:root {
  --ink: #2a241c;
  --muted: #6d6256;
  --line: #d8cbb8;
  --paper: #f6efe4;
  --paper-2: #efe4d4;
  --chalk: #24382f;
  --chalk-2: #1b2c25;
  --wood: #b08968;
  --desk: #fffaf2;
  --desk-edge: #c9a57a;
  --aisle: rgba(36, 56, 47, 0.06);
  --hold: #f3e6cf;
  --danger: #a33b2b;
  --ok: #2a7a6e;
  --focus: #c4922a;
  --shadow: 0 10px 30px rgba(42, 36, 28, 0.08);
  --font: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", "Source Han Sans SC", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(1200px 500px at 10% -10%, #f3e2c4 0%, transparent 50%),
    #e7dccb;
  color: var(--ink);
  font-family: var(--font);
}

button, input, select { font-family: inherit; }

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

.app {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.top {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  flex-shrink: 0;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.06), transparent 40%),
    var(--chalk);
  color: #f3efe6;
  box-shadow: inset 0 -1px 0 rgba(255,255,255,0.06);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 220px; }

.logo {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #d7b15a;
  color: #2a241c;
  font-weight: 700;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.12);
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: #c9d4cc;
}

.class-name {
  width: min(240px, 42vw);
  border: 0;
  border-bottom: 1px dashed rgba(243, 239, 230, 0.45);
  background: transparent;
  color: #f3efe6;
  font-size: 18px;
  font-weight: 700;
  padding: 0 0 2px;
}

.class-name:focus { outline: none; border-bottom-color: #d7b15a; }

.toolbar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  max-width: 100%;
}

.sep {
  width: 1px;
  height: 18px;
  background: rgba(243, 239, 230, 0.18);
  margin: 0 2px;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(42, 36, 28, 0.08);
}

.top .btn {
  background: rgba(255,255,255,0.1);
  color: #f3efe6;
  border-color: rgba(255,255,255,0.12);
  box-shadow: none;
}

.top .btn:hover { background: rgba(255,255,255,0.16); }
.top .btn:disabled { opacity: 0.35; cursor: default; }

.btn-primary {
  background: #2a7a6e !important;
  color: #fff !important;
  border-color: #24685e !important;
}

.top .btn-primary { background: #d7b15a !important; color: #2a241c !important; border-color: #c49a3e !important; }

.btn-danger { background: #f8e8e4; color: var(--danger); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: default; }

.workspace {
  flex: 1 1 0;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 220px;
  gap: 12px;
  padding: 10px 12px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

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

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
}

.count { color: var(--muted); font-size: 12px; }

.add-form {
  display: grid;
  grid-template-columns: 1fr 64px;
  gap: 6px;
  margin-bottom: 8px;
}

.add-form input {
  grid-column: 1 / -1;
  min-width: 0;
  width: 100%;
}

.add-form input, .add-form select, .field input, .field select, .modal input, .modal select {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 7px 8px;
  font-size: 13px;
  color: var(--ink);
}

.add-form input:focus, .field input:focus, .modal input:focus {
  outline: 2px solid rgba(196, 146, 42, 0.35);
  border-color: var(--focus);
}

.roster-list {
  flex: 1 1 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  padding-right: 2px;
}

.roster-empty, .hold-empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  padding: 10px 4px;
}

.roster-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 8px;
  cursor: grab;
}

.roster-item.seated { opacity: 0.72; cursor: pointer; }
.roster-item .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c9bba6;
  flex: none;
}
.roster-item .name { flex: 1; font-size: 14px; font-weight: 600; }
.roster-item .tag { font-size: 11px; color: var(--muted); }
.roster-item.boy { box-shadow: inset 3px 0 0 #6f8fbf; }
.roster-item.girl { box-shadow: inset 3px 0 0 #c97b8a; }
.icon-btn {
  appearance: none;
  flex: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  width: 24px;
  height: 24px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.icon-btn:hover { background: #efe4d4; color: var(--ink); }
.icon-btn.del { font-size: 16px; }
.icon-btn.del:hover { background: #f8e8e4; color: var(--danger); }

.panel-actions { display: grid; gap: 6px; margin-top: 10px; flex-shrink: 0; }
#btn-bulk { margin: 0 0 8px; flex-shrink: 0; }
.add-form { flex-shrink: 0; }

.more { margin-top: 10px; font-size: 13px; color: var(--muted); flex-shrink: 0; }
.more summary { cursor: pointer; }
.more-body {
  display: grid;
  gap: 8px;
  margin-top: 8px;
  max-height: 28vh;
  overflow: auto;
}
.field { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }

.classroom {
  background:
    linear-gradient(180deg, #efe2cd, #e6d3b5);
  border: 1px solid #d2b48c;
  border-radius: 16px;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255,255,255,0.35);
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.podium {
  background:
    repeating-linear-gradient(90deg, #2d3f36 0 18px, #33463c 18px 36px);
  color: #f0e6d2;
  text-align: center;
  padding: 8px 12px;
  border-radius: 8px;
  letter-spacing: 0.4em;
  font-size: 14px;
  font-weight: 700;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.18);
}

.podium.hidden, .hidden { display: none !important; }

.row-tag {
  text-align: center;
  color: #7a6a56;
  font-size: 12px;
  padding: 6px 0 4px;
}

.board-scroll {
  flex: 1 1 0;
  overflow: auto;
  min-height: 0;
}

.board-inner { position: relative; min-width: max-content; padding: 34px 6px 18px; }

.board { display: flex; flex-direction: column; gap: 10px; }

.desk-row {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 10px;
}

.aisle {
  width: 28px;
  border-radius: 999px;
  background: var(--aisle);
}

.group-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  flex-shrink: 0;
}
.group-bar-label { font-size: 12px; color: #7a6a56; }
.group-bar .btn { padding: 4px 8px; font-size: 12px; }
.group-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-left: 4px; }
.group-chip {
  appearance: none;
  border: 0;
  background: var(--g, #888);
  color: #fff;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: grab;
  touch-action: none;
}
.group-chip.selected { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--g, #888); }

.pair {
  position: relative;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #f8edd9, #f1dfc3);
  border: 1px solid var(--desk-edge);
  border-radius: 12px;
  box-shadow: 0 2px 0 #b8895b, 0 8px 16px rgba(80, 50, 20, 0.08);
  min-width: 168px;
}

.pair-handle {
  appearance: none;
  border: 0;
  background: transparent;
  color: #8a6a45;
  font-size: 11px;
  padding: 3px 8px 0;
  cursor: grab;
  letter-spacing: 0.12em;
}

.pair-handle[disabled] {
  opacity: 0.35;
  cursor: default;
}
.pair-handle-group {
  color: #fff;
  background: var(--g, #888);
  border-radius: 8px;
  margin: 4px 8px 0;
  padding: 3px 8px;
  letter-spacing: 0;
  font-weight: 700;
}

.pair-dot {
  position: absolute;
  top: auto;
  bottom: 6px;
  right: 6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: var(--g, #c9bba6);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.12);
  padding: 0;
  cursor: pointer;
  z-index: 2;
}
.pair-dot:hover { transform: scale(1.12); }

.pair-seats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

.seat {
  min-height: 56px;
  min-width: 82px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 8px;
  font-size: 16px;
  font-weight: 700;
  user-select: none;
  touch-action: none;
}

.seat + .seat { border-left: 1px dashed #d7c2a3; }

.seat.empty {
  color: #c3b19a;
  font-weight: 500;
  font-size: 13px;
  background:
    repeating-linear-gradient(135deg, transparent, transparent 6px, rgba(180,150,110,0.07) 6px, rgba(180,150,110,0.07) 7px);
}

.seat.filled { background: var(--desk); cursor: grab; }
.seat.filled.boy { box-shadow: inset 0 -3px 0 #8aa4c9; }
.seat.filled.girl { box-shadow: inset 0 -3px 0 #d49aa4; }
.seat.filled[style*="--g"] { box-shadow: inset 0 -3px 0 var(--g); }

.seat.selected {
  outline: 3px solid #d7b15a;
  outline-offset: -3px;
  z-index: 1;
}

.seat.drop-ok,
.seat.group-preview {
  outline: 2px dashed var(--ok);
  outline-offset: -3px;
  background: #e7f3ef;
}
.seat.group-preview {
  outline-style: solid;
  background: #dceee8;
}
.seat.drop-swap {
  outline: 2px dashed #c4922a;
  outline-offset: -3px;
}

.seat.flash {
  animation: flash 0.8s ease;
}

@keyframes flash {
  0%, 100% { box-shadow: inset 0 0 0 0 transparent; }
  40% { box-shadow: inset 0 0 0 3px #d7b15a; }
}

.chip-name { pointer-events: none; text-align: center; line-height: 1.2; }

.group-layer { position: absolute; inset: 0; pointer-events: none; z-index: 5; }

.group-box {
  position: absolute;
  pointer-events: none;
  border: 2px solid var(--g, #888);
  border-radius: 10px;
  box-shadow: none;
}

.group-handle {
  pointer-events: auto;
  position: absolute;
  left: 4px;
  right: 4px;
  top: 0;
  transform: none;
  appearance: none;
  border: 0;
  background: var(--g, #888);
  color: #fff;
  border-radius: 8px;
  padding: 0 10px;
  height: 28px;
  font-size: 13px;
  font-weight: 700;
  cursor: grab;
  white-space: nowrap;
  touch-action: none;
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
}

.group-box.selected { box-shadow: none; border-width: 3px; }
.group-box.drop-ok { outline: 2px dashed var(--ok); }
.group-box.preview {
  border-style: dashed;
  background: rgba(255, 255, 255, 0.28);
  z-index: 6;
}
.group-box.pair-frame {
  border-width: 2px;
  border-radius: 12px;
  background: transparent;
}
.group-box.handle-only {
  border: 0;
  background: transparent;
  overflow: visible;
}

.hold-panel { background: var(--hold); }

.hold-tip {
  margin: 0 0 8px;
  font-size: 12px;
  color: #7a6246;
  line-height: 1.45;
}

.holding {
  flex: 1 1 0;
  min-height: 0;
  border: 2px dashed #d2b48c;
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
  background: rgba(255,255,255,0.35);
}

.hold-chip {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-weight: 700;
  cursor: grab;
  touch-action: none;
}

.hold-chip.boy { box-shadow: inset 3px 0 0 #6f8fbf; }
.hold-chip.girl { box-shadow: inset 3px 0 0 #c97b8a; }

.group-help { margin-top: 10px; }
.group-help p { margin: 0 0 4px; font-size: 12px; color: #7a6246; line-height: 1.4; }

.group-pop {
  position: fixed;
  z-index: 55;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: 220px;
  padding: 8px;
  background: #fffaf2;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.16);
}
.group-pop button {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
}
.group-pop button.on {
  background: var(--g, #c45c46);
  color: #fff;
  border-color: transparent;
}

.pal {
  appearance: none;
  border: 1px solid transparent;
  background: var(--g);
  color: #fff;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
}

.pal.on { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--g); }
.pal.off { background: #efe4d4; color: var(--muted); border-color: var(--line); }

.hint {
  padding: 6px 16px 8px;
  color: var(--muted);
  font-size: 13px;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(42, 36, 28, 0.35);
  display: grid;
  place-items: center;
  z-index: 40;
  padding: 16px;
}

.modal-card {
  width: min(420px, 100%);
  background: var(--paper);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.18);
}

.modal-card h3 { margin: 0 0 12px; }
.modal-card .field { margin-bottom: 10px; }
.modal-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.grow { flex: 1; }
.help-card ol { padding-left: 1.2em; line-height: 1.6; }
.bulk-card { width: min(480px, 100%); }
.bulk-tip { margin: 0 0 8px; color: var(--muted); font-size: 13px; line-height: 1.5; }
#bulk-text {
  width: 100%;
  min-height: 200px;
  resize: vertical;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
}
#bulk-text:focus {
  outline: 2px solid rgba(196, 146, 42, 0.35);
  border-color: var(--focus);
}
.bulk-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 10px 0 4px;
}
.check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--ink);
  flex: 1;
}
.help-card p { color: var(--muted); font-size: 13px; line-height: 1.5; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--chalk);
  color: #f3efe6;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 50;
  max-width: min(90vw, 520px);
}

.ghost {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  background: #fffaf2;
  border: 1px solid var(--desk-edge);
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(0,0,0,0.16);
}

body.dragging { cursor: grabbing; }
body.dragging * { cursor: grabbing !important; }

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 220px minmax(0, 1fr) 180px;
    gap: 8px;
    padding: 8px;
  }
}

@media (max-width: 820px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 26vh) minmax(0, 1fr) minmax(0, 22vh);
  }
  .top { flex-wrap: wrap; }
  .hint { white-space: normal; }
}

@media print {
  html, body { height: auto; overflow: visible; background: #fff; }
  .app { height: auto; max-height: none; overflow: visible; }
  .top .toolbar, .roster-panel, .hold-panel, .hint, .modal, .toast, .ghost { display: none !important; }
  .workspace { display: block; padding: 0; overflow: visible; }
  .classroom { box-shadow: none; border: 0; overflow: visible; height: auto; }
  .board-scroll { overflow: visible; }
}
