:root {
  --font: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  --background: #EAF5FB;
  --ink: #0B3954;
  --primary: #1E88E5;
  --send: #FF8A00;
  --gap: 12px;
  --radius: 16px;
  --color-size: 48px;
  font-family: var(--font);
  color: var(--ink);
  background: var(--background);
  font-size: 18px;
  line-height: 1.5;
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
[hidden] { display: none !important; }
button, input, a { -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; }
button, .button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 60px; padding: 12px 20px; border: 2px solid transparent;
  border-radius: var(--radius); background: var(--primary); color: white;
  font-size: 22px; font-weight: 700; line-height: 1.3; cursor: pointer;
  text-decoration: none; gap: 8px;
}
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 4px solid var(--ink); outline-offset: 4px; }
button:not(:disabled):active, .button:active { transform: translateY(2px); }
.send { background: var(--send); }
.secondary { background: white; color: var(--primary); border-color: var(--primary); }
input { min-width: 0; width: 100%; min-height: 60px; border: 2px solid #9BC5DC; border-radius: var(--radius); padding: 10px 16px; color: var(--ink); background: white; font-size: 22px; }
input::placeholder { color: #607F90; }
h1 { font-size: 30px; line-height: 1.3; margin: 0 0 16px; }
p { margin: 0; }
.message { color: #A52D27; min-height: 0; overflow-wrap: anywhere; }
.message:empty { display: none; }
.mode-badge { position: fixed; z-index: 20; bottom: 4px; left: 8px; padding: 2px 8px; border-radius: 8px; background: rgba(255,255,255,.85); color: var(--ink); font-size: 12px; pointer-events: none; }
.home-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.home-card { text-align: center; max-width: 100%; }
.home-card h1 { font-size: 40px; font-weight: 700; margin-bottom: 36px; overflow-wrap: anywhere; }
.home-actions { display: flex; gap: 20px; justify-content: center; flex-wrap: wrap; }
.home-actions .button { width: 280px; max-width: 100%; height: 88px; font-size: 28px; }
.home-card .message { margin-top: 20px; }
.back-link { color: var(--ink); display: inline-block; padding: 10px 0; margin-bottom: 8px; font-weight: 700; text-decoration: none; }
.join-view { width: min(440px, 100%); margin: auto; padding: 16px 20px 36px; }
.join-card { display: grid; gap: var(--gap); padding: 24px; background: rgba(255,255,255,.75); border-radius: 24px; box-shadow: 0 2px 12px rgba(11,57,84,.08); }
.join-card h1 { text-align: center; margin-bottom: 4px; }
.join-card label { font-weight: 700; }
.code-input { font-size: 44px; font-weight: 700; text-align: center; letter-spacing: .25em; padding-left: calc(16px + .25em); background: repeating-linear-gradient(90deg, #fff 0, #fff calc(25% - 1px), #CFE3EF calc(25% - 1px), #CFE3EF 25%); }
.keypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--gap); container-type: inline-size; }
.keypad button { color: var(--ink); background: #EAF5FB; padding: 8px; font-size: 28px; }
.keypad .delete-key { white-space: nowrap; font-size: 18px; letter-spacing: -0.02em; gap: 4px; }
.keypad .delete-key > [aria-hidden] { font-size: 20px; }
@container (width < 294px) { .keypad .delete-text { display: none; } .keypad .delete-key > [aria-hidden] { font-size: 26px; } }

body.teacher-gating { background: #EAF5FB; overflow: auto; }
.teacher-gating #stage-canvas { display: none; }
.teacher-gate { min-height: 100vh; min-height: 100dvh; display: grid; place-content: center; padding: 20px; }
.teacher-gate-inner { width: min(420px, calc(100vw - 40px)); }
.teacher-gate .back-link { font-size: 16px; }
.teacher-card { background: white; border-radius: 20px; padding: 32px 28px; box-shadow: 0 8px 24px rgba(11,57,84,.12); }
.teacher-card h1 { font-size: 28px; text-align: center; }
.teacher-card .teacher-intro { color: #4A6572; font-size: 16px; line-height: 1.5; text-align: center; }
.teacher-card label { display: block; margin-top: 20px; font-size: 16px; font-weight: 700; }
.teacher-card input { height: 56px; min-height: 56px; font-size: 20px; border: 2px solid #9FC7DD; border-radius: 14px; padding: 0 16px; }
.teacher-card input:focus { border-color: #1E88E5; }
.teacher-card .teacher-error { color: #C62828; font-size: 14px; }
.teacher-card button { width: 100%; height: 56px; min-height: 56px; margin-top: 16px; border-radius: 14px; background: #FF8A00; font-size: 20px; }
.teacher-hint { margin-top: 16px; text-align: center; color: #4A6572; font-size: 15px; }
.choose-view { max-width: 1120px; margin: auto; padding: 28px 24px 40px; }
.page-header { display: flex; gap: 16px; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.page-header h1 { margin: 4px 0 0; }
.eyebrow { font-size: 18px; font-weight: 700; }
.template-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px; margin-top: 16px; }
.template-card { background: white; color: var(--ink); border: 2px solid #D4E7F2; flex-direction: column; padding: 16px 10px; font-size: 22px; }
.template-card:hover { border-color: var(--primary); }
.template-card img { display: block; width: 100%; height: 132px; object-fit: contain; }
.paint-view { padding: 16px 20px 30px; }
.paint-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 0 0 12px; }
.paint-header h1 { font-size: 26px; margin: 0; }
.paint-header span { font-weight: 700; font-size: 18px; }
.paint-layout { display: flex; flex-direction: column; gap: 16px; }
.canvas-card { display: flex; align-items: center; justify-content: center; background: white; border-radius: 20px; box-shadow: 0 2px 12px rgba(11,57,84,.08); padding: 16px; min-width: 0; }
#fill-canvas { display: block; width: 100%; height: min(47dvh, 620px); object-fit: contain; touch-action: none; user-select: none; }
.paint-panel { min-width: 0; display: flex; flex-direction: column; align-items: stretch; gap: var(--gap); }
.palette { display: grid; grid-template-columns: repeat(6, var(--color-size)); justify-content: center; gap: 12px; padding: 6px; }
.color-button { width: var(--color-size); height: var(--color-size); min-height: 0; padding: 0; border-radius: 50%; border: 2px solid rgba(11,57,84,.15); }
.color-button[aria-pressed="true"] { border: 4px solid var(--ink); transform: scale(1.1); box-shadow: 0 0 0 2px white; }
.color-button.is-white { border-color: #909EA5; }
.color-button.is-white[aria-pressed="true"] { border-color: var(--ink); }
.paint-tools { display: flex; gap: var(--gap); }
.paint-tools button { flex: 1; font-size: 22px; padding: 10px 4px; }
#send { width: 100%; min-height: 76px; font-size: 26px; margin-top: auto; }
.sending { animation: fly-away .8s ease-in forwards; }
@keyframes fly-away { to { transform: translateY(-100vh) scale(.4); opacity: 0; } }
.success-view { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; padding: 24px; text-align: center; }
.success-view h1 { margin: 0; font-size: 36px; }
.success-symbol { width: 100px; height: 100px; display: grid; place-items: center; border-radius: 50%; background: white; color: #2E7D32; font-size: 64px; }
.stage-page { overflow: hidden; background: var(--ink); }
#stage-canvas { display: block; width: 100vw; height: 100vh; height: 100dvh; }
.room-overlay { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; }
.room-card { display: flex; flex-direction: column; width: min(680px, 100%); padding: 32px 24px; gap: 8px; background: rgba(255,255,255,.88); color: var(--ink); box-shadow: 0 8px 40px rgba(11,57,84,.12); font-size: 22px; }
.room-card:disabled { opacity: 1; }
.room-label { font-size: 24px; }
.stage-code { font-size: 120px; line-height: 1.25; letter-spacing: .06em; }
.student-url { font-size: 20px; overflow-wrap: anywhere; max-width: 100%; user-select: text; }
.room-hint { font-size: 18px; font-weight: 400; margin-top: 16px; }
.room-small { position: fixed; top: 16px; left: 16px; background: rgba(255,255,255,.8); color: var(--ink); min-height: 48px; padding: 8px 18px; font-size: 28px; }
.fullscreen { position: fixed; z-index: 4; right: 16px; top: 16px; border-radius: 50%; width: 48px; height: 48px; min-height: 48px; padding: 0; background: rgba(255,255,255,.8); color: var(--ink); font-size: 28px; }
.stage-error { position: fixed; z-index: 5; bottom: 28px; left: 50%; transform: translateX(-50%); background: white; border-radius: 16px; padding: 16px 24px; color: #A52D27; max-width: calc(100% - 32px); text-align: center; }
@media (min-width: 700px) and (min-height: 700px) { :root { --color-size: 56px; } }
@media (min-width: 700px) { .template-grid { grid-template-columns: repeat(4, minmax(140px, 1fr)); } }
@media (min-width: 850px) { .template-grid { grid-template-columns: repeat(5, minmax(140px, 1fr)); } }
@media (orientation: landscape) and (min-width: 700px) {
  .paint-view { height: 100vh; height: 100dvh; display: flex; flex-direction: column; padding-bottom: 24px; }
  .paint-layout { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 260px; }
  .canvas-card { min-height: 0; }
  #fill-canvas { height: 100%; }
  .paint-panel { min-height: 0; padding: 6px; }
  .palette { grid-template-columns: repeat(3, var(--color-size)); gap: 10px; }
  .paint-tools { gap: 6px; }
  .paint-tools button { min-width: 0; height: 64px; min-height: 64px; flex-direction: column; gap: 0; padding: 2px; font-size: 14px; line-height: 1.15; font-weight: 700; white-space: nowrap; }
  .paint-tools button span span { display: block; font-size: 24px; line-height: 1; }
  #send { height: 72px; min-height: 72px; font-size: 24px; font-weight: 700; }
}
@media (max-width: 399px) {
  .join-view { padding: 12px 12px 28px; }
  .join-card { padding: 20px 16px; }
  .choose-view { padding: 20px 16px 32px; }
  .page-header { align-items: flex-start; }
  .page-header h1 { font-size: 26px; }
  .page-header button { padding: 10px; font-size: 22px; }
  .template-grid { gap: 12px; }
  .paint-view { padding: 12px 8px 28px; }
  .paint-header h1 { font-size: 22px; }
  .palette { gap: 9px; padding: 6px 0; }
  .paint-tools { gap: 8px; }
  .stage-code { font-size: 86px; }
  .student-url { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) { .sending { animation-timing-function: linear; } }

/* Teacher preparation and classroom controls share the student palette. */
.preparing { overflow: auto; background: var(--background); }
.preparing #stage-canvas { display: none; }
.prepare-view { max-width: 1120px; margin: auto; padding: 32px 24px 48px; }
.prepare-view h1, .gallery-card h1, .students-card h1 { font-size: 28px; font-weight: 700; color: #0B3954; }
.prepare-view h2 { margin: 12px 0; font-size: 24px; }
.world-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; }
.world-card { min-height: 180px; border-radius: 20px; background: white; color: var(--ink); border: 4px solid var(--primary); font-size: 28px; }
.selection-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.selection-tools button { font-size: 20px; }
.selection-card { position: relative; border: 4px solid transparent; border-radius: 20px; }
.selection-card[aria-pressed="true"] { border-color: #1E88E5; }
.selection-check { display: none; position: absolute; right: 8px; top: 8px; width: 30px; height: 30px; border-radius: 50%; color: white; background: #1E88E5; font-size: 22px; }
.selection-card[aria-pressed="true"] .selection-check { display: grid; place-items: center; }
.prepare-footer { position: sticky; bottom: 0; background: rgba(234,245,251,.96); display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 16px; padding: 16px 0; margin-top: 20px; }
.prepare-footer .send { min-width: 200px; }
.stage-controls { position: fixed; z-index: 4; right: 16px; top: 16px; display: flex; gap: 10px; transition: opacity .2s; }
.stage-controls.idle { opacity: .3; }
.stage-controls:focus-within { opacity: 1; }
.stage-controls button { width: 48px; height: 48px; min-height: 48px; border-radius: 50%; padding: 0; background: rgba(255,255,255,.8); color: var(--ink); font-size: 25px; }
.stage-controls #room-info { font-size: 18px; }
.stage-controls #hide-mode[aria-pressed="true"] { background: #C62828; color: white; }
.stage-banner { position: fixed; z-index: 2; top: 80px; left: 50%; transform: translateX(-50%); padding: 8px 20px; background: rgba(255,255,255,.9); color: var(--ink); border-radius: 20px; white-space: nowrap; pointer-events: none; }
.hide-cursor { cursor: crosshair; }
.room-card { width: min(900px, 100%); flex-direction: row; flex-wrap: wrap; border-radius: 20px; gap: 16px; max-height: calc(100dvh - 48px); overflow: auto; }
.room-details { display: flex; flex: 1; min-width: 0; flex-direction: column; align-items: center; gap: 6px; }
.room-qr { display: block; width: 220px; height: 220px; flex-shrink: 0; background: white; }
.room-qr img { width: 220px; height: 220px; display: block; image-rendering: pixelated; }
.room-hint { flex-basis: 100%; margin-top: 0; }
.gallery-card { width: min(560px, calc(100% - 32px)); max-height: calc(100dvh - 32px); overflow: auto; padding: 28px; border: 0; border-radius: 20px; background: white; color: var(--ink); box-shadow: 0 12px 60px #0B395440; }
.gallery-card::backdrop { background: #0B395466; }
.gallery-card > * + * { margin-top: 16px; }
.gallery-card strong { display: block; }
.gallery-card button { width: 100%; font-size: 21px; }
.danger { color: #C62828; border-color: #E2B4B4; }
.send-toast { position: fixed; z-index: 30; bottom: 28px; left: 50%; transform: translateX(-50%); background: white; color: var(--ink); border-radius: 20px; padding: 16px 24px; box-shadow: 0 4px 24px #0B395430; }
.students-page { background: var(--background); padding: 24px; }
.students-card { max-width: 980px; margin: auto; padding: 28px; background: white; border-radius: 20px; }
.students-form { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 16px; margin: 24px 0; }
.students-form label { flex: 1 1 150px; }
.students-table { width: 100%; border-collapse: collapse; margin-top: 24px; text-align: left; }
.students-table td, .students-table th { border-bottom: 1px solid #D4E7F2; padding: 12px; }
@media (orientation: portrait) {
  .room-card { flex-direction: column; flex-wrap: nowrap; }
  .room-hint { flex-basis: auto; }
  .room-qr, .room-qr img { width: 220px; height: 220px; }
}
@media (max-width: 480px) {
  .prepare-view { padding: 24px 16px; }
  .selection-tools button { font-size: 17px; padding: 10px; }
  .room-card { padding: 20px 16px; }
  .stage-code { font-size: 72px; }
  .room-label { font-size: 20px; }
  .student-url { font-size: 15px; }
  .stage-controls { right: 10px; }
  .room-small { top: 76px; font-size: 20px; padding: 6px 10px; }
  .gallery-card { padding: 24px 20px; }
}

.sound-small { width: 40px; height: 40px; min-height: 40px; padding: 0; flex-shrink: 0; font-size: 23px; border-radius: 50%; }
.paint-header #template-name { margin-left: auto; }
#send { white-space: nowrap; }
.stage-debug { position: fixed; bottom: 30px; left: 8px; color: white; background: #0009; padding: 4px 8px; font: 13px monospace; pointer-events: none; z-index: 5; }
