:root {
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #20243b;
  background: #f5f6fb;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.brand-mark { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 11px; color: #fff; background: #6852e9; font-size: 26px; font-weight: 800; line-height: 1; vertical-align: middle; }
.eyebrow { color: #7763e6; font-size: 11px; font-weight: 800; letter-spacing: .17em; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 9px; border: 0; border-radius: 12px; padding: 12px 19px; font-weight: 700; transition: transform .15s, background .15s, box-shadow .15s; }
.button:not(:disabled):hover { transform: translateY(-1px); }
.button svg { width: 19px; height: 19px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.button-primary { background: #6951eb; color: #fff; box-shadow: 0 8px 20px #6951eb30; }
.button-primary:not(:disabled):hover { background: #5840dc; box-shadow: 0 10px 24px #6951eb42; }
.button-primary svg path { fill: currentColor; stroke: none; }
.button-danger { background: #fff1f2; color: #da4458; border: 1px solid #ffd9df; }
.button-danger:not(:disabled):hover { background: #ffe3e8; }
.button-danger svg rect { fill: currentColor; stroke: none; }
.button-secondary { background: #f1efff; color: #624bdd; border: 1px solid #ded9ff; }
.button-secondary:not(:disabled):hover { background: #e9e5ff; }

/* Login */
.login-view { min-height: 100vh; display: grid; grid-template-columns: minmax(440px, 48%) 1fr; background: #fff; }
.login-art { position: relative; overflow: hidden; min-height: 700px; background: linear-gradient(150deg, #7661e9 0%, #6755dc 47%, #493ba9 100%); color: #fff; }
.art-orb { position: absolute; border-radius: 50%; pointer-events: none; }
.art-orb-one { width: 620px; height: 620px; right: -260px; top: -230px; background: radial-gradient(circle at 35% 65%, #ffffff23, #ffffff00 67%); border: 1px solid #ffffff16; }
.art-orb-two { width: 560px; height: 560px; left: -300px; bottom: -320px; border: 110px solid #ffffff0c; }
.art-lines { position: absolute; inset: 0; opacity: .12; background-image: linear-gradient(#fff 1px, transparent 1px), linear-gradient(90deg, #fff 1px, transparent 1px); background-size: 48px 48px; mask-image: linear-gradient(transparent, #000 35%, transparent); }
.art-content { position: relative; z-index: 1; max-width: 540px; margin: 0 auto; padding: 42px 46px 96px; }
.art-logo { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 800; letter-spacing: .02em; }
.art-logo .brand-mark { background: #ffffff2e; }
.art-illustration { position: relative; width: 100%; max-width: 420px; height: 322px; margin: 73px auto 24px; }
.art-video { position: absolute; width: 345px; height: 244px; left: 21px; top: 18px; overflow: hidden; border-radius: 19px; background: #f8f7ff; transform: rotate(-5deg); box-shadow: 0 24px 60px #29217165, inset 0 0 0 1px #ffffff95; }
.art-video-top { height: 38px; display: flex; align-items: center; gap: 6px; padding-left: 15px; background: #f2efff; }
.art-video-top span { width: 7px; height: 7px; border-radius: 50%; background: #cfc9f8; }
.art-video-top span:first-child { background: #ffb5b9; }
.art-video-top span:nth-child(2) { background: #ffdc9d; }
.art-video-top span:nth-child(3) { background: #aaddc8; }
.art-portrait { position: relative; width: 100%; height: 163px; overflow: hidden; background: linear-gradient(135deg, #d9d0ff, #f4e1ed); }
.portrait-head { position: absolute; width: 73px; height: 81px; left: 137px; top: 30px; border-radius: 45% 45% 48% 48%; background: #e5aa8c; box-shadow: 0 -13px 0 5px #392963; }
.portrait-body { position: absolute; width: 169px; height: 106px; left: 89px; top: 115px; border-radius: 80px 80px 0 0; background: #6251bd; }
.art-video-bottom { height: 43px; display: flex; align-items: center; justify-content: center; gap: 11px; }
.art-video-bottom i { display: block; width: 24px; height: 24px; border-radius: 50%; background: #e8e5ff; }
.art-video-bottom b { display: block; width: 31px; height: 25px; border-radius: 8px; background: #ff7885; }
.art-chat { position: absolute; right: 1px; top: 130px; width: 105px; padding: 15px 13px; border-radius: 15px; background: #fff; box-shadow: 0 15px 35px #342a8255; transform: rotate(8deg); }
.art-chat span { display: block; height: 7px; margin: 8px 0; border-radius: 5px; background: #dbd6fa; }
.art-chat span:nth-child(2) { width: 72%; background: #a69af2; }
.art-chat span:nth-child(3) { width: 51%; }
.art-live { position: absolute; left: 8px; top: 3px; display: flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 8px; background: #fff; color: #e05269; font-size: 12px; font-weight: 800; box-shadow: 0 8px 18px #28217033; transform: rotate(5deg); }
.art-live i, .live-badge i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.art-content h1 { margin: 12px 0 14px; font-size: clamp(38px, 4vw, 54px); line-height: 1.18; letter-spacing: -.05em; }
.art-content p { max-width: 350px; color: #e6e2ff; font-size: 14px; line-height: 1.9; }
.art-footer { position: absolute; left: 46px; bottom: 28px; color: #d8d1ff; font-size: 10px; font-weight: 700; letter-spacing: .2em; }
.login-main { display: flex; flex-direction: column; justify-content: center; align-items: center; min-height: 700px; padding: 44px; }
.login-card { width: min(100%, 410px); }
.login-card h2 { margin: 13px 0 10px; font-size: 36px; letter-spacing: -.045em; }
.login-lead { margin: 0 0 38px; color: #85889b; font-size: 14px; line-height: 1.8; }
.login-card form { display: flex; flex-direction: column; }
.login-card label { margin: 0 0 8px; color: #41435a; font-size: 13px; font-weight: 750; }
.login-card input { height: 51px; margin-bottom: 21px; padding: 0 16px; border: 1px solid #e1e3ec; border-radius: 11px; outline: none; color: #252844; background: #fff; transition: border-color .15s, box-shadow .15s; }
.login-card input:focus, .chat-form input:focus { border-color: #8674ed; box-shadow: 0 0 0 3px #7563ea1e; }
.login-card input::placeholder { color: #b3b5c1; }
.form-error { margin: -5px 0 17px; color: #ce3f52; font-size: 13px; }
.login-submit { height: 53px; justify-content: space-between; margin-top: 5px; padding: 0 19px; }
.login-submit span { font-size: 22px; line-height: 1; }
.login-note { display: flex; align-items: center; gap: 7px; margin-top: 29px; color: #9b9dab; font-size: 11px; }
.note-lock { color: #8c7aea; font-size: 23px; line-height: 0; }
.login-copyright { width: min(100%, 410px); margin: 100px 0 0; color: #b4b6c1; font-size: 11px; }
.mobile-brand { display: none; }

/* Classroom */
.classroom-view { min-height: 100vh; background: #f6f7fb; }
.site-header { background: #fff; border-bottom: 1px solid #edeef3; }
.header-inner { max-width: 1440px; min-height: 72px; margin: auto; padding: 0 42px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.brand { display: flex; align-items: center; gap: 9px; white-space: nowrap; color: #272842; font-size: 17px; font-weight: 800; }
.brand small { align-self: flex-end; margin: 0 0 3px 6px; color: #b5b1cb; font-size: 9px; letter-spacing: .13em; }
.header-right { display: flex; align-items: center; gap: 20px; }
.connection-badge { display: inline-flex; align-items: center; gap: 7px; color: #9397a7; font-size: 11px; white-space: nowrap; }
.connection-badge i { width: 7px; height: 7px; border-radius: 50%; background: #c9cbd3; }
.connection-badge.connected { color: #349577; }
.connection-badge.connected i { background: #37bc89; box-shadow: 0 0 0 4px #37bc8920; }
.user-chip { display: flex; align-items: center; gap: 9px; padding-left: 19px; border-left: 1px solid #ebecf2; }
.avatar { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 12px; color: #fff; background: linear-gradient(145deg, #9d8cff, #6852e9); font-size: 13px; font-weight: 800; }
.user-meta { display: flex; flex-direction: column; gap: 1px; }
.user-meta strong { max-width: 120px; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.user-meta small { color: #989aab; font-size: 10px; }
.edit-nickname-button { display: grid; place-items: center; width: 30px; height: 30px; margin-left: -12px; border: 0; border-radius: 8px; background: transparent; color: #9b91d7; }
.edit-nickname-button:hover { background: #f2f0ff; color: #6651df; }
.edit-nickname-button svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.text-button { border: 0; background: transparent; color: #8c8f9e; font-size: 12px; white-space: nowrap; }
.text-button:hover { color: #6651df; }
.classroom-main { max-width: 1440px; margin: auto; padding: 41px 42px 30px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 30px; }
.page-heading h1 { margin: 9px 0 5px; font-size: 31px; letter-spacing: -.045em; }
.title-dot { color: #7b63e9; }
.page-heading p { margin: 0; color: #9699a8; font-size: 12px; }
.heading-facts { display: flex; align-items: center; gap: 11px; padding-bottom: 2px; }
.live-badge, .viewer-badge { display: inline-flex; align-items: center; gap: 7px; padding: 9px 12px; border-radius: 10px; background: #fff; border: 1px solid #ebedf3; color: #9a9caa; font-size: 11px; font-weight: 700; white-space: nowrap; }
.live-badge.live { color: #e14c61; background: #fff3f5; border-color: #ffe4e9; }
.live-badge.live i { animation: live-pulse 1.6s infinite; }
.viewer-badge svg { width: 16px; height: 16px; fill: none; stroke: #9999af; stroke-width: 1.8; }
@keyframes live-pulse { 50% { opacity: .4; } }
.classroom-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 360px); gap: 22px; align-items: stretch; }
.stage-card, .chat-card { overflow: hidden; border-radius: 19px; background: #fff; border: 1px solid #eceef4; box-shadow: 0 9px 30px #20243b08; }
.stage-top, .chat-heading { display: flex; justify-content: space-between; align-items: center; padding: 21px 23px 18px; }
.stage-kicker { color: #a39bbf; font-size: 9px; font-weight: 800; letter-spacing: .17em; }
.stage-top h2, .chat-heading h2 { margin: 6px 0 0; color: #292b41; font-size: 16px; }
.stage-state { color: #9295a5; font-size: 11px; }
.video-stage { position: relative; width: calc(100% - 46px); aspect-ratio: 16 / 9; margin: 0 23px; overflow: hidden; border-radius: 14px; background: #1c1d31; }
.video-stage video, .video-stage canvas { width: 100%; height: 100%; display: block; object-fit: contain; background: #161722; }
.stage-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 18px; text-align: center; background: radial-gradient(circle at 50% 40%, #393853, #1c1d31 65%); color: #fff; }
.stage-empty-icon { display: grid; place-items: center; width: 75px; height: 75px; margin-bottom: 15px; border-radius: 21px; color: #b2a9f7; background: #ffffff10; border: 1px solid #ffffff15; }
.stage-empty-icon svg { width: 37px; height: 37px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.stage-empty h3 { margin: 0 0 7px; font-size: 17px; }
.stage-empty p { margin: 0; color: #a8a9bc; font-size: 12px; }
.stage-watermark { position: absolute; right: 15px; bottom: 14px; display: flex; align-items: center; gap: 5px; color: #ffffffa6; font-size: 10px; font-weight: 700; pointer-events: none; }
.stage-watermark .brand-mark { width: 17px; height: 17px; border-radius: 5px; font-size: 13px; opacity: .75; }
.stage-bottom { display: flex; justify-content: space-between; align-items: center; gap: 14px; min-height: 102px; padding: 19px 23px; }
.stage-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.stage-info div { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stage-info strong { font-size: 12px; }
.stage-info small { color: #9c9fac; font-size: 11px; line-height: 1.4; }
.info-icon { display: grid; flex: none; place-items: center; width: 33px; height: 33px; border-radius: 11px; color: #765eee; background: #f1efff; font-size: 17px; }
.control-actions { display: flex; flex-wrap: wrap; gap: 8px; white-space: nowrap; }
.stage-bottom { flex-wrap: wrap; }
.media-toggle.is-on .icon-off, .media-toggle.is-off .icon-on { display: none; }
.media-toggle .icon-off { stroke-width: 2.5; }
.control-actions .mic-button.is-on { background: #e4f7eb; border-color: #a5dfbb; color: #147947; }
.control-actions .mic-button.is-off { background: #fff0f1; border-color: #f5c2cb; color: #b43851; }
.control-actions .sound-button.is-on { background: #e8f1ff; border-color: #b6d0fa; color: #285eae; }
.control-actions .sound-button.is-off { background: #f0f1f5; border-color: #d5d8e2; color: #5d6474; }
.control-actions .sound-button.sound-needs-action { background: #fff0d5; border-color: #f3cb7e; color: #8c4f00; box-shadow: 0 0 0 2px #ffe5b47a; }
.chat-card { display: flex; flex-direction: column; min-height: 0; }
.chat-heading { border-bottom: 1px solid #f0f1f5; }
.chat-heading-actions { display: flex; align-items: center; gap: 8px; }
.chat-count { color: #a0a2ae; font-size: 11px; white-space: nowrap; }
.member-list-toggle { display: none; border: 0; border-radius: 7px; padding: 4px 7px; background: #f1efff; color: #624bdd; font-size: 10px; font-weight: 700; white-space: nowrap; }
.members-section { padding: 12px 18px 11px; border-bottom: 1px solid #f0f1f5; }
.members-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 9px; }
.members-heading strong { color: #74758a; font-size: 11px; }
.members-heading span { color: #a5a6b4; font-size: 10px; }
.member-list { display: flex; align-content: flex-start; flex-wrap: wrap; gap: 6px; max-height: 80px; min-height: 27px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #d9d9e9 transparent; }
.member-pill { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; min-height: 26px; padding: 3px 8px 3px 4px; border: 1px solid #ececf5; border-radius: 8px; background: #f8f8fc; color: #646678; font-size: 10px; }
.member-pill.mine { border-color: #e5dfff; background: #f6f3ff; color: #604bd4; }
.member-pill.teacher { border-color: #e7dcff; }
.member-avatar { display: grid; flex: none; place-items: center; width: 18px; height: 18px; border-radius: 6px; background: #e9e7f7; color: #7561d5; font-size: 9px; font-weight: 800; }
.member-pill.teacher .member-avatar { background: #e9e2ff; color: #624adf; }
.member-pill.mine .member-avatar { background: #ded7ff; }
.member-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-teacher-tag { color: #8877d9; font-size: 9px; }
.member-mic-tag { color: #c54254; font-size: 9px; font-weight: 800; white-space: nowrap; }
.member-pill.speaking { border-color: #ffd5dc; background: #fff3f5; }
.members-empty { color: #b1b2bf; font-size: 10px; }
.chat-messages { flex: 1; height: 320px; min-height: 320px; overflow-y: auto; overscroll-behavior: contain; padding: 17px 20px 8px; scrollbar-width: thin; scrollbar-color: #d9d9e9 transparent; }
.chat-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: #a2a3b2; }
.chat-empty span { display: grid; place-items: center; width: 43px; height: 43px; margin-bottom: 9px; border-radius: 14px; color: #8573e5; background: #f3f0ff; font-size: 21px; }
.chat-empty strong { color: #676a7c; font-size: 12px; }
.chat-empty p { margin: 5px 0; font-size: 11px; }
.message { display: flex; align-items: flex-start; gap: 9px; min-width: 0; margin: 0 0 17px; }
.message-avatar { display: grid; flex: none; place-items: center; width: 30px; height: 30px; border-radius: 10px; color: #7059e6; background: #eeebff; font-size: 11px; font-weight: 800; }
.message.mine .message-avatar { color: #2c9e80; background: #e5f7f0; }
.message-body { flex: 1 1 0%; min-width: 0; }
.message-meta { display: flex; align-items: baseline; gap: 7px; margin: 1px 0 6px; }
.message-meta strong { min-width: 0; max-width: 145px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #303149; font-size: 11px; }
.message-meta time { flex: none; color: #6f7180; font-size: 10px; }
.message-text { display: inline-block; max-width: 100%; padding: 9px 11px; border-radius: 2px 10px 10px 10px; background: #f5f5fa; color: #33374a; font-size: 11px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.mine .message-text { background: #f0edff; }
.chat-form { display: flex; align-items: center; gap: 8px; margin: 0 18px; padding: 5px 5px 5px 12px; border: 1px solid #e9eaf1; border-radius: 11px; background: #fff; }
.chat-form:focus-within { border-color: #aaa0f1; }
.chat-form input { flex: 1; min-width: 0; height: 31px; padding: 0; outline: 0; border: 0; color: #343648; font-size: 11px; }
.chat-form input:focus { box-shadow: none; }
.chat-form input::placeholder { color: #aaacb8; }
.chat-form button { display: grid; flex: none; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 8px; background: #7059eb; color: #fff; }
.chat-form button:hover { background: #5e47d9; }
.chat-form button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.chat-hint { padding: 7px 21px 13px; color: #b3b5c0; font-size: 10px; text-align: right; }
.classroom-footnote { margin: 19px 0 0; color: #abaebb; font-size: 11px; text-align: center; }
/* Keep the desktop conversation beside the video at a bounded height. */
@media (min-width: 801px) and (min-height: 521px) {
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .chat-card {
    max-height: min(680px, 72vh);
    max-height: min(680px, 72dvh);
  }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .chat-messages { min-height: 0; }
}
.toast { position: fixed; z-index: 20; right: 25px; bottom: 24px; max-width: min(420px, calc(100vw - 32px)); padding: 13px 18px; border-radius: 11px; background: #282946; color: #fff; box-shadow: 0 12px 30px #20243b35; font-size: 12px; line-height: 1.5; }
.nickname-dialog { width: min(390px, calc(100vw - 28px)); max-width: none; padding: 25px; border: 1px solid #efedf7; border-radius: 17px; background: #fff; color: #25263d; box-shadow: 0 25px 80px #1c1b3a40; }
.nickname-dialog::backdrop { background: #20203587; backdrop-filter: blur(2px); }
.dialog-icon { display: grid; place-items: center; width: 39px; height: 39px; border-radius: 12px; background: #f0edff; color: #6953df; font-size: 20px; }
.nickname-dialog h2 { margin: 15px 0 6px; font-size: 19px; }
.nickname-dialog p { margin: 0 0 20px; color: #9295a4; font-size: 12px; line-height: 1.6; }
.nickname-dialog label { display: block; margin-bottom: 8px; color: #494b61; font-size: 12px; font-weight: 700; }
.nickname-dialog input { width: 100%; height: 46px; padding: 0 13px; border: 1px solid #dedfeb; border-radius: 10px; outline: none; color: #25263d; }
.nickname-dialog input:focus { border-color: #8674ed; box-shadow: 0 0 0 3px #7563ea1e; }
.nickname-dialog .form-error { margin: 8px 0 0; color: #ce3f52; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.dialog-actions .button { padding: 10px 17px; font-size: 12px; }

@media (max-width: 1050px) {
  .classroom-grid { grid-template-columns: minmax(0, 1fr) 310px; gap: 15px; }
  .classroom-main { padding: 31px 25px; }
  .header-inner { padding: 0 25px; }
  .stage-bottom { align-items: flex-start; flex-direction: column; }
  .control-actions { align-self: flex-end; }
}
@media (max-width: 800px) {
  .login-view { grid-template-columns: 1fr; }
  .login-art { display: none; }
  .login-main { min-height: 100vh; justify-content: center; padding: 26px; }
  .mobile-brand { display: flex; align-items: center; gap: 9px; align-self: flex-start; margin-bottom: auto; color: #272842; font-size: 16px; font-weight: 800; }
  .login-card { margin: 40px 0 80px; }
  .login-copyright { margin: auto 0 0; }
  .classroom-grid { grid-template-columns: 1fr; }
  .chat-card { min-height: 425px; }
  .chat-messages { min-height: 260px; height: 260px; }
  .stage-bottom { flex-direction: row; align-items: center; }
}
@media (max-width: 600px) {
  .header-inner { min-height: 62px; padding: 0 16px; }
  .brand { font-size: 15px; }
  .brand .brand-mark { width: 29px; height: 29px; border-radius: 9px; font-size: 21px; }
  .brand small, .connection-badge, .user-meta { display: none; }
  .header-right { gap: 10px; }
  .user-chip { padding-left: 0; border: 0; }
  .edit-nickname-button { margin-left: -5px; }
  .avatar { width: 31px; height: 31px; border-radius: 10px; }
  .classroom-main { padding: 26px 14px; }
  .page-heading { align-items: flex-start; flex-direction: column; gap: 17px; margin-bottom: 20px; }
  .page-heading h1 { font-size: 27px; }
  .stage-top, .chat-heading { padding: 18px 16px 15px; }
  .video-stage { width: calc(100% - 24px); margin: 0 12px; }
  .stage-bottom { align-items: stretch; flex-direction: column; padding: 18px 16px; }
  .control-actions { align-self: stretch; }
  .control-actions .button { width: 100%; }
  .stage-empty-icon { width: 50px; height: 50px; margin-bottom: 8px; border-radius: 15px; }
  .stage-empty-icon svg { width: 27px; height: 27px; }
  .stage-empty h3 { font-size: 13px; }
  .stage-empty p { font-size: 10px; }
}

/* Emoji selector for the shared classroom and fullscreen chat composer. */
.chat-form { position: relative; }
.chat-form button.emoji-toggle {
  width: 32px;
  height: 32px;
  flex: none;
  background: transparent;
  color: #5f5a78;
  font-size: 21px;
  line-height: 1;
}
.chat-form button.emoji-toggle:hover,
.chat-form button.emoji-toggle[aria-expanded="true"] { background: #f0edff; }
.emoji-picker {
  position: absolute;
  z-index: 12;
  left: 0;
  bottom: calc(100% + 8px);
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 3px;
  width: min(300px, 100%);
  padding: 9px;
  border: 1px solid #e5e1f3;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 14px 35px #22204438;
}
.emoji-picker button.emoji-option {
  width: 100%;
  height: 32px;
  border-radius: 7px;
  background: transparent;
  color: #222044;
  font-size: 20px;
  line-height: 1;
  touch-action: manipulation;
}
.emoji-picker button.emoji-option:hover,
.emoji-picker button.emoji-option:focus-visible { background: #f1eeff; outline: none; }

/* The fullscreen target contains both the video and the existing chat composer. */
.fullscreen-button {
  position: absolute;
  z-index: 10;
  top: 12px;
  right: 12px;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid #ffffff55;
  border-radius: 10px;
  background: #171827b8;
  color: #fff;
  backdrop-filter: blur(8px);
}
.fullscreen-button:hover, .fullscreen-button:focus-visible { background: #6951eb; outline: 2px solid #ffffffb3; outline-offset: 2px; }
.fullscreen-button svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.fullscreen-button.active svg { transform: rotate(180deg); }

@media (max-width: 800px) {
  .video-stage.portrait {
    width: calc(100% - 24px);
    width: min(calc(100% - 24px), calc(70dvh * var(--media-ratio)));
    aspect-ratio: var(--media-ratio);
    max-height: 70vh;
    max-height: 70dvh;
    margin-left: auto;
    margin-right: auto;
  }
}

body.stage-fullscreen-fallback { overflow: hidden; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  background: #090a10;
}
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .stage-card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  border: 0;
  border-radius: 0;
  background: #090a10;
  box-shadow: none;
}
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .stage-top { display: none; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .video-stage,
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .video-stage.portrait {
  flex: 1;
  width: 100%;
  min-height: 0;
  max-height: none;
  margin: 0;
  border-radius: 0;
  aspect-ratio: auto;
  background: #090a10;
}
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .video-stage video,
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .video-stage canvas { background: #090a10; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .stage-watermark { display: none; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .fullscreen-button {
  top: calc(12px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
}
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .stage-bottom {
  position: absolute;
  z-index: 5;
  top: calc(12px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  display: block;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  pointer-events: none;
}
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .stage-info { display: none; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .control-actions { pointer-events: auto; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .control-actions .button {
  width: auto;
  min-height: 40px;
  padding: 9px 12px;
  background: #171827c9;
  border-color: #ffffff55;
  color: #fff;
  box-shadow: none;
  backdrop-filter: blur(8px);
}
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .control-actions .button-danger { color: #ff9fae; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .control-actions .mic-button.is-on { background: #155239d9; border-color: #76dca0; color: #f0fff5; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .control-actions .mic-button.is-off { background: #662333d9; border-color: #ff9fb1; color: #fff3f6; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .control-actions .sound-button.is-on { background: #1c497bd9; border-color: #9ac9ff; color: #f2f8ff; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .control-actions .sound-button.is-off { background: #292e3dd9; border-color: #b9becb; color: #f4f5f8; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .control-actions .sound-button.sound-needs-action { background: #71501fd9; border-color: #f3cb7e; color: #fff5dd; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .chat-card {
  position: absolute;
  z-index: 7;
  left: calc(12px + env(safe-area-inset-left));
  bottom: calc(12px + env(safe-area-inset-bottom));
  width: min(360px, calc(100% - 24px - env(safe-area-inset-left) - env(safe-area-inset-right)));
  height: auto;
  min-height: 0;
  max-height: calc(100% - 76px);
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  pointer-events: none;
}
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .chat-heading,
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .members-section,
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .chat-hint { display: none; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .chat-messages {
  flex: 0 1 auto;
  height: auto;
  min-height: 0;
  /* Ten compact text lines plus padding; shorter chats keep their natural height. */
  max-height: min(192px, calc(100vh - 140px));
  max-height: min(192px, calc(100dvh - 140px));
  padding: 4px 2px 8px;
  overflow-y: auto;
  pointer-events: auto;
  scrollbar-color: #ffffff70 transparent;
}
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .chat-empty { color: #fff; text-shadow: 0 1px 5px #000; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .chat-empty strong,
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .chat-empty p { color: #fff; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .message { margin-bottom: 5px; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .message-avatar { color: #fff; background: rgba(0, 0, 0, .5); }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .message-meta {
  display: inline-flex;
  max-width: 100%;
  margin: 0 0 2px;
  padding: 2px 6px;
  border-radius: 7px;
  background: rgba(0, 0, 0, .5);
}
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .message-meta strong { color: #fff; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .message-meta time { color: #e8e9f3; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .message-text,
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .message.mine .message-text { padding: 6px 9px; color: #fff; background: rgba(0, 0, 0, .5); line-height: 1.4; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .chat-form {
  flex: none;
  margin: 0;
  border-color: #ffffff40;
  background: #171827d9;
  box-shadow: 0 4px 18px #0005;
  backdrop-filter: blur(8px);
  pointer-events: auto;
}
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .chat-form input { color: #fff; background: transparent; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .chat-form input::placeholder { color: #e4e2ec; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .chat-form button.emoji-toggle { color: #fff; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .emoji-picker { pointer-events: auto; }

@media (max-width: 600px) {
  .classroom-grid:is(:fullscreen, .fullscreen-fallback) .chat-card { max-height: min(38vh, 300px); max-height: min(38dvh, 300px); }
  .classroom-grid:is(:fullscreen, .fullscreen-fallback) .message-avatar { width: 25px; height: 25px; }
}

/* The phone classroom shares one viewport between the stream and the conversation. */
@media (max-width: 800px) {
  .classroom-view { display: flex; flex-direction: column; height: 100vh; height: var(--mobile-classroom-height, 100dvh); min-height: 0; overflow: hidden; }
  .site-header { flex: none; }
  .header-inner { min-height: 52px; }
  .classroom-main { display: flex; flex: 1; flex-direction: column; width: 100%; min-height: 0; padding: 8px 10px max(8px, env(safe-area-inset-bottom)); overflow: hidden; }
  .page-heading, .classroom-footnote { display: none; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) {
    display: grid;
    flex: 1;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 42%) minmax(0, 1fr);
    gap: 8px;
    min-height: 0;
  }
  .classroom-grid.portrait-stream:not(:fullscreen):not(.fullscreen-fallback) { grid-template-rows: minmax(0, 53%) minmax(0, 1fr); }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .stage-card,
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .chat-card { min-height: 0; border-radius: 12px; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .stage-card { display: flex; flex-direction: column; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .stage-top,
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .chat-heading { flex: none; min-height: 30px; padding: 6px 10px; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .stage-kicker { display: none; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .stage-top h2,
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .chat-heading h2 { margin: 0; font-size: 12px; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .video-stage,
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .video-stage.portrait {
    flex: 1;
    width: calc(100% - 12px);
    min-height: 0;
    max-height: none;
    margin: 0 6px;
    border-radius: 8px;
    aspect-ratio: auto;
  }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .stage-bottom { display: block; flex: none; min-height: 0; padding: 5px 8px 7px; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .stage-info,
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .members-section,
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .chat-hint { display: none; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .control-actions { width: 100%; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .control-actions .button { width: 100%; min-height: 34px; padding: 6px 10px; font-size: 12px; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .chat-card { position: relative; height: auto; overflow: visible; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .chat-messages { flex: 1; height: auto; min-height: 0; padding: 8px 10px; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .message { margin-bottom: 9px; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .message-text { font-size: 12px; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .chat-form { flex: none; margin: 0 8px 8px; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .member-list-toggle { display: inline-flex; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .members-section.mobile-open {
    position: absolute;
    z-index: 11;
    top: 30px;
    right: 8px;
    left: 8px;
    display: block;
    max-height: min(180px, 50%);
    overflow: auto;
    border: 1px solid #e9e5f5;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 12px 28px #22204430;
  }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .emoji-picker { max-height: min(180px, 45dvh); overflow-y: auto; }
  .classroom-short-viewport .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .stage-top { display: none; }
}

@media (max-width: 600px) {
  .header-inner { min-height: 50px; }
}

/* A landscape phone uses a compact side-by-side classroom. */
@media (max-width: 1000px) and (max-height: 520px) and (orientation: landscape) {
  .classroom-view { display: flex; flex-direction: column; height: 100vh; height: var(--mobile-classroom-height, 100dvh); min-height: 0; overflow: hidden; }
  .site-header { flex: none; }
  .header-inner { min-height: 42px; }
  .brand small, .connection-badge, .user-meta { display: none; }
  .classroom-main { display: flex; flex: 1; flex-direction: column; width: 100%; min-height: 0; padding: 5px 8px max(5px, env(safe-area-inset-bottom)); overflow: hidden; }
  .page-heading, .classroom-footnote { display: none; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback),
  .classroom-grid.portrait-stream:not(:fullscreen):not(.fullscreen-fallback) {
    display: grid;
    flex: 1;
    grid-template-columns: minmax(0, 1fr) minmax(220px, 34%);
    grid-template-rows: minmax(0, 1fr);
    gap: 8px;
    min-height: 0;
  }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .stage-card,
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .chat-card { min-height: 0; border-radius: 12px; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .stage-card { display: flex; flex-direction: column; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .stage-top,
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .chat-heading { flex: none; min-height: 26px; padding: 4px 8px; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .stage-kicker { display: none; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .stage-top h2,
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .chat-heading h2 { margin: 0; font-size: 12px; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .video-stage,
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .video-stage.portrait {
    flex: 1;
    width: calc(100% - 10px);
    min-height: 0;
    max-height: none;
    margin: 0 5px;
    border-radius: 8px;
    aspect-ratio: auto;
  }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .stage-bottom { display: block; flex: none; min-height: 0; padding: 4px 6px 6px; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .stage-info,
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .members-section,
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .chat-hint { display: none; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .control-actions { width: 100%; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .control-actions .button { width: 100%; min-height: 32px; padding: 5px 9px; font-size: 12px; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .chat-card { position: relative; height: auto; overflow: visible; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .chat-messages { flex: 1; height: auto; min-height: 0; padding: 6px 8px; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .message { margin-bottom: 8px; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .chat-form { flex: none; margin: 0 6px 6px; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .member-list-toggle { display: inline-flex; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .members-section.mobile-open {
    position: absolute;
    z-index: 11;
    top: 26px;
    right: 6px;
    left: 6px;
    display: block;
    max-height: min(150px, 55%);
    overflow: auto;
    border: 1px solid #e9e5f5;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 12px 28px #22204430;
  }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .emoji-picker { max-height: min(160px, 45dvh); overflow-y: auto; }
}

/* Teacher account management stays in a dialog, leaving the classroom layout intact. */
.manage-users-button { color: #6951df; font-weight: 700; }
.users-dialog {
  width: min(650px, calc(100vw - 24px));
  max-width: none;
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  padding: 0;
  overflow: hidden;
  border: 1px solid #efedf7;
  border-radius: 17px;
  background: #fff;
  color: #25263d;
  box-shadow: 0 25px 80px #1c1b3a40;
}
.users-dialog[open] { display: flex; flex-direction: column; }
.users-dialog::backdrop { background: #20203587; backdrop-filter: blur(2px); }
.users-dialog-header { display: flex; flex: none; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 22px 24px 16px; border-bottom: 1px solid #eeedf4; }
.users-dialog-header h2 { margin: 0 0 5px; font-size: 19px; }
.users-dialog-header p { margin: 0; color: #8d90a0; font-size: 12px; line-height: 1.5; }
.users-dialog-header .text-button { padding: 4px 0; }
.users-feedback { flex: none; margin: 0; padding: 10px 24px; border-bottom: 1px solid #cdebd9; background: #effaf3; color: #25774a; font-size: 12px; line-height: 1.4; overflow-wrap: anywhere; }
.users-dialog-body { min-height: 0; padding: 17px 24px 23px; overflow-y: auto; overscroll-behavior: contain; }
.users-section + .users-section { margin-top: 22px; padding-top: 18px; border-top: 1px solid #eeedf4; }
.users-section h3 { margin: 0 0 12px; font-size: 14px; }
.users-section-heading { display: flex; align-items: baseline; gap: 10px; }
.users-section-heading h3 { margin-right: auto; }
.users-section-heading span { color: #9295a4; font-size: 11px; }
.users-section-heading button { color: #6951df; }
.users-list-status { margin: 4px 0 10px; color: #888c9d; font-size: 12px; }
.users-list { display: grid; gap: 8px; }
.users-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 12px; min-width: 0; padding: 10px 12px; border: 1px solid #eaeaf2; border-radius: 11px; background: #fafaff; }
.users-identity { display: flex; flex-direction: column; min-width: 0; gap: 3px; }
.users-identity strong { overflow: hidden; color: #34354e; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.users-identity > span { overflow: hidden; color: #9295a4; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.users-badges, .users-row-actions { display: flex; align-items: center; gap: 8px; }
.users-online, .users-self { padding: 4px 7px; border-radius: 7px; background: #eeeef3; color: #777b89; font-size: 10px; white-space: nowrap; }
.users-online.is-online { background: #e7f7ef; color: #23885c; }
.users-self { background: #f0edff; color: #6653d7; }
.users-row-actions .text-button { min-height: 32px; color: #6951df; }
.users-row-actions .users-delete-button { color: #cb4b5d; }
.users-row-actions .text-button:disabled { color: #b9b9c4; cursor: not-allowed; }
.users-form label { display: block; margin: 0 0 7px; color: #494b61; font-size: 12px; font-weight: 700; }
.users-form input, .users-form select { width: 100%; height: 43px; margin-bottom: 13px; padding: 0 12px; border: 1px solid #dedfeb; border-radius: 10px; outline: none; background: #fff; color: #25263d; font: inherit; font-size: 12px; }
.users-form input:focus, .users-form select:focus { border-color: #8674ed; box-shadow: 0 0 0 3px #7563ea1e; }
.users-form-grid { display: grid; grid-template-columns: minmax(0, 1fr) 120px; gap: 10px; }
.users-form .form-error { margin: -2px 0 0; color: #ce3f52; font-size: 12px; }
.users-form .dialog-actions { margin-top: 3px; }
.nickname-dialog input + label { margin-top: 14px; }
.dialog-icon-danger { background: #fff1f2; color: #da4458; font-weight: 800; }

@media (max-width: 600px) {
  .header-right { gap: 7px; }
  .manage-users-button { font-size: 11px; }
  .users-dialog-header { padding: 15px 14px 12px; }
  .users-dialog-header h2 { font-size: 17px; }
  .users-dialog-header p { font-size: 11px; }
  .users-feedback { padding: 8px 14px; font-size: 11px; }
  .users-dialog-body { padding: 12px 14px 16px; }
  .users-row { grid-template-columns: minmax(0, 1fr) auto; gap: 4px 8px; padding: 8px 9px; }
  .users-row-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .users-row-actions .text-button { min-height: 31px; }
  .users-form-grid { grid-template-columns: minmax(0, 1fr) 94px; }
  .users-dialog .dialog-actions .button { min-height: 39px; }
  .nickname-dialog { max-height: calc(100dvh - 24px); overflow-y: auto; }
}

.control-actions .button svg { flex: none; }
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .control-actions {
  max-width: calc(100vw - 94px);
  flex-wrap: wrap;
}
.classroom-grid:is(:fullscreen, .fullscreen-fallback) .control-actions .button {
  padding: 7px 9px;
  font-size: 11px;
}

@media (max-width: 800px), (max-width: 1000px) and (max-height: 520px) and (orientation: landscape) {
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .control-actions { gap: 4px; flex-wrap: nowrap; }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .control-actions .button {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    gap: 4px;
    padding-right: 4px;
    padding-left: 4px;
  }
  .classroom-grid:not(:fullscreen):not(.fullscreen-fallback) .control-actions .button svg { width: 15px; height: 15px; }
}
