@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;600;700;800&family=Patrick+Hand&display=swap');

:root {
  --font-display: 'Baloo 2', 'Trebuchet MS', sans-serif;
  --font-story: 'Patrick Hand', 'Trebuchet MS', sans-serif;
  --paper-ink: #39213b;
  --paper-plum: #54264f;
  --paper-pink: #df3988;
  --paper-pink-soft: #fbe5ef;
  --paper-peach: #ffc982;
}

body {
  color: var(--paper-plum);
  background: #fff3f8;
  font-family: var(--font-display);
}

#student-room-badge { align-self: center; padding: 6px 16px; border: 1px solid #efc4d7; border-radius: 999px; background: #fffafd; color: #9c477c; font-size: 15px; text-align: center; }
#student-room-code { margin-left: 7px; color: #a72567; letter-spacing: .14em; font-size: 19px; }

/* The reference has a compact, balanced toolbar above a wide story canvas. */
.top-header {
  min-height: 76px;
  padding: 10px 28px;
  gap: 20px;
  background: #fffafd;
  border: 0;
  box-shadow: 0 2px 14px rgba(107, 47, 87, .06);
}

.top-header > #fullscreen-btn { order: 2; }
.brand-title { gap: 10px; font-size: 30px; line-height: 1; color: var(--paper-plum); }
.brand-icon {
  width: 44px;
  height: 44px;
  color: var(--paper-pink);
  background: none !important;
  font-size: 39px;
  transform: rotate(-8deg);
}
.session-pill { margin-left: 8px; padding: 8px 17px; background: var(--paper-pink); color: #fff; border: 0; font-size: 14px; }
.header-room-code { margin-left:0; padding:5px 12px; border:1px solid #efc4d7; border-radius:999px; background:#fff7fb; color:#9c477c; font:700 10px/1.2 var(--font-display); letter-spacing:.07em; white-space:nowrap; }
.header-room-code strong { margin-left:5px; color:#a72567; font-size:16px; letter-spacing:.16em; }
.header-tools { display: flex; align-items: center; gap: 22px; margin-left: auto; }
.enable-sound-btn { border:1px solid #efc4d7; border-radius:999px; background:#fff7fb; color:#a72567; padding:5px 10px; font:700 12px var(--font-display); white-space:nowrap; cursor:pointer; }
.room-retry-notice { max-width:180px; color:#9c477c; font:600 12px/1.2 var(--font-display); }
.room-retry-notice:empty { display:none; }
.enable-sound-btn.hidden { display:none; }
.header-join-url { position:absolute; left:50%; transform:translateX(-50%); max-width:28vw; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:#714568; font:700 15px/1.2 var(--font-display); }
.board-tab { padding: 8px 2px; color: #bd2e75; border-bottom: 2px solid #d83a86; font-weight: 700; }
.teacher-avatar { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: #ffd4e6; color: #923566; font-size: 29px; }
.settings { position: relative; }
.settings summary { cursor: pointer; list-style: none; font-size: 26px; }
.settings summary::-webkit-details-marker { display: none; }
.settings-menu { position: absolute; z-index: 30; top: 42px; right: 0; display: flex; flex-direction: column; gap: 10px; width: 245px; padding: 15px; border: 1px solid #f0c5d8; border-radius: 18px; background: #fffafd; box-shadow: 0 12px 30px #63284824; }
.settings-menu .btn { width: 100%; max-width: none !important; }
.fullscreen-icon { flex: none; width: 40px; height: 40px; border: 1px solid #efc4d7; border-radius: 12px; color: #993667; background: #fff7fb; font-size: 24px; cursor: pointer; }

/* Lobby: keep join information first, with the mission and roster directly below. */
#teacher-waiting-view { max-width: 1180px; padding: 32px 24px; }
.join-hero-card { border: 2px solid #f1d2df; border-radius: 28px; background: linear-gradient(135deg, #fffafd, #ffedf5); box-shadow: 0 14px 35px #a64e7714; }
.join-hero-title { color: #9c477c; }
.join-url-banner { color: #5d2d59; background: #fff; border: 2px dashed #df65a0; box-shadow: 0 6px 22px #d94f8a1a; }
.room-code-badge { color: #a72567; background: #fff; border-color: #df3988; }
.waiting-grid { gap: 18px; }
.preview-card, .roster-card { border: 1px solid #f0d1de; border-radius: 22px; background: #fffafd; box-shadow: 0 8px 20px #8444640b; }
#teacher-waiting-view .preview-card::after { position: absolute; top: 8px; right: 18px; color: #eeae4f; font-size: 34px; content: '☆'; }
#teacher-waiting-view .preview-card h2 { color: #a83e77 !important; }
#teacher-waiting-view .preview-card p { color: #543a58 !important; background: repeating-linear-gradient(to bottom, #fff 0, #fff 28px, #e7f2f7 29px, #fff 30px) !important; border-left-color: #dc5a91 !important; border-radius: 12px !important; line-height: 1.75 !important; }
.roster-pills { max-height: 220px; }
.student-pill { color: #654267; background: #fff0f6; border-color: #f1cada; font: 600 17px var(--font-display); }
.connection-lost { color:#b4234d!important; border-color:#e995a9!important; background:#fff0f1!important; }
.connection-lost small { color:#b4234d!important; }
#teacher-waiting-view > div:last-child .btn { min-width: min(100%, 330px); }

/* Live view sizing follows the reference: banner, then a 4:1 story/roster split. */
#teacher-live-view {
  height: calc(100dvh - 76px);
  min-height: 650px;
  gap: 14px;
  padding: 4px 20px 12px;
  overflow: hidden;
  background: #fff4f8;
}
.mission-banner {
  position: relative;
  isolation: isolate;
  display: flex;
  flex: none;
  align-items: center;
  gap: 28px;
  min-height: 190px;
  padding: 14px 28px;
  overflow: hidden;
  border-radius: 26px;
  background: linear-gradient(100deg, #fce4ee 0%, #fdeaf2 72%, #fbe5ef 100%);
}
.mission-banner::after {
  position: absolute;
  z-index: -1;
  right: 205px;
  bottom: -8px;
  width: 290px;
  height: 174px;
  background: url('assets/forest-silhouette.svg') center bottom / contain no-repeat;
  opacity: .52;
  content: '';
  pointer-events: none;
}
.mission-postcard {
  position: relative;
  z-index: 1;
  flex: none;
  width: 268px;
  height: 164px;
  padding: 10px;
  transform: rotate(-4deg);
  border-radius: 5px;
  background: #fff;
  box-shadow: 0 5px 13px #73405a20;
}
.mission-postcard::before {
  position: absolute;
  z-index: 2;
  top: -9px;
  left: 34%;
  width: 72px;
  height: 25px;
  transform: rotate(-10deg);
  background: radial-gradient(#fff9 1px, transparent 2px) 0 0 / 8px 8px, #ec8db4;
  content: '';
}
.mission-postcard img { display: block; width: 100%; height: 100%; object-fit: cover; }
.mission-copy { z-index: 1; flex: 1; min-width: 0; }
.eyebrow { color: #88617f; font-size: 16px; font-weight: 800; letter-spacing: 1px; }
.mission-copy h1 { margin: 8px 0 10px; color: var(--paper-plum) !important; font-size: clamp(27px, 2.7vw, 43px) !important; font-weight: 800; line-height: 1.12; }
.mission-copy p { color: #63455f; font-size: clamp(17px, 1.45vw, 23px); line-height: 1.3; }
.mission-note { position: relative; flex: none; padding: 24px 30px; border-radius: 22px; background: #fbd9e8; color: #6d2256; text-align: center; font: 500 23px/1.35 var(--font-story); }
.mission-note span { position: absolute; right: 10px; bottom: -8px; transform: rotate(12deg); color: #eda529; font-size: 48px; }

.live-main-content { display: grid; grid-template-columns: minmax(0, 1fr) 284px; gap: 15px; flex: 1; min-height: 0; overflow: visible; }
.story-column { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.writer-spotlight-card {
  display: flex;
  flex: none;
  align-items: center;
  gap: 19px;
  min-width: 0;
  min-height: 100px;
  padding: 12px 42px;
  border: 0 !important;
  border-radius: 20px 20px 0 0;
  background: linear-gradient(100deg, #ffcf83, #ffd494) !important;
  box-shadow: none !important;
  text-align: left;
}
.writer-star { transform: rotate(-12deg); color: #db3887; font-size: 52px; line-height: 1; }
.writer-label { color: #74214f !important; font-size: 22px; font-weight: 800; white-space: nowrap; }
.spotlight-name { overflow-wrap: anywhere; color: #552246 !important; font: 800 clamp(38px, 4.5vw, 66px)/1.05 var(--font-display); }
.pencil-art { margin-left: auto; transform: rotate(-18deg); color: #a5397d; font-size: 65px; line-height: 1; }

/* One notebook sheet owns its rules, left margin, punched holes and tape. */
.story-canvas-container {
  position: relative;
  isolation: isolate;
  display: flex;
  flex: 1;
  min-height: 280px;
  margin: 0;
  padding: 0;
  overflow: auto;
  border-radius: 0 0 20px 20px;
  background: #fff0f5;
  box-shadow: 0 7px 18px #75436012;
}
.story-paper {
  position: relative;
  flex: 1;
  max-width: none;
  min-height: 100%;
  margin: 0;
  padding: 52px 38px 80px 110px;
  border: 0;
  border-radius: 0 0 20px 20px;
  background-color: #fff;
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 43px, #cde7f2 44px, transparent 45px);
  box-shadow: none;
  color: var(--paper-ink);
  font: 400 clamp(28px, 2.2vw, 36px)/2.2 var(--font-story);
}
.story-paper::before {
  position: absolute;
  z-index: 0;
  top: 0;
  bottom: 0;
  left: 76px;
  width: 2px;
  background: #ee8db9;
  content: '';
  pointer-events: none;
}
.story-paper::after {
  position: absolute;
  z-index: 0;
  top: 14px;
  bottom: 10px;
  left: 25px;
  width: 25px;
  background: radial-gradient(circle, #ead0dc 0, #f8e7ee 10px, transparent 11px) 0 0 / 25px 45px repeat-y;
  content: '';
  pointer-events: none;
}
.story-paper > span { position: relative; z-index: 1; }
.story-paper #story-opening-anchor { color: var(--paper-ink) !important; font-style: normal !important; font-weight: 400 !important; }
.contribution-inline-span { position: relative; display: inline; margin: 0 .16em; padding: 0; border: 0 !important; border-radius: 0; background: transparent !important; box-shadow: none !important; line-height: inherit; box-decoration-break: clone; }
.student-author-tag { position: absolute; top: -1.4em; left: 0; padding: 2px 8px; border-radius: 9px; background: #f8b7dc; color: #57234f !important; font: 700 14px/1.25 var(--font-display); letter-spacing: 0; text-transform: none; white-space: nowrap; }
.contribution-body-text { color: var(--paper-ink) !important; font-weight: 400; }
.speech-word.is-speaking { border-radius:4px; background:#ffe082; color:#4c2549!important; box-shadow:0 0 0 2px #ffe082; }
#story-opening-anchor .speech-word.is-speaking { color:#4c2549!important; }
#story-opening-anchor .speech-word.is-speaking { color:#4c2549!important; }
.paper-tape { position: absolute; z-index: 2; right: 10px; bottom: 7px; display: block; width: 112px; height: 32px; transform: rotate(-28deg); background: radial-gradient(#fff9 1px, transparent 2px) 0 0 / 8px 8px, #ef8fbb; opacity: .95; pointer-events: none; }

.live-sidebar { display: flex; flex-direction: column; gap: 14px; padding: 19px 15px; overflow: auto; border: 0; border-radius: 20px; background: #fce5ef; color: #5d3b61; }
.roster-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: #76506e; font-size: 14px; }
.roster-heading strong { font-weight: 800; letter-spacing: .6px; }
.roster-heading span { font-size: 13px; }
.roster-heading i { display: inline-block; width: 9px; height: 9px; margin-left: 5px; border-radius: 50%; background: #39ae83; }
#live-roster-list { display: flex; flex-direction: column; gap: 12px; }
.roster-item { display: flex; align-items: center; justify-content: flex-start; gap: 12px; padding: 11px; border: 2px solid transparent; border-radius: 18px; background: #fffafd; color: #50234d; box-shadow: none; }
.roster-item.active-writer { border-color: #eb75ac !important; background: #ffe6f0 !important; box-shadow: 0 4px 12px #d94f8a18; }
.student-avatar { flex: none; width: 53px; height: 53px; overflow: hidden; border-radius: 50%; }
.student-avatar svg { display: block; width: 100%; height: 100%; }
.student-card-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.student-card-copy strong { overflow-wrap: anywhere; font-size: 20px; line-height: 1.2; }
.student-card-copy small { color: #837186; font-size: 14px; }
.active-writer .student-card-copy small { color: #c52f79; }

.teacher-controls-footer { display: flex; flex: none; flex-direction: column; gap: 7px; padding: 0; border: 0; background: transparent; box-shadow: none; }
.main-actions { display: flex; justify-content: center; gap: 15px; width: 100%; flex-wrap: wrap; }
.main-actions .btn { min-width: 220px; padding: 13px 24px !important; border-radius: 20px; box-shadow: none; font: 700 21px var(--font-display); }
.main-actions .btn span { margin-left: 10px; font-size: 27px; }
.main-actions .btn-mint { background: linear-gradient(110deg, #df3988, #cd2f78) !important; }
.main-actions .btn-secondary { border: 2px solid #efa8c7 !important; background: #fff0f6 !important; color: #a92368 !important; }
.extra-actions { display: flex; gap: 12px; }
.extra-actions .btn { padding: 2px 10px; border: 0 !important; background: transparent !important; box-shadow: none; color: #986580 !important; font-size: 12px; }

@media (min-width: 1600px) {
  .mission-banner { min-height: 196px; }
  .mission-postcard { width: 280px; height: 170px; }
  .live-main-content { grid-template-columns: minmax(0, 1fr) 296px; }
}
@media (max-width: 1100px) {
  .mission-note { display: none; }
  .mission-postcard { width: 200px; height: 142px; }
  .mission-banner { gap: 23px; padding-inline: 20px; }
  .mission-banner::after { right: 30px; }
  .live-main-content { grid-template-columns: minmax(0, 1fr) 250px; }
  .writer-spotlight-card { gap: 14px; padding-inline: 25px; }
  .writer-label { font-size: 18px; }
  .pencil-art { font-size: 50px; }
}
@media (max-width: 850px) {
  .top-header { flex-wrap: wrap; }
  .brand-title { font-size: 27px; }
  .header-tools { margin-left: auto; }
  #teacher-live-view { height: auto; min-height: 0; padding: 0 12px 14px; overflow: visible; }
  .mission-banner { min-height: 150px; }
  .mission-postcard { width: 145px; height: 120px; }
  .mission-copy h1 { font-size: 27px !important; }
  .live-main-content { display: flex; flex-direction: column; }
  .story-column { min-height: 480px; }
  .live-sidebar { max-height: 180px; }
  #live-roster-list { flex-direction: row; overflow: auto; }
  .roster-item { min-width: 175px; }
  .story-canvas-container { overflow: visible; }
  .main-actions .btn { min-width: 0; flex: 1; padding: 12px 15px !important; font-size: 18px; }
}
@media (max-width: 560px) {
  .top-header { gap: 8px; padding: 10px 14px; }
  .brand-title { gap: 7px; font-size: 23px; }
  .brand-icon { width: 34px; height: 34px; font-size: 31px; }
  .session-pill { margin-left: 0; padding: 6px 9px; font-size: 10px; }
  .header-tools { gap: 10px; }
  .teacher-avatar, .board-tab { display: none; }
  #teacher-waiting-view { padding: 16px 12px; }
  .join-url-banner { width: 100%; padding: .9rem 1rem; font-size: clamp(1.2rem, 7vw, 1.8rem); }
  .join-details-row { gap: 1.25rem; }
  .room-code-badge { font-size: 2.6rem; }
  .waiting-grid { grid-template-columns: 1fr; }
  .mission-banner { min-height: 122px; gap: 12px; padding: 12px; border-radius: 18px; }
  .mission-banner::after { right: 0; width: 125px; height: 95px; opacity: .3; }
  .mission-postcard { width: 86px; height: 92px; padding: 5px; }
  .mission-postcard::before { top: -7px; width: 42px; height: 16px; }
  .mission-copy { position: relative; z-index: 1; }
  .eyebrow { font-size: 11px; }
  .mission-copy h1 { margin: 5px 0; font-size: 21px !important; }
  .mission-copy p { font-size: 14px; }
  .writer-spotlight-card { min-height: 76px; gap: 9px; padding: 13px 12px; }
  .writer-star { font-size: 32px; }
  .writer-label { font-size: 12px; }
  .spotlight-name { font-size: clamp(27px, 8vw, 36px); }
  .pencil-art { display: none; }
  .story-column { min-height: 400px; }
  .story-paper { padding: 34px 15px 60px 56px; font-size: 25px; background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 37px, #cde7f2 38px, transparent 39px); }
  .story-paper::before { left: 38px; }
  .story-paper::after { left: 8px; width: 18px; background-size: 18px 39px; }
  .student-author-tag { font-size: 11px; }
  .paper-tape { right: 8px; bottom: 5px; width: 80px; height: 25px; }
  .teacher-controls-footer > div { width: 100%; }
  .main-actions { gap: 7px; }
  .main-actions .btn { padding: 10px 9px !important; border-radius: 14px; font-size: 14px; }
  .main-actions .btn span { display: none; }
}

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


/* Music stays directly under the main lobby action in one small, tidy control. */
.lobby-actions{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:8px;flex-wrap:wrap;width:100%;margin-top:4px}
#teacher-waiting-view .lobby-actions{flex-direction:column!important}
.lobby-session-actions{display:flex;align-items:center;justify-content:center;gap:12px;flex-wrap:wrap}
.lobby-session-actions>#btn-start-session{font-size:1.25rem;padding:1rem 2.7rem}
.lobby-session-actions>#btn-new-room{min-width:0;padding:.8rem 1.1rem;font-size:1rem}
.lobby-music{display:inline-flex;align-items:center;gap:9px;border:1px solid #f0d4e0;border-radius:999px;background:#fffafd;padding:4px 10px;box-shadow:0 2px 8px #8444640b;width:auto}
#toggle-music-btn{display:inline-flex;align-items:center;gap:5px;border:0;border-radius:999px;background:transparent;color:#9c4b78;font:600 11px var(--font-display);padding:2px 3px;min-width:0!important;cursor:pointer;box-shadow:none;white-space:nowrap}
#toggle-music-btn>span:first-child{font-size:15px;line-height:1;color:#ce548b}
#toggle-music-btn.music-playing{color:#ad326e}
#toggle-music-btn:focus-visible,#music-volume:focus-visible{outline:2px solid #ce548b;outline-offset:2px}
#music-volume{width:58px;height:16px;accent-color:#ce548b;cursor:pointer}
.top-header > #fullscreen-btn{order:0}.preview-card{position:relative}.btn,button,select,input{font-family:var(--font-display)}
@media(max-width:560px){.lobby-actions{gap:12px}.lobby-session-actions{width:100%;flex-wrap:nowrap}.lobby-session-actions>#btn-start-session{min-width:0!important;flex:1;padding:1rem .7rem;font-size:1rem}.lobby-session-actions>#btn-new-room{flex:none}}
/* Preserve the complete board and toolbar on shorter classroom displays. */
#teacher-live-view{min-height:0}.story-canvas-container{min-height:0}.brand-icon{box-shadow:none!important}.pencil-art img{display:block;width:76px;height:76px}.pencil-art{transform:none;font-size:0}
.student-card-copy small::before{content:'';display:inline-block;width:8px;height:8px;margin-right:6px;border-radius:50%;background:#43af88}.active-writer .student-card-copy small::before{background:#df3988}
.active-writer:not(.connection-lost) .student-card-copy small::before{content:'✏';width:auto;height:auto;background:none;color:#ce548b;font-size:14px;line-height:1}
.connection-lost .student-card-copy small::before{content:'●';width:auto;height:auto;background:none;color:#d33554;font-size:11px;line-height:1}
.main-actions .btn::before{content:'';width:34px;height:36px;flex:none;background:center/contain no-repeat}.main-actions #btn-read-whole-story::before{background-image:url('assets/book.svg')}.main-actions #btn-new-mission::before{background-image:url('assets/wand.svg')}.main-actions #btn-reset-session::before{background-image:url('assets/reset.svg')}
@media(max-height:800px) and (min-width:851px){.mission-banner{min-height:150px;padding-block:10px}.mission-postcard{width:210px;height:130px}.mission-copy h1{font-size:clamp(26px,2.5vw,38px)!important}.mission-note{padding:15px 20px;font-size:21px}.writer-spotlight-card{min-height:80px;padding-block:8px}.spotlight-name{font-size:48px}.main-actions .btn{padding:9px 22px!important;font-size:20px}.story-paper{padding-top:40px}.pencil-art img{width:60px;height:60px}}
@media(max-width:560px){.main-actions .btn{gap:5px}.main-actions .btn::before{width:23px;height:26px}}
body.session-live{height:100dvh;min-height:0;overflow:hidden}body.session-live #app-container{height:100dvh;min-height:0;flex:none}.top-header{flex-shrink:0}body.session-live #teacher-live-view{height:auto;flex:1;min-height:0}
@media(max-width:850px){body.session-live{height:auto;min-height:100dvh;overflow:auto}body.session-live #app-container{height:auto;min-height:100dvh}body.session-live #teacher-live-view{height:auto;flex:none}}
@media(max-width:850px){.header-join-url{position:static;order:4;transform:none;max-width:100%;width:100%;text-align:center;font-size:13px}}
