:root {
  --ink: #20322d;
  --muted: #69756f;
  --paper: #f4f0e8;
  --card: #fffdf8;
  --line: #dcd8ce;
  --green: #2e6653;
  --shadow: 0 16px 45px rgba(43, 54, 48, 0.08);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 12%, rgba(229, 190, 104, .15), transparent 26rem),
    radial-gradient(circle at 94% 38%, rgba(93, 157, 129, .11), transparent 28rem),
    var(--paper);
  font-family: "DM Sans", system-ui, sans-serif;
  min-height: 100vh;
}

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

.app-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding-bottom: 90px; }

.topbar {
  height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(32, 50, 45, .13);
}

.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; font-weight: 700; }
.brand-mark { width: 31px; height: 31px; position: relative; display: grid; place-items: center; }
.brand-mark i { position: absolute; width: 14px; height: 14px; border-radius: 50%; background: var(--green); }
.brand-mark i:nth-child(1) { transform: translate(-7px, 6px); }
.brand-mark i:nth-child(2) { transform: translate(7px, 6px); background: #e5ae46; }
.brand-mark i:nth-child(3) { transform: translate(0, -6px); background: #c96d5f; }
.class-switcher { display: flex; align-items: center; gap: 7px; }
.class-switcher label { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.class-switcher select { max-width: 190px; height: 36px; padding: 0 32px 0 11px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: rgba(255,255,255,.65); font-weight: 600; outline: none; }
.class-switcher button, .clear-button { height: 36px; padding: 0 11px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,.5); cursor: pointer; font-size: 12px; font-weight: 700; }
.class-switcher button:hover, .clear-button:hover { background: white; }
.class-switcher button:disabled { opacity: .35; cursor: not-allowed; }
.class-switcher .danger-icon { width: 34px; padding: 0; color: #a4473d; font-size: 18px; }

.hero { padding: 72px 0 50px; display: grid; grid-template-columns: 1.5fr .7fr; gap: 60px; align-items: end; }
.eyebrow { margin: 0 0 15px; color: #9a6a32; font-size: 12px; letter-spacing: .18em; font-weight: 700; }
h1, h2 { font-family: "Fraunces", Georgia, serif; }
h1 { margin: 0; font-size: clamp(52px, 7vw, 88px); line-height: .92; letter-spacing: -.045em; font-weight: 600; }
h1 em { color: #bd5f54; font-weight: inherit; }
.hero-copy { margin: 0 0 7px; max-width: 360px; color: var(--muted); line-height: 1.7; font-size: 16px; }

.workspace { display: grid; grid-template-columns: 1.15fr .85fr; gap: 18px; }
.panel { background: rgba(255, 253, 248, .88); border: 1px solid rgba(32,50,45,.12); border-radius: 18px; padding: 28px; box-shadow: var(--shadow); }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.panel-heading > div:first-child { display: flex; align-items: center; gap: 13px; }
.step { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; border: 1px solid #c9c3b7; color: #8e6b40; font-size: 11px; font-weight: 700; }
h2 { margin: 0; font-size: 27px; line-height: 1.15; }
.hint { color: var(--muted); margin: 15px 0 22px 47px; font-size: 13px; }
.saved-state { color: #4e7567; font-size: 12px; display: flex; align-items: center; gap: 7px; transition: opacity .2s; }
.saved-state span { width: 7px; height: 7px; border-radius: 50%; background: #70a58f; box-shadow: 0 0 0 4px rgba(112,165,143,.13); }
.roster-actions { display: flex; align-items: center; gap: 12px; }
.clear-button { height: 31px; color: #98564c; background: transparent; }

.roster-intro { display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.column-visibility { display: flex; align-items: center; gap: 5px; }
.column-visibility > span { margin-right: 2px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
.column-visibility button { height: 28px; padding: 0 9px; border: 1px solid var(--line); border-radius: 999px; color: #8b7168; background: transparent; cursor: pointer; font-size: 10px; font-weight: 700; }
.column-visibility button.active { border-color: #92aa9f; color: #345f50; background: #e4eee9; }
.paste-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(135px, .62fr) minmax(190px, 1fr); gap: 12px; }
.paste-grid.hide-rooms { grid-template-columns: minmax(0, 1.2fr) minmax(190px, 1fr); }
.paste-grid.hide-emails { grid-template-columns: 2fr 1fr; }
.paste-grid.hide-rooms.hide-emails { grid-template-columns: 1fr; }
.paste-grid.hide-rooms .rooms-column, .paste-grid.hide-emails .emails-column { display: none; }
.paste-grid label { min-width: 0; }
.paste-grid label > span { display: block; margin-bottom: 8px; color: #53605b; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; }
textarea { width: 100%; height: 208px; resize: vertical; padding: 15px 16px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); line-height: 1.55; outline: none; }
.emails-column textarea { min-width: 0; overflow-x: auto; overflow-y: auto; white-space: pre; overflow-wrap: normal; word-break: normal; }
textarea:focus, .role-name:focus { border-color: #6f9a88; box-shadow: 0 0 0 3px rgba(83,128,108,.12); }
textarea::placeholder { color: #bab8b0; }
.input-status { min-height: 18px; margin-top: 10px; color: var(--muted); font-size: 12px; }
.input-status.error { color: #a4473d; }
.room-assignment-tools { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: rgba(236,232,222,.52); }
.auto-room-control { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.auto-room-control label { font-weight: 600; }
.auto-room-control input, .room-modal-toolbar input { width: 52px; height: 34px; padding: 0 5px; border: 1px solid var(--line); border-radius: 7px; background: white; text-align: center; outline: none; }
.auto-room-control button, .view-rooms-button, .room-modal-toolbar button, .room-modal-footer button { height: 34px; padding: 0 12px; border: 0; border-radius: 7px; background: var(--green); color: white; cursor: pointer; font-size: 12px; font-weight: 700; }
.view-rooms-button { border: 1px solid #c9c5bb; background: white; color: var(--ink); }
.view-rooms-button:hover { border-color: #88a395; }

.role-count-control { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; background: white; overflow: hidden; }
.role-count-control button { width: 34px; height: 32px; border: 0; background: transparent; cursor: pointer; font-size: 19px; }
.role-count-control button:hover { background: #f2efe7; }
.role-count-control output { width: 63px; text-align: center; font-size: 12px; font-weight: 700; }
.no-roles-toggle { display: flex; align-items: center; gap: 11px; margin: 18px 0 16px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #f0ece3; cursor: pointer; }
.no-roles-toggle > span { min-width: 0; flex: 1; }
.no-roles-toggle strong, .no-roles-toggle small { display: block; }
.no-roles-toggle strong { font-size: 13px; }
.no-roles-toggle small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.no-roles-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.no-roles-toggle i { position: relative; flex: 0 0 auto; width: 39px; height: 22px; border-radius: 999px; background: #bbb8af; transition: background .18s; }
.no-roles-toggle i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: white; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .18s; }
.no-roles-toggle input:checked + i { background: var(--green); }
.no-roles-toggle input:checked + i::after { transform: translateX(17px); }
.roles-panel.no-roles .role-configuration { display: none; }
.roles-panel.no-roles .role-count-control { visibility: hidden; }
.role-editor { display: grid; gap: 9px; }
.role-row { display: flex; align-items: center; min-height: 49px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 10px; background: white; }
.drag-handle { color: #aaa89f; font-size: 17px; margin-right: 8px; }
.color-picker-label { position: relative; width: 25px; height: 25px; cursor: pointer; flex: 0 0 auto; }
.color-input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.color-swatch { display: block; width: 25px; height: 25px; border-radius: 7px; background: var(--swatch); box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }
.role-name { min-width: 0; flex: 1; margin-left: 11px; padding: 5px 7px; border: 1px solid transparent; border-radius: 6px; outline: none; font-weight: 600; background: transparent; }
.only-one-label { display: flex; align-items: center; gap: 6px; margin-left: 8px; color: var(--muted); font-size: 11px; white-space: nowrap; cursor: pointer; }
.only-one-input { width: 16px; height: 16px; accent-color: var(--green); cursor: pointer; }
.saved-roles { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line); }
.saved-roles-heading h3 { margin: 0; font-family: "Fraunces", Georgia, serif; font-size: 17px; }
.saved-roles-heading p { margin: 3px 0 12px; color: var(--muted); font-size: 11px; }
.saved-role-add { display: flex; gap: 7px; }
.saved-role-add input { min-width: 0; flex: 1; height: 38px; padding: 0 11px; border: 1px solid var(--line); border-radius: 8px; outline: none; background: white; }
.saved-role-add input:focus { border-color: #6f9a88; box-shadow: 0 0 0 3px rgba(83,128,108,.12); }
.saved-role-add button { border: 0; border-radius: 8px; padding: 0 14px; background: #e8e3d9; cursor: pointer; font-size: 12px; font-weight: 700; }
.saved-role-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 11px; }
.saved-role-chip { display: inline-flex; align-items: center; overflow: hidden; border: 1px solid #d5d0c5; border-radius: 999px; background: #fff; font-size: 11px; }
.saved-role-chip .use-saved-role { border: 0; padding: 6px 4px 6px 10px; background: transparent; cursor: pointer; font-weight: 600; }
.saved-role-chip .remove-saved-role { border: 0; padding: 6px 8px 6px 4px; color: #9b756d; background: transparent; cursor: pointer; }
.saved-role-chip:hover { border-color: #8ea79d; }
.primary-button { display: flex; justify-content: space-between; align-items: center; width: 100%; margin-top: 21px; padding: 15px 19px; border: 0; border-radius: 10px; color: white; background: var(--green); cursor: pointer; font-weight: 700; box-shadow: 0 8px 18px rgba(46,102,83,.2); transition: transform .15s, background .15s; }
.primary-button:hover { background: #245544; transform: translateY(-1px); }
.primary-button:active { transform: translateY(0); }

.results { margin-top: 70px; scroll-margin-top: 20px; }
.results-heading { display: flex; justify-content: space-between; align-items: end; margin-bottom: 22px; }
.results-heading h2 { font-size: 38px; }
.result-actions { display: flex; gap: 8px; }
.text-button { border: 1px solid rgba(32,50,45,.17); border-radius: 9px; padding: 10px 13px; background: rgba(255,255,255,.42); cursor: pointer; font-size: 13px; font-weight: 600; }
.text-button:hover { background: white; }
.text-button:disabled { opacity: .55; cursor: wait; }
.copy-button { color: white; background: var(--green); border-color: var(--green); }
.copy-button:hover { background: #245544; }
.zoom-export-button { color: #315c4d; border-color: #9db3a9; background: #e5eee9; }
.zoom-export-button:hover { background: #d9e8e0; }
.copy-status { min-height: 20px; margin: -13px 0 10px; color: #4e7567; text-align: right; font-size: 12px; }
.role-lists { display: grid; grid-template-columns: repeat(var(--role-count, 3), minmax(220px, 1fr)); gap: 14px; align-items: start; }
.role-card { overflow: hidden; border: 1px solid color-mix(in srgb, var(--role-color) 32%, #999); border-radius: 16px; background: color-mix(in srgb, var(--role-color) 18%, white); box-shadow: 0 12px 30px rgba(43,54,48,.06); animation: rise .35s both; }
.role-card:nth-child(2) { animation-delay: .05s; }
.role-card:nth-child(3) { animation-delay: .1s; }
.role-card:nth-child(4) { animation-delay: .15s; }
.role-card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 19px 20px 15px; border-bottom: 1px solid color-mix(in srgb, var(--role-color) 24%, transparent); }
.role-card h3 { margin: 0; font-family: "Fraunces", Georgia, serif; font-size: 22px; }
.role-total { padding: 4px 8px; border-radius: 999px; background: rgba(255,255,255,.48); font-size: 11px; font-weight: 700; }
.student-list { margin: 0; padding: 8px 13px 14px; list-style: none; }
.student-list li { display: flex; align-items: center; gap: 11px; min-height: 44px; padding: 7px 6px; border-bottom: 1px solid rgba(32,50,45,.09); }
.student-list li:last-child { border-bottom: 0; }
.room-badge { display: grid; place-items: center; min-width: 29px; height: 29px; padding: 0 7px; border-radius: 8px; background: color-mix(in srgb, var(--role-color) 50%, white); font-size: 12px; font-weight: 800; }
.student-name { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.role-card.unassigned { --role-color: #b8b8b3; }
.empty-state { min-height: 210px; border: 1px dashed #c8c2b6; border-radius: 16px; display: grid; place-items: center; align-content: center; color: #9b998f; background: rgba(255,255,255,.2); }
.empty-state span { font-size: 28px; }
.empty-state p { margin: 8px 0 0; }

.room-modal { width: min(1050px, calc(100% - 30px)); max-height: 88vh; padding: 0; overflow: hidden; border: 1px solid rgba(32,50,45,.2); border-radius: 20px; color: var(--ink); background: var(--paper); box-shadow: 0 25px 80px rgba(20,35,29,.28); }
.room-modal::backdrop { background: rgba(25,37,32,.55); backdrop-filter: blur(4px); }
.room-modal-header { display: flex; justify-content: space-between; align-items: flex-start; padding: 27px 29px 20px; border-bottom: 1px solid var(--line); background: rgba(255,253,248,.82); }
.room-modal-header .eyebrow { margin-bottom: 8px; }
.room-modal-header h2 { font-size: 31px; }
.room-modal-header > div > p:last-child { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.modal-close { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; background: white; color: #8d665e; cursor: pointer; font-size: 23px; }
.room-modal-toolbar { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 13px 20px; border-bottom: 1px solid var(--line); color: var(--muted); background: #ebe7dd; font-size: 12px; }
.room-overview { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 13px; max-height: calc(88vh - 220px); padding: 20px 24px; overflow-y: auto; align-items: start; }
.room-overview-card { overflow: hidden; border: 1px solid #d5d0c5; border-radius: 13px; background: #fffdf9; }
.room-overview-header { display: flex; align-items: center; justify-content: space-between; padding: 13px 15px; border-bottom: 1px solid #e1ddd4; background: #e5efe9; }
.room-name-input { min-width: 0; flex: 1; margin: -4px 8px -4px -5px; padding: 4px 5px; border: 1px solid transparent; border-radius: 6px; color: var(--ink); background: transparent; font-family: "Fraunces", Georgia, serif; font-size: 18px; font-weight: 700; outline: none; }
.room-name-input:hover { border-color: #bdcec5; background: rgba(255,255,255,.45); }
.room-name-input:focus { border-color: #789b8b; background: white; box-shadow: 0 0 0 3px rgba(83,128,108,.12); }
.room-overview-header span { color: var(--muted); font-size: 11px; font-weight: 700; }
.room-students { margin: 0; padding: 7px 10px 10px; list-style: none; }
.room-student { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 5px 3px; border-bottom: 1px solid #ece8df; }
.room-student:last-child { border-bottom: 0; }
.room-student-name { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 600; }
.room-student select { width: 77px; height: 29px; border: 1px solid #d5d0c5; border-radius: 7px; color: var(--ink); background: white; font-size: 11px; }
.room-modal-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 13px 25px; border-top: 1px solid var(--line); background: rgba(255,253,248,.9); }
.room-modal-footer p { margin: 0; color: var(--muted); font-size: 12px; }
.room-modal-footer button { min-width: 82px; }

.duplicate-modal { width: min(650px, calc(100% - 28px)); max-height: 88vh; padding: 0; overflow: hidden; border: 1px solid rgba(32,50,45,.2); border-radius: 20px; color: var(--ink); background: var(--paper); box-shadow: 0 25px 80px rgba(20,35,29,.3); }
.duplicate-modal::backdrop { background: rgba(25,37,32,.58); backdrop-filter: blur(4px); }
.duplicate-modal-header { display: flex; gap: 16px; align-items: flex-start; padding: 26px 28px 21px; border-bottom: 1px solid var(--line); background: #fffaf3; }
.duplicate-alert-icon { display: grid; place-items: center; flex: 0 0 auto; width: 39px; height: 39px; border-radius: 50%; color: white; background: #c96d5f; font-family: "Fraunces", Georgia, serif; font-size: 22px; font-weight: 700; }
.duplicate-modal-header .eyebrow { margin: 1px 0 7px; color: #aa5047; }
.duplicate-modal-header h2 { font-size: 27px; }
.duplicate-modal-header p:last-child { margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.duplicate-name-groups { display: grid; gap: 15px; max-height: calc(88vh - 245px); padding: 20px 27px; overflow-y: auto; }
.duplicate-group { overflow: hidden; border: 1px solid #dad5ca; border-radius: 12px; background: white; }
.duplicate-group h3 { margin: 0; padding: 11px 14px; border-bottom: 1px solid #e3dfd6; background: #f0ece4; font-family: "Fraunces", Georgia, serif; font-size: 16px; }
.duplicate-entry { display: grid; grid-template-columns: minmax(125px, 1fr) minmax(130px, .8fr) minmax(145px, 1fr); gap: 10px; align-items: center; padding: 10px 13px; border-bottom: 1px solid #ece8df; }
.duplicate-entry:last-child { border-bottom: 0; }
.duplicate-context { min-width: 0; color: var(--muted); font-size: 11px; }
.duplicate-context strong { display: block; overflow: hidden; color: var(--ink); text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.duplicate-initials { height: 36px; padding: 0 10px; border: 1px solid #d5d0c5; border-radius: 8px; outline: none; }
.duplicate-initials:focus { border-color: #6f9a88; box-shadow: 0 0 0 3px rgba(83,128,108,.12); }
.duplicate-preview { overflow: hidden; color: #4e7567; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 600; }
.duplicate-error { min-height: 20px; padding: 0 27px 6px; color: #a4473d; font-size: 12px; }
.duplicate-modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 27px; border-top: 1px solid var(--line); background: rgba(255,253,248,.9); }
.duplicate-modal-footer button { height: 38px; padding: 0 15px; border-radius: 8px; cursor: pointer; font-size: 12px; font-weight: 700; }
.duplicate-later { border: 1px solid var(--line); color: var(--muted); background: white; }
.duplicate-apply { border: 0; color: white; background: var(--green); }

@keyframes rise { from { opacity: 0; transform: translateY(9px); } }

body.present-mode .topbar, body.present-mode .hero, body.present-mode .workspace, body.present-mode .results-heading .eyebrow, body.present-mode .result-actions { display: none; }
body.present-mode .app-shell { width: min(1500px, calc(100% - 50px)); padding-top: 35px; }
body.present-mode .results { margin-top: 0; }
body.present-mode .results-heading { margin-bottom: 25px; }
body.present-mode .results-heading h2 { font-size: 48px; }
body.present-mode .role-card h3 { font-size: 28px; }
body.present-mode .student-list li { min-height: 55px; }
body.present-mode .student-name { font-size: 17px; }
body.present-mode::after { content: "Press Esc to exit"; position: fixed; right: 16px; bottom: 12px; color: #7d817c; font-size: 11px; }

@media (max-width: 850px) {
  .hero { grid-template-columns: 1fr; gap: 25px; padding-top: 50px; }
  .workspace { grid-template-columns: 1fr; }
  .role-lists { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .room-overview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .app-shell { width: min(100% - 24px, 1180px); }
  .topbar { height: auto; min-height: 82px; padding: 13px 0; align-items: flex-start; }
  .class-switcher { justify-content: flex-end; flex-wrap: wrap; max-width: 230px; }
  .class-switcher label { display: none; }
  .class-switcher select { order: -1; width: 100%; max-width: none; }
  .hero { padding: 42px 0 36px; }
  h1 { font-size: 50px; }
  .panel { padding: 20px; }
  .panel-heading { align-items: flex-start; }
  .saved-state { display: none; }
  .hint { margin-left: 0; }
  .paste-grid { grid-template-columns: 1fr; }
  .roster-intro { align-items: flex-start; flex-direction: column; margin-bottom: 12px; }
  .roster-intro .hint { margin-bottom: 0; }
  .paste-grid.hide-rooms, .paste-grid.hide-emails, .paste-grid.hide-rooms.hide-emails { grid-template-columns: 1fr; }
  .room-assignment-tools { align-items: stretch; flex-direction: column; }
  .auto-room-control { flex-wrap: wrap; }
  .view-rooms-button { width: 100%; }
  .role-row { flex-wrap: wrap; }
  .only-one-label { width: 100%; margin: 3px 0 0 44px; }
  textarea { height: 150px; }
  .results-heading { align-items: flex-start; gap: 20px; }
  .result-actions { flex-wrap: wrap; justify-content: flex-end; }
  .result-actions .text-button:not(.copy-button) span { display: none; }
  .copy-status { margin-top: -7px; }
  .role-lists { grid-template-columns: 1fr; }
  .room-overview { grid-template-columns: 1fr; }
  .room-modal-toolbar { flex-wrap: wrap; }
  .duplicate-entry { grid-template-columns: 1fr 1fr; }
  .duplicate-preview { grid-column: 1 / -1; }
}

@media print {
  .topbar, .hero, .workspace, .result-actions, .results-heading .eyebrow { display: none !important; }
  body { background: white; }
  .app-shell { width: 100%; padding: 0; }
  .results { margin: 0; }
  .role-card { break-inside: avoid; box-shadow: none; }
}
