:root {
  --ink: #17211d;
  --muted: #68746e;
  --line: #dce4df;
  --paper: #f6f8f5;
  --surface: #ffffff;
  --green: #174f3c;
  --green-deep: #103d2e;
  --green-soft: #e5f0eb;
  --orange: #e77732;
  --male: #dceeff;
  --male-line: #85b7e6;
  --female: #ffe5ed;
  --female-line: #e99ab4;
  --aisle: #e5e7e6;
  --aisle-line: #aeb6b2;
  --danger: #a94848;
  --shadow: 0 18px 54px rgba(30, 56, 44, 0.1);
  --radius-lg: 24px;
  --radius-md: 14px;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--paper); }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 8%, rgba(231, 119, 50, 0.07), transparent 26rem),
    var(--paper);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 82px;
  padding: 14px clamp(18px, 3vw, 44px);
  border-bottom: 1px solid rgba(23, 79, 60, 0.12);
  background: rgba(246, 248, 245, 0.9);
  backdrop-filter: blur(18px);
}

.brand, .header-actions, .section-heading, .dialog-heading, .dialog-actions {
  display: flex;
  align-items: center;
}

.brand { gap: 14px; }
.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 15px 15px 15px 4px;
  color: white;
  background: var(--green);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.05em;
  box-shadow: 0 8px 22px rgba(23, 79, 60, 0.18);
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(20px, 2vw, 27px); letter-spacing: -0.025em; }
h2 { margin-bottom: 0; font-size: 18px; letter-spacing: -0.02em; }

.eyebrow, .step-label {
  margin-bottom: 4px;
  color: var(--orange);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.15em;
}

.header-actions { gap: 10px; }
.save-status { margin-right: 8px; color: var(--muted); font-size: 12px; }

.button {
  min-height: 40px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 11px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button-primary { color: white; background: var(--green); box-shadow: 0 7px 18px rgba(23, 79, 60, 0.16); }
.button-primary:hover { background: var(--green-deep); }
.button-secondary { border-color: var(--line); background: var(--surface); }
.button-secondary:hover { border-color: #b9c8c0; }
.button-quiet { color: #52625a; background: transparent; }
.button-danger { border-color: #efd0d0; color: var(--danger); background: #fff8f8; }

.app-shell {
  display: grid;
  grid-template-columns: minmax(290px, 350px) minmax(600px, 1fr);
  gap: clamp(18px, 2.4vw, 34px);
  max-width: 1680px;
  margin: 0 auto;
  padding: clamp(18px, 2.6vw, 38px);
}

.control-panel { display: flex; flex-direction: column; gap: 16px; }
.panel-section, .classroom-stage {
  border: 1px solid rgba(23, 79, 60, 0.1);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.panel-section { padding: 20px; border-radius: var(--radius-md); }
.section-heading { justify-content: space-between; margin-bottom: 18px; }
.section-number { color: #cbd4cf; font-family: Georgia, serif; font-size: 25px; font-style: italic; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
.field > span { color: #3c4842; font-size: 12px; font-weight: 750; }
.field small { color: var(--muted); font-size: 10px; line-height: 1.5; }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  color: var(--ink);
  background: #fbfcfb;
  transition: border 150ms ease, box-shadow 150ms ease;
}
.field textarea { min-height: 96px; resize: vertical; line-height: 1.55; }
.field .privacy-note { padding: 8px 9px; border-left: 3px solid #d29a43; color: #735b32; background: #fffaf0; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23, 79, 60, 0.1); }
.field input[type="range"] { min-height: 28px; padding: 0; border: 0; background: transparent; box-shadow: none; accent-color: var(--green); cursor: ew-resize; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

.student-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 4px;
}
.summary-chip { padding: 10px 8px; border-radius: 10px; text-align: center; background: var(--paper); }
.summary-chip strong { display: block; font-size: 19px; }
.summary-chip span { color: var(--muted); font-size: 10px; }

.legend { display: flex; flex-wrap: wrap; gap: 12px; margin: 3px 0 15px; color: var(--muted); font-size: 11px; }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend b { font-weight: 500; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; border: 1px solid var(--line); background: white; }
.legend-dot.male { border-color: var(--male-line); background: var(--male); }
.legend-dot.female { border-color: var(--female-line); background: var(--female); }
.legend-dot.aisle { border-color: var(--aisle-line); background: var(--aisle); }

.hint-box { margin-bottom: 0; padding: 11px 12px; border-left: 3px solid var(--orange); color: #59675f; background: #fff7f1; font-size: 11px; line-height: 1.6; }
.layout-rotation, .gender-patterns, .room-marker-settings { margin: 14px 0; padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: #f8faf9; }
.layout-rotation { display: flex; align-items: stretch; flex-direction: column; gap: 10px; }
.layout-rotation strong, .gender-pattern-heading strong, .room-marker-heading strong { display: block; color: #35423c; font-size: 12px; }
.layout-rotation small, .gender-pattern-heading small, .room-marker-heading small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; line-height: 1.45; }
.rotation-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.rotation-buttons .button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 7px 10px; font-size: 11px; }
.rotation-buttons .button span[aria-hidden] { color: var(--orange); font-size: 18px; line-height: 1; }
.gender-pattern-heading { margin-bottom: 11px; }
.gender-pattern-buttons { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.gender-pattern-button { display: flex; min-width: 0; min-height: 66px; align-items: center; justify-content: center; flex-direction: column; gap: 6px; padding: 7px 4px; border: 1px solid var(--line); border-radius: 10px; color: #46534c; background: white; cursor: pointer; font-size: 10px; font-weight: 800; transition: border 150ms ease, box-shadow 150ms ease, transform 150ms ease; }
.gender-pattern-button:hover { border-color: rgba(23,79,60,.35); box-shadow: 0 5px 13px rgba(23,79,60,.08); transform: translateY(-1px); }
.gender-pattern-button:focus-visible { outline: 3px solid rgba(23,79,60,.14); outline-offset: 1px; }
.gender-pattern-preview { display: grid; grid-template-columns: repeat(2, 15px); grid-template-rows: repeat(2, 10px); gap: 2px; padding: 3px; border-radius: 5px; background: #edf1ef; }
.gender-pattern-preview i { border-radius: 2px; background: var(--male); box-shadow: inset 0 0 0 1px var(--male-line); }
.pattern-rows i:nth-child(n+3), .pattern-columns i:nth-child(even), .pattern-checkerboard i:nth-child(2), .pattern-checkerboard i:nth-child(3) { background: var(--female); box-shadow: inset 0 0 0 1px var(--female-line); }
.pattern-columns i:nth-child(3) { background: var(--male); box-shadow: inset 0 0 0 1px var(--male-line); }
.room-marker-heading { margin-bottom: 11px; }
.room-marker-fields { display: grid; gap: 9px; }
.room-marker-control { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr); gap: 8px; padding-top: 9px; border-top: 1px dashed rgba(23,79,60,.12); }
.room-marker-control:first-child { padding-top: 0; border-top: 0; }
.room-marker-fields .field { min-width: 0; margin-bottom: 0; }
.room-marker-fields .field select { padding-right: 4px; font-size: 10px; }
.range-label { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.range-label output { flex-shrink: 0; color: var(--orange); font-size: 9px; font-weight: 850; font-variant-numeric: tabular-nums; }
.compact-section { margin-bottom: 8px; }
.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.classroom-stage {
  position: relative;
  min-width: 0;
  min-height: calc(100vh - 158px);
  padding: clamp(20px, 3vw, 42px);
  overflow: hidden;
  border-radius: var(--radius-lg);
}
.classroom-stage::after {
  position: absolute;
  right: -100px;
  bottom: -130px;
  width: 320px;
  height: 320px;
  border: 1px solid rgba(23, 79, 60, 0.055);
  border-radius: 50%;
  box-shadow: 0 0 0 55px rgba(23, 79, 60, 0.025), 0 0 0 110px rgba(23, 79, 60, 0.018);
  content: "";
  pointer-events: none;
}
.stage-heading { position: relative; z-index: 1; display: flex; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.stage-heading h2 { font-size: clamp(22px, 2.3vw, 32px); }
.stage-subtitle { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.status-key span { display: inline-flex; padding: 7px 11px; border-radius: 99px; color: var(--green); background: var(--green-soft); font-size: 11px; font-weight: 800; }
.status-key span.is-error { color: #994343; background: #fde9e9; }

.admin-mode-bar {
  position: relative;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1020px;
  margin: -4px auto 24px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #f7faf8;
}
.mode-tabs { display: flex; gap: 5px; flex-shrink: 0; }
.mode-tab {
  min-height: 36px;
  padding: 7px 12px;
  border: 0;
  border-radius: 9px;
  color: #69766f;
  background: transparent;
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
}
.mode-tab:hover:not(:disabled) { color: var(--green); background: #eaf2ee; }
.mode-tab.is-active { color: white; background: var(--green); box-shadow: 0 5px 14px rgba(23,79,60,.18); }
.mode-tab:disabled { cursor: not-allowed; opacity: .38; }
.mode-guidance { min-width: 0; text-align: right; }
.mode-guidance p { margin: 0; color: #59675f; font-size: 11px; line-height: 1.4; }
.mode-guidance span { display: block; margin-top: 2px; color: var(--orange); font-size: 10px; font-weight: 800; }

.room-layout {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) 78px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    ". top ."
    "left grid right"
    ". bottom .";
  gap: 9px;
  max-width: 1190px;
  margin: 0 auto;
}
.room-edge { display: grid; gap: 6px; pointer-events: none; }
.room-edge-top { grid-area: top; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.room-edge-bottom { grid-area: bottom; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.room-edge-left { grid-area: left; grid-template-rows: repeat(3, minmax(54px, 1fr)); }
.room-edge-right { grid-area: right; grid-template-rows: repeat(3, minmax(54px, 1fr)); }
.room-slot { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; min-width: 0; min-height: 38px; gap: 4px; }
.room-edge-left .room-slot, .room-edge-right .room-slot { flex-direction: column; }
.room-marker {
  --marker-offset: 0px;
  --marker-translate: translateX(var(--marker-offset));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  max-width: 100%;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid rgba(23,79,60,.18);
  border-radius: 9px;
  color: var(--green);
  background: #f3f8f5;
  box-shadow: 0 4px 12px rgba(29,48,39,.055);
  font-size: 10px;
  font-weight: 850;
  line-height: 1.15;
  text-align: center;
  white-space: nowrap;
  transform: var(--marker-translate);
}
.room-marker-icon { color: var(--orange); font-size: 15px; line-height: 1; }
.room-marker-board {
  width: var(--board-length, 172px);
  max-width: none;
  flex-shrink: 0;
  border-color: #123b2d;
  border-radius: 7px;
  color: #f7fbf8;
  background: linear-gradient(155deg, #245d48, #153e30);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.07), 0 5px 13px rgba(18,59,45,.16);
}
.room-marker-board .room-marker-icon { color: #f4d8a8; }
.room-marker-door { border-color: rgba(231,119,50,.22); color: #9b4e1e; background: #fff7f1; }
.room-marker-teacher { border-color: rgba(71,115,153,.22); color: #355d7d; background: #f2f7fb; }
.room-edge-left .room-marker, .room-edge-right .room-marker { --marker-translate: translateY(var(--marker-offset)); flex-direction: column; padding: 7px 5px; white-space: normal; }
.room-edge-left .room-marker-board, .room-edge-right .room-marker-board { width: calc(100% - 6px); height: var(--board-side-length, 139px); max-width: 72px; }
.grid-scroll { position: relative; z-index: 2; grid-area: grid; min-width: 0; overflow: auto; padding: 3px 3px 16px; }
.room-layout.is-rotating .seat-grid { animation: layoutRotatePulse 320ms cubic-bezier(.2,.8,.2,1); }
.seat-grid {
  --cols: 4;
  display: grid;
  grid-template-columns: 54px repeat(var(--cols), minmax(88px, 1fr));
  gap: 10px;
  min-width: calc(58px + var(--cols) * 98px);
  max-width: 1020px;
  margin: 0 auto;
}
.grid-corner { min-height: 32px; }
.axis-button {
  min-height: 32px;
  padding: 4px;
  border: 0;
  border-radius: 8px;
  color: #6f7d76;
  background: transparent;
  cursor: pointer;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.axis-button:hover { color: var(--green); background: var(--green-soft); }
.axis-button:disabled { cursor: default; opacity: .58; }
.axis-button:disabled:hover { color: #6f7d76; background: transparent; }

.seat {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 66px;
  padding: 8px;
  overflow: hidden;
  border: 1.5px solid var(--line);
  border-radius: 13px 13px 13px 5px;
  background: white;
  box-shadow: 0 5px 14px rgba(29, 48, 39, 0.055);
  cursor: pointer;
  transition: transform 140ms ease, border 140ms ease, box-shadow 140ms ease;
}
.seat:hover { z-index: 2; transform: translateY(-2px); box-shadow: 0 8px 20px rgba(29, 48, 39, 0.1); }
.seat[data-type="male"] { border-color: var(--male-line); background: var(--male); }
.seat[data-type="female"] { border-color: var(--female-line); background: var(--female); }
.seat[data-type="aisle"] { border-style: dashed; border-color: var(--aisle-line); color: #7d8581; background: repeating-linear-gradient(135deg, #eceeed, #eceeed 7px, #e4e7e5 7px, #e4e7e5 14px); box-shadow: none; }
.seat-main { display: flex; flex-direction: column; align-items: center; gap: 2px; pointer-events: none; }
.seat-main strong { font-size: 17px; }
.seat-main small { color: #67736d; font-size: 9px; font-weight: 700; }
.pin-button {
  position: absolute;
  top: 5px;
  right: 5px;
  display: grid;
  width: 23px;
  height: 23px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 7px;
  color: #78847e;
  background: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  font-size: 12px;
}
.pin-button:hover, .pin-button.is-pinned { color: white; background: var(--orange); }
.seat.prearrange-seat { border-style: dashed; }
.seat.prearrange-seat:hover { border-color: var(--orange); box-shadow: 0 8px 24px rgba(231,119,50,.13); }
.seat.prearrange-seat.is-pinned-seat { border-style: solid; border-color: var(--orange); box-shadow: inset 0 0 0 2px rgba(231,119,50,.08); }
.seat.admin-adjust-seat { border-color: #b8c8c0; background: linear-gradient(145deg, #fff, #f7faf8); }
.seat.admin-adjust-seat:hover { border-color: var(--green); }
.seat.admin-adjust-seat.is-swap-selected { border-color: var(--orange); background: #fff8f2; box-shadow: 0 0 0 4px rgba(231,119,50,.13), 0 8px 22px rgba(29,48,39,.09); transform: translateY(-2px); }
.admin-result { width: 100%; min-width: 0; }
.admin-result .student-number { color: var(--orange); font-size: 9px; font-weight: 850; }
.admin-result .student-name, .admin-result .student-name-only { max-width: 100%; overflow: hidden; font-size: 16px; text-overflow: ellipsis; white-space: nowrap; }
.admin-result > strong:not(.student-name):not(.student-name-only) { font-size: 19px; }
.admin-seat-meta { color: #7b8781 !important; font-size: 8px !important; }

.validation-panel { position: relative; z-index: 2; margin: 8px auto 0; max-width: 1015px; padding: 12px 14px; border: 1px solid #f1cccc; border-radius: 10px; color: #963f3f; background: #fff5f5; font-size: 12px; line-height: 1.6; }

.presentation-only { display: none; }
.presentation-mode .admin-only { display: none !important; }
.presentation-mode .presentation-only { display: flex; }
.presentation-mode {
  background:
    radial-gradient(circle at 12% 5%, rgba(231, 119, 50, 0.1), transparent 28rem),
    radial-gradient(circle at 90% 72%, rgba(23, 79, 60, 0.1), transparent 30rem),
    #f3f7f4;
}
.presentation-mode .app-header { border-bottom-color: rgba(23, 79, 60, 0.09); background: rgba(251, 253, 251, 0.88); box-shadow: 0 6px 30px rgba(29, 48, 39, 0.035); }
.presentation-mode .app-shell { display: block; max-width: 1500px; padding-top: 22px; }
.presentation-mode .classroom-stage {
  min-height: calc(100vh - 126px);
  border: 1px solid rgba(255, 255, 255, 0.8);
  background: linear-gradient(145deg, rgba(255,255,255,.96), rgba(249,252,250,.9));
  box-shadow: 0 24px 80px rgba(33, 68, 51, 0.09), inset 0 1px 0 #fff;
}
.presentation-mode .classroom-stage::before {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image: radial-gradient(rgba(23,79,60,.1) .7px, transparent .7px);
  background-size: 20px 20px;
  mask-image: linear-gradient(to bottom, black, transparent 72%);
  opacity: .18;
  content: "";
  pointer-events: none;
}
.presentation-mode .stage-heading { justify-content: center; text-align: center; animation: headingEnter 650ms cubic-bezier(.2,.8,.2,1) both; }
.presentation-mode .stage-heading h2 { background: linear-gradient(110deg, #163f31, #1f6b51 55%, #e77732); background-clip: text; color: transparent; }
.presentation-mode .stage-subtitle { justify-content: center; text-transform: uppercase; letter-spacing: .18em; }
.presentation-mode .seat-grid { grid-template-columns: repeat(var(--cols), minmax(100px, 1fr)); gap: 8px; min-width: calc(var(--cols) * 110px); max-width: 1120px; }
.presentation-mode .grid-corner, .presentation-mode .axis-button { display: none; }
.presentation-mode .seat {
  min-height: clamp(60px, 6.5vh, 78px);
  border: 1px solid #d7ddda;
  border-radius: 16px 16px 16px 6px;
  color: var(--ink);
  background: linear-gradient(145deg, rgba(255,255,255,.98), rgba(248,251,249,.95));
  box-shadow: 0 7px 22px rgba(29, 48, 39, 0.065), inset 0 1px 0 #fff;
  cursor: default;
}
.presentation-mode .seat:hover { transform: none; }
.presentation-mode .seat.has-profile { cursor: pointer; }
.presentation-mode .seat.has-profile:hover { border-color: rgba(231,119,50,.58); box-shadow: 0 10px 28px rgba(29,48,39,.11), 0 0 0 3px rgba(231,119,50,.08); transform: translateY(-2px); }
.profile-indicator { position: absolute; top: 6px; right: 7px; display: grid; width: 18px; height: 18px; place-items: center; border-radius: 50%; color: white; background: linear-gradient(145deg, var(--orange), #d45b1a); box-shadow: 0 4px 10px rgba(231,119,50,.24); font-size: 12px; font-weight: 900; }
.presentation-mode .seat.is-aisle { visibility: hidden; }
.presentation-mode .seat-main strong { font-size: clamp(22px, 2.8vw, 34px); font-variant-numeric: tabular-nums; }
.presentation-mode .student-result { width: 100%; min-width: 0; line-height: 1.12; }
.presentation-mode .student-result .student-number { display: block; margin-bottom: 2px; color: var(--orange); font-size: clamp(10px, 1vw, 13px); font-weight: 850; letter-spacing: .05em; }
.presentation-mode .student-result .student-name { max-width: 100%; overflow: hidden; font-size: clamp(16px, 2vw, 25px); text-overflow: ellipsis; white-space: nowrap; }
.presentation-mode .student-result .student-name-only { max-width: 100%; overflow: hidden; font-size: clamp(18px, 2.3vw, 29px); text-overflow: ellipsis; white-space: nowrap; }
.presentation-mode .student-result .student-name-fallback { color: #52625a; font-size: clamp(17px, 2vw, 25px); }
.presentation-mode .seat-main small, .presentation-mode .pin-button { display: none; }
.presentation-mode .seat::after {
  position: absolute;
  inset: -60% -90%;
  background: linear-gradient(105deg, transparent 40%, rgba(255,255,255,.95) 50%, transparent 60%);
  content: "";
  opacity: 0;
  pointer-events: none;
  transform: translateX(-45%) rotate(6deg);
}
.presentation-mode .seat.is-rolling { border-color: rgba(49, 126, 94, .32); animation: seatPulse 340ms ease-in-out infinite alternate; }
.presentation-mode .seat.is-rolling::after { opacity: .8; animation: seatShimmer 620ms linear infinite; }
.presentation-mode .seat.is-rolling strong { color: #1e664d; filter: blur(.25px); animation: numberFlip 150ms ease-in-out infinite alternate; }
.presentation-mode .seat.is-final { animation: seatLand 520ms var(--reveal-delay, 0ms) cubic-bezier(.16,1.35,.35,1) both; }
.presentation-mode .seat.is-final strong { animation: numberGlow 760ms var(--reveal-delay, 0ms) ease-out both; }

.presentation-decor { position: absolute; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.aurora { position: absolute; width: 300px; height: 300px; border-radius: 50%; filter: blur(22px); opacity: .14; }
.aurora-one { top: -190px; left: -90px; background: #ef9a5a; animation: auroraFloat 8s ease-in-out infinite alternate; }
.aurora-two { right: -100px; bottom: -190px; background: #4b9b7d; animation: auroraFloat 10s 1s ease-in-out infinite alternate-reverse; }
.spark { position: absolute; color: rgba(231,119,50,.4); animation: sparkFloat 4s ease-in-out infinite; }
.spark-one { top: 9%; left: 9%; font-size: 18px; }
.spark-two { top: 21%; right: 8%; font-size: 12px; animation-delay: -1.8s; }
.spark-three { bottom: 17%; left: 5%; font-size: 28px; color: rgba(23,79,60,.28); animation-delay: -3s; }
.presentation-mode .room-marker { animation: markerEnter 560ms 100ms ease-out both; }
.presentation-mode .room-marker:not(.room-marker-board) { border-color: rgba(23,79,60,.14); background: rgba(250,253,251,.88); }
.presentation-mode .room-marker-board { border-color: rgba(18,59,45,.45); background: linear-gradient(155deg, rgba(36,93,72,.96), rgba(21,62,48,.96)); }
.presentation-mode .room-marker-door { border-color: rgba(231,119,50,.2); background: rgba(255,248,242,.9); }
.presentation-mode .room-marker-teacher { border-color: rgba(71,115,153,.18); background: rgba(244,249,252,.9); }

.presentation-rotation { display: inline-flex; overflow: hidden; border: 1px solid #cfd8d3; border-radius: 9px; background: white; }
.presentation-rotate-button { min-width: 39px; padding: 7px 10px; border: 0; border-radius: 0; box-shadow: none; }
.presentation-rotate-button + .presentation-rotate-button { border-left: 1px solid #dbe2de; }
.presentation-rotate-button > span[aria-hidden] { color: var(--orange); font-size: 19px; line-height: 1; }
.presentation-rotate-button:disabled { cursor: wait; opacity: .45; }

.sound-button { gap: 7px; min-width: 104px; color: var(--green); }
.language-button { min-width: 52px; }
.sound-button > span:first-child { font-size: 16px; }
.sound-button.is-muted { color: var(--muted); opacity: .72; }

.draw-panel { position: relative; z-index: 3; flex-direction: column; align-items: center; gap: 12px; margin-top: 8px; }
.draw-panel p { margin-bottom: 0; color: var(--muted); font-size: 13px; }
.draw-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 12px 26px;
  border: 0;
  border-radius: 99px;
  color: white;
  background: linear-gradient(135deg, #1f6b51, #103d2e);
  box-shadow: 0 12px 30px rgba(23, 79, 60, 0.25), inset 0 1px 0 rgba(255,255,255,.2);
  cursor: pointer;
  font-weight: 850;
}
.draw-button:hover { background: var(--green-deep); transform: translateY(-1px); }
.draw-button:disabled { cursor: wait; opacity: 0.7; }
.draw-icon { font-size: 21px; }
.draw-button.is-drawing .draw-icon { animation: spin 620ms linear infinite; }
.drawing-mode .draw-button { box-shadow: 0 0 0 8px rgba(23,79,60,.08), 0 14px 34px rgba(23,79,60,.28); }

.draw-countdown {
  position: absolute;
  inset: 0;
  z-index: 30;
  align-items: center;
  justify-content: center;
  border-radius: inherit;
  background: radial-gradient(circle, rgba(255,255,255,.88), rgba(243,248,245,.68) 45%, rgba(23,79,60,.12));
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  backdrop-filter: blur(5px);
  transition: opacity 180ms ease, visibility 180ms ease;
}
.draw-countdown.is-active { opacity: 1; visibility: visible; }
.draw-countdown span {
  display: grid;
  width: 150px;
  height: 150px;
  place-items: center;
  border: 1px solid rgba(255,255,255,.8);
  border-radius: 50%;
  color: white;
  background: linear-gradient(145deg, #26785b, #103d2e);
  box-shadow: 0 24px 70px rgba(23,79,60,.32), 0 0 0 18px rgba(255,255,255,.45);
  font-size: clamp(42px, 7vw, 78px);
  font-weight: 900;
  letter-spacing: -.05em;
}
.draw-countdown span.is-pop { animation: countdownPop 390ms cubic-bezier(.16,1.4,.3,1) both; }

.celebration-layer { position: absolute; inset: 0; z-index: 25; overflow: hidden; pointer-events: none; }
.celebration-layer i { position: absolute; top: -20px; left: var(--left); width: 8px; height: 16px; border-radius: 3px; background: var(--color); opacity: 0; }
.celebration-layer.is-active i { animation: confettiFall var(--duration) var(--delay) cubic-bezier(.18,.72,.45,1) both; }

.student-profile-overlay[hidden] { display: none !important; }
.student-profile-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at center, rgba(28,73,55,.42), rgba(8,23,17,.78));
  opacity: 0;
  visibility: hidden;
  perspective: 1400px;
  backdrop-filter: blur(10px);
  transition: opacity 260ms ease, visibility 260ms ease;
}
.student-profile-overlay.is-open { opacity: 1; visibility: visible; }
.student-profile-card { width: min(660px, calc(100vw - 42px)); height: min(540px, calc(100vh - 100px)); min-height: 400px; }
.student-profile-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform 900ms cubic-bezier(.18,.88,.24,1.08); }
.student-profile-card.is-flipped .student-profile-inner { transform: rotateY(180deg); }
.profile-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 34px 34px 34px 10px;
  backface-visibility: hidden;
  box-shadow: 0 36px 100px rgba(3,17,11,.42), inset 0 1px 0 rgba(255,255,255,.7);
}
.profile-front { display: flex; align-items: center; justify-content: center; flex-direction: column; color: white; background: radial-gradient(circle at 20% 15%, rgba(255,255,255,.22), transparent 22rem), linear-gradient(145deg, #2b7a5d, #103d2e 65%, #0c2c21); }
.profile-back { pointer-events: none; }
.student-profile-card.is-flipped .profile-front { pointer-events: none; }
.student-profile-card.is-flipped .profile-back { pointer-events: auto; }
.profile-front::after { position: absolute; inset: 0; background-image: radial-gradient(rgba(255,255,255,.3) .8px, transparent .8px); background-size: 22px 22px; content: ""; opacity: .22; }
.profile-front p, .profile-front h2, .profile-front small { position: relative; z-index: 2; }
.profile-front p { margin-bottom: 8px; color: #f7cba9; font-size: 15px; font-weight: 850; letter-spacing: .14em; }
.profile-front h2 { margin-bottom: 14px; font-size: clamp(38px, 7vw, 72px); letter-spacing: -.04em; }
.profile-front small { color: rgba(255,255,255,.72); letter-spacing: .08em; }
.profile-orbit { position: absolute; width: 330px; height: 330px; border: 1px solid rgba(255,255,255,.18); border-radius: 50%; box-shadow: 0 0 0 42px rgba(255,255,255,.04), 0 0 0 88px rgba(255,255,255,.025); animation: profileOrbit 10s linear infinite; }
.profile-back { padding: clamp(26px, 5vw, 52px); color: var(--ink); background: radial-gradient(circle at 100% 0, rgba(231,119,50,.12), transparent 20rem), linear-gradient(145deg, #fff, #f3f8f5); transform: rotateY(180deg); }
.profile-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding-bottom: 20px; border-bottom: 1px solid #dbe5df; }
.profile-heading p { margin-bottom: 4px; color: var(--orange); font-size: 12px; font-weight: 850; letter-spacing: .1em; }
.profile-heading h2 { font-size: clamp(29px, 5vw, 46px); }
.profile-badge { padding: 7px 10px; border-radius: 99px; color: var(--green); background: var(--green-soft); font-size: 9px; font-weight: 900; letter-spacing: .12em; }
.profile-fields { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 11px; max-height: calc(100% - 125px); padding: 22px 2px 8px; overflow: auto; }
.profile-field { min-width: 0; padding: 13px 14px; border: 1px solid #dfe8e3; border-radius: 13px; background: rgba(255,255,255,.72); }
.profile-field > span { display: block; margin-bottom: 5px; color: #738078; font-size: 10px; font-weight: 800; letter-spacing: .05em; }
.profile-value-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.profile-value-row strong { min-width: 0; overflow-wrap: anywhere; font-size: clamp(15px, 2vw, 19px); }
.sensitive-toggle { flex-shrink: 0; padding: 4px 7px; border: 0; border-radius: 7px; color: var(--green); background: var(--green-soft); cursor: pointer; font-size: 9px; font-weight: 850; }
.profile-hint { position: absolute; right: 34px; bottom: 18px; margin: 0; color: #7a8780; font-size: 10px; }
.profile-empty { grid-column: 1 / -1; padding: 34px; color: #728077; text-align: center; }
.profile-close { position: fixed; z-index: 205; top: 24px; right: 28px; width: 46px; height: 46px; border: 1px solid rgba(255,255,255,.25); border-radius: 50%; color: white; background: rgba(12,35,25,.45); cursor: pointer; font-size: 29px; backdrop-filter: blur(8px); }
.profile-close:hover { background: rgba(12,35,25,.7); transform: rotate(5deg); }

.pin-dialog { width: min(430px, calc(100vw - 34px)); padding: 0; border: 0; border-radius: 18px; box-shadow: 0 30px 90px rgba(15, 35, 26, 0.25); }
.pin-dialog::backdrop { background: rgba(16, 34, 26, 0.42); backdrop-filter: blur(3px); }
.pin-dialog form { padding: 24px; }
.dialog-heading { justify-content: space-between; margin-bottom: 22px; }
.icon-button { width: 34px; height: 34px; border: 0; border-radius: 9px; color: var(--muted); background: var(--paper); cursor: pointer; font-size: 24px; }
.dialog-actions { justify-content: flex-end; gap: 9px; margin-top: 8px; }

.toast {
  position: fixed;
  z-index: 100;
  right: 24px;
  bottom: 24px;
  max-width: min(380px, calc(100vw - 48px));
  padding: 12px 16px;
  border-radius: 10px;
  color: white;
  background: #25342d;
  box-shadow: 0 14px 34px rgba(20, 38, 29, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms ease;
  font-size: 12px;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.is-error { background: #8f3e3e; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes seatPulse { from { transform: scale(0.985); } to { transform: scale(1.015); box-shadow: 0 10px 30px rgba(23, 79, 60, 0.13); } }
@keyframes seatLand { 0% { transform: perspective(500px) rotateX(18deg) scale(.86); opacity: .25; } 70% { transform: perspective(500px) rotateX(-2deg) scale(1.035); } 100% { transform: none; opacity: 1; } }
@keyframes seatShimmer { to { transform: translateX(45%) rotate(6deg); } }
@keyframes numberFlip { from { transform: translateY(-2px) scale(.97); opacity: .65; } to { transform: translateY(2px) scale(1.03); opacity: 1; } }
@keyframes numberGlow { 0% { color: var(--orange); text-shadow: 0 0 22px rgba(231,119,50,.75); } 100% { color: var(--ink); text-shadow: none; } }
@keyframes headingEnter { from { opacity: 0; transform: translateY(-16px); } to { opacity: 1; transform: none; } }
@keyframes markerEnter { from { opacity: 0; transform: var(--marker-translate) scale(.82); } to { opacity: 1; transform: var(--marker-translate) scale(1); } }
@keyframes layoutRotatePulse { 0% { opacity: .35; transform: scale(.96); } 100% { opacity: 1; transform: none; } }
@keyframes auroraFloat { to { transform: translate(38px, 24px) scale(1.12); } }
@keyframes sparkFloat { 0%,100% { transform: translateY(0) rotate(0); opacity: .25; } 50% { transform: translateY(-12px) rotate(45deg); opacity: .7; } }
@keyframes countdownPop { 0% { transform: scale(.55) rotate(-8deg); opacity: 0; } 65% { transform: scale(1.08) rotate(2deg); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
@keyframes confettiFall { 0% { opacity: 0; transform: translate3d(0,-20px,0) rotate(0); } 12% { opacity: 1; } 100% { opacity: 0; transform: translate3d(var(--drift), 92vh, 0) rotate(620deg); } }
@keyframes profileOrbit { to { transform: rotate(360deg); } }

@media (min-width: 981px) {
  body:not(.presentation-mode) { height: 100%; overflow: hidden; }
  body:not(.presentation-mode) .app-shell {
    align-items: stretch;
    height: calc(100vh - 82px);
    height: calc(100dvh - 82px);
    overflow: hidden;
  }
  body:not(.presentation-mode) .control-panel,
  body:not(.presentation-mode) .classroom-stage {
    min-height: 0;
    max-height: 100%;
    overscroll-behavior: contain;
    scrollbar-color: rgba(23, 79, 60, .35) transparent;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
  }
  body:not(.presentation-mode) .control-panel {
    padding: 2px 8px 20px 2px;
    overflow-x: hidden;
    overflow-y: auto;
  }
  body:not(.presentation-mode) .classroom-stage { height: 100%; overflow: auto; }
  body:not(.presentation-mode) .control-panel::-webkit-scrollbar,
  body:not(.presentation-mode) .classroom-stage::-webkit-scrollbar { width: 10px; height: 10px; }
  body:not(.presentation-mode) .control-panel::-webkit-scrollbar-thumb,
  body:not(.presentation-mode) .classroom-stage::-webkit-scrollbar-thumb {
    border: 3px solid transparent;
    border-radius: 99px;
    background: rgba(23, 79, 60, .35);
    background-clip: padding-box;
  }
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .classroom-stage { min-height: auto; }
  .control-panel { display: grid; grid-template-columns: 1fr 1fr; }
  .compact-section { grid-column: 1 / -1; }
}

@media (max-width: 680px) {
  .app-header { align-items: flex-start; gap: 12px; }
  .header-actions { flex-wrap: wrap; justify-content: flex-end; }
  .save-status, #fullscreenButton { display: none; }
  .control-panel { display: flex; }
  .app-shell { padding: 12px; }
  .classroom-stage { padding: 18px 12px; border-radius: 16px; }
  .seat-grid { gap: 7px; }
  .presentation-mode .app-header { min-height: 70px; }
  .presentation-mode .app-shell { padding: 8px; }
  .presentation-mode .classroom-stage { padding: 14px 6px; }
  .admin-mode-bar { align-items: stretch; flex-direction: column; }
  .mode-tabs { display: grid; grid-template-columns: repeat(3, 1fr); }
  .mode-guidance { text-align: left; }
  .room-marker-control { grid-template-columns: 1fr; }
  .room-layout { grid-template-columns: 50px minmax(0, 1fr) 50px; gap: 5px; }
  .room-marker { gap: 3px; padding: 5px 6px; font-size: 8px; }
  .room-edge-top .room-marker-board, .room-edge-bottom .room-marker-board { width: var(--board-mobile-length, 73px); }
  .room-marker-icon { font-size: 12px; }
  .profile-fields { grid-template-columns: 1fr; }
  .student-profile-card { min-height: 480px; }
  .profile-back { padding: 26px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
