:root {
  --red: #d62839;
  --red-d: #a4161a;
  --gold: #ffd166;
  --green: #1b4332;
  --card: rgba(15, 23, 42, 0.72);
  --line: rgba(255, 255, 255, 0.16);
  --text: #fdf8ef;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #050a18; color: var(--text); font-family: 'Gowun Dodum', system-ui, sans-serif; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: rgba(255,255,255,0.1); color: var(--text); border-radius: 12px; padding: 8px 14px; }
button:hover { background: rgba(255,255,255,0.18); }
button.primary { background: linear-gradient(180deg, #e63946, var(--red-d)); border-color: #ff8fa3; font-family: 'Jua', sans-serif; letter-spacing: .5px; box-shadow: 0 6px 20px rgba(214, 40, 57, .35); }
button.primary:hover { filter: brightness(1.1); }
button.big { font-size: 18px; padding: 12px 20px; border-radius: 16px; }
input, textarea { font: inherit; color: var(--text); background: rgba(0,0,0,0.35); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; outline: none; }
input:focus, textarea:focus { border-color: var(--gold); }
.err { color: #ff8fa3; min-height: 1em; margin: 8px 0 0; font-size: 14px; }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(ellipse at center, rgba(5,10,24,.35), rgba(5,10,24,.85)); z-index: 20; padding: 16px; }
.join-card, .wish-card { width: min(420px, 100%); background: var(--card); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: 24px; padding: 28px; box-shadow: 0 30px 80px rgba(0,0,0,.5); }
.join-title { font-family: 'Jua', sans-serif; font-size: 34px; text-align: center; text-shadow: 0 0 24px rgba(255, 209, 102, .6); }
.join-sub { text-align: center; opacity: .8; margin: 6px 0 22px; }
.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.field > span { font-size: 14px; opacity: .75; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatches button { width: 30px; height: 30px; border-radius: 50%; padding: 0; border: 2px solid transparent; }
.swatches.small button { width: 24px; height: 24px; }
.swatches button.on { border-color: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.25); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { padding: 6px 12px; font-size: 14px; }
.chips button.on { background: rgba(255, 209, 102, .25); border-color: var(--gold); }
#joinBtn { width: 100%; font-size: 20px; padding: 14px; margin-top: 6px; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }
.topbar { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; pointer-events: none; width: calc(100% - 32px); }
.pill { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: 14px; backdrop-filter: blur(8px); white-space: nowrap; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #06d6a0; box-shadow: 0 0 8px #06d6a0; }

#chat { position: absolute; left: 16px; bottom: 16px; width: min(440px, calc(100% - 32px)); display: flex; flex-direction: column; gap: 6px; transition: width .2s; }
#chat[data-size="big"] { width: min(560px, calc(100% - 32px)); }
.chat-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; padding: 0 4px; opacity: .85; }
.chat-head button { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--text); cursor: pointer; }
.chat-body { position: relative; }
#chatLog { height: 34vh; overflow-y: auto; display: flex; flex-direction: column; gap: 5px; padding: 10px 12px; border-radius: 14px; background: rgba(15,23,42,.62); border: 1px solid var(--line); backdrop-filter: blur(6px); font-size: 15px; line-height: 1.45; scrollbar-width: thin; pointer-events: auto; overscroll-behavior: contain; word-break: break-word; }
#chat[data-size="big"] #chatLog { height: 58vh; }
#chat[data-size="min"] #chatLog { height: 0; padding: 0; border: 0; }
#chat[data-size="min"] #chatNew { display: none; }
#chatLog .m:first-child { margin-top: auto; }
#chatLog .tm { font-size: 11px; opacity: .45; margin-right: 6px; font-variant-numeric: tabular-nums; }
#chatNew { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); font-size: 12px; padding: 5px 12px; border-radius: 999px; border: none; background: var(--gold); color: #3d2c00; cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,.3); }
#chatLog .m b { font-weight: 700; }
#chatLog .sys { opacity: .6; font-size: 13px; }
#chatForm { display: flex; gap: 6px; }
#chatForm input { flex: 1; min-width: 0; background: var(--card); }

.actions { position: absolute; right: 16px; bottom: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.emotes { display: flex; gap: 6px; background: var(--card); padding: 6px; border-radius: 14px; border: 1px solid var(--line); }
.emotes button { padding: 4px 8px; font-size: 20px; border: none; background: transparent; }
.help { position: absolute; top: 56px; left: 50%; transform: translateX(-50%); font-size: 13px; opacity: .7; background: var(--card); padding: 6px 14px; border-radius: 999px; white-space: nowrap; transition: opacity 1s; pointer-events: none; }

#bubbles { position: fixed; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }
.bubble { position: absolute; transform: translate(-50%, -100%); background: #fff; color: #222; padding: 6px 12px; border-radius: 14px; font-size: 14px; max-width: 220px; word-break: break-all; box-shadow: 0 4px 14px rgba(0,0,0,.3); white-space: pre-wrap; }
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%); border: 6px solid transparent; border-top-color: #fff; border-bottom: 0; }
.bubble.emote { background: transparent; box-shadow: none; font-size: 34px; padding: 0; animation: floatUp 2s ease-out forwards; }
.bubble.emote::after { display: none; }
@keyframes floatUp { from { opacity: 1; margin-top: 0; } to { opacity: 0; margin-top: -60px; } }
.label { position: absolute; transform: translate(-50%, -100%); font-size: 12px; padding: 1px 8px; border-radius: 8px; background: rgba(0,0,0,.45); color: #fff; white-space: nowrap; font-family: 'Jua', sans-serif; }
.label.me { background: rgba(214, 40, 57, .75); }

.wish-head { font-family: 'Jua', sans-serif; font-size: 24px; margin-bottom: 12px; }
#wishText { width: 100%; height: 120px; resize: none; font-family: 'Nanum Pen Script', cursive; font-size: 26px; line-height: 1.2; background: #fff3a3; color: #3d2c00; border: none; }
.wish-card .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.wish-card .row.end { justify-content: flex-end; }
.hint { font-size: 13px; opacity: .7; margin: 10px 0 0; }
#pickBanner { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 15; background: var(--card); border: 1px solid var(--gold); padding: 10px 16px; border-radius: 14px; display: flex; gap: 10px; align-items: center; }

#wishView { position: fixed; inset: 0; z-index: 18; display: grid; place-items: center; background: rgba(0,0,0,.35); }
.note-paper { width: min(300px, 80vw); aspect-ratio: 1; padding: 28px 24px; background: #fff3a3; color: #3d2c00; box-shadow: 0 20px 50px rgba(0,0,0,.5); transform: rotate(-2deg); display: flex; flex-direction: column; justify-content: space-between; position: relative; animation: pop .25s ease-out; }
.note-paper::before { content: ''; position: absolute; top: -10px; left: 50%; width: 90px; height: 24px; transform: translateX(-50%) rotate(2deg); background: rgba(255,255,255,.55); }
.note-text { font-family: 'Nanum Pen Script', cursive; font-size: 34px; line-height: 1.15; word-break: break-all; }
.note-from { font-family: 'Nanum Pen Script', cursive; font-size: 24px; text-align: right; opacity: .75; }
.note-who { font-family: 'Jua', sans-serif; font-size: 16px; opacity: .8; margin-top: 4px; }
.note-when { font-size: 12px; text-align: right; opacity: .55; }
.note-paper { background-image: linear-gradient(180deg, rgba(255,255,255,.25), rgba(255,255,255,0) 40%, rgba(60,40,0,.12)); }
.note-paper::after { content: ''; position: absolute; right: 0; bottom: 0; width: 42px; height: 42px; background: linear-gradient(315deg, rgba(5,10,24,.35) 50%, rgba(0,0,0,.14) 50%, rgba(255,255,255,.35)); }
#noteTip { position: fixed; left: 0; top: 0; z-index: 16; max-width: 260px; pointer-events: none; background: rgba(255,252,240,.97); color: #2f2208; border-left: 6px solid #fff3a3; border-radius: 10px; padding: 8px 12px; box-shadow: 0 8px 24px rgba(0,0,0,.35); }
#noteTip .who { font-family: 'Jua', sans-serif; font-size: 14px; }
#noteTip .what { font-family: 'Nanum Pen Script', cursive; font-size: 24px; line-height: 1.1; word-break: break-all; margin: 2px 0; }
#noteTip .when { font-size: 11px; opacity: .55; text-align: right; }
#heightPill { background: rgba(214,40,57,.75); }
@keyframes pop { from { transform: scale(.7) rotate(-8deg); opacity: 0; } }

#toast { position: fixed; top: 100px; left: 50%; transform: translateX(-50%); background: var(--card); border: 1px solid var(--line); padding: 10px 18px; border-radius: 14px; z-index: 30; opacity: 0; transition: opacity .3s; pointer-events: none; }
#toast.show { opacity: 1; }

#joystick { position: absolute; left: 24px; bottom: 150px; width: 110px; height: 110px; border-radius: 50%; background: rgba(255,255,255,.08); border: 1px solid var(--line); display: none; touch-action: none; }
#joystick .stick { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%; background: rgba(255,255,255,.35); }

@media (pointer: coarse) {
  #joystick { display: block; }
  .help { display: none; }
}
@media (max-width: 640px) {
  #chat { width: calc(100% - 32px); bottom: 84px; }
  #chatLog { height: 22vh; font-size: 14px; }
  #chat[data-size="big"] #chatLog { height: 46vh; }
  .actions { left: 16px; right: 16px; bottom: 16px; flex-direction: row; justify-content: space-between; align-items: center; }
  .emotes { overflow-x: auto; max-width: 52%; }
  button.big { font-size: 15px; padding: 10px 12px; }
  #joystick { bottom: auto; top: 110px; left: auto; right: 16px; width: 96px; height: 96px; }
}

/* A candlelit invitation to the winter great hall. */
:root { --red: #79333b; --red-d: #4c202d; --gold: #d8b778; --green: #203e38; --card: rgba(15, 23, 30, .9); --line: rgba(216,183,120,.25); --text: #eee7d8; }
html, body { background: #0b111c; }
button { border-radius: 5px; transition: background .2s, border-color .2s, transform .2s; }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }
button.primary { background: linear-gradient(135deg, #987044, #d6b778 48%, #b28b51); border: 1px solid #e0c593; color: #201b15; font-family: 'Noto Serif KR', serif; font-weight: 700; box-shadow: 0 6px 24px #0004; letter-spacing: 0; }
button.primary:hover { transform: translateY(-1px); filter: brightness(1.08); }
input, textarea { border-radius: 4px; background: #080e1580; }
#join { background: linear-gradient(90deg, rgba(6,12,21,.89), rgba(6,12,21,.44) 50%, rgba(6,12,21,.76)), linear-gradient(0deg,#070d18c9,transparent 45%); overflow-y: auto; padding: 48px 6vw; }
.invitation { width: min(1140px,100%); display: grid; grid-template-columns: 1fr 400px; align-items: center; gap: 9%; }
.invitation-story { padding: 10px 0; }
.eyebrow, .card-eyebrow, .invitation-footer { font-family: 'Cormorant Garamond', Georgia, serif; letter-spacing: .24em; color: #d8b778; font-size: 12px; }
.school-seal { margin: 30px 0 24px; border: 1px solid #d8b77866; width: 62px; height: 70px; border-radius: 40% 40% 48% 48%; display: grid; place-items: center; font-size: 33px; color: var(--gold); box-shadow: inset 0 0 0 5px #d8b7780d; }
.invitation-kicker { font-size: 13px; color: #d1bc95; letter-spacing: .18em; margin: 0 0 14px; }
h1 { font-family: 'Noto Serif KR',serif; font-size: clamp(30px,3.7vw,49px); line-height: 1.55; font-weight: 500; letter-spacing: -.06em; margin: 0; text-shadow: 0 3px 30px #0008; }
h1 em { font-style: normal; color: #dfc38b; }
.invitation-desc { color: #bdb8b0; font-size: 14px; line-height: 1.9; margin: 24px 0; }
.invitation-details { display: flex; gap: 24px; font-size: 12px; color: #cec0a5; }
.invitation-footer { margin-top: 42px; border-top: 1px solid #d8b77833; padding-top: 20px; font-size: 10px; letter-spacing: .18em; }
.join-card, .wish-card { border-radius: 8px; background: linear-gradient(150deg,rgba(27,35,43,.96),rgba(11,18,27,.96)); border: 1px solid #bfa16d70; box-shadow: 0 24px 80px #0007, inset 0 0 0 5px #bfa16d08; padding: 32px; }
.join-card { width: 100%; position: relative; }
.join-card::before, .join-card::after { content: '✦'; position: absolute; color: #d8b778; font-size: 12px; top: -8px; background: #16202a; padding: 0 5px; }
.join-card::before { left: 22px; } .join-card::after { right: 22px; }
.card-eyebrow { text-align: center; font-size: 11px; margin: 5px 0 14px; }
.join-title { font: 600 27px 'Noto Serif KR',serif; text-shadow: none; letter-spacing: -.05em; color: #f0dfbc; }
.join-sub { font-size: 12px; line-height: 1.7; margin: 12px 0 28px; color: #a9b3bb; }
.field { margin-bottom: 20px; gap: 10px; }
.field > span { font-size: 12px; opacity: 1; color: #c4b799; }
.swatches { gap: 10px; }
.swatches button { width: 25px; height: 25px; }
.swatches button.on { border-color: #ead6ad; box-shadow: 0 0 0 3px #d8b77833; }
.chips { gap: 6px; }
.chips button { font-size: 11px; padding: 8px 9px; border-radius: 4px; background: transparent; color: #c9c4b9; }
.chips button.on { background: #d8b77819; color: #e6c78e; }
#joinBtn { font-size: 15px; padding: 14px 8px; }
.join-footnote { text-align: center; font-size: 10px; color: #9a978e; line-height: 1.7; margin: 5px 0 0; }
.hall-brand { position: absolute; top: 22px; left: 25px; display: flex; align-items: center; gap: 12px; font: 500 17px 'Noto Serif KR',serif; color: #ebd6ac; text-shadow: 0 2px 8px #000; }
.hall-brand > span { font-size: 28px; }
.hall-brand small { display: block; font: 9px 'Cormorant Garamond',serif; letter-spacing: .18em; margin-top: 5px; }
.topbar { left: auto; right: 22px; top: 24px; width: auto; transform: none; }
.pill { border-radius: 4px; font-size: 12px; padding: 8px 12px; }
.dot { background: #a9b98c; box-shadow: 0 0 8px #a9b98c66; }
.help { top: 80px; border-radius: 4px; font-size: 11px; }
#chatLog { background: rgba(10,18,26,.78); border-radius: 5px; font-size: 13px; }
.chat-head { color: #d8c196; }
.chat-head button, .emotes, button.big, #toast, #pickBanner { border-radius: 5px; }
.label.me { background: #614a2fdd; }
.wish-head { font: 500 22px 'Noto Serif KR',serif; color: #e5cd9e; }
.note-paper::before { width: 30px; height: 30px; border-radius: 50%; background: #842f3e; border: 3px double #b46465; top: -15px; }
@media (max-width: 900px) { .invitation { gap: 6%; grid-template-columns: 1fr 360px; } .hall-brand { top: 16px; left: 16px; font-size: 14px; } .topbar { top: 70px; right: 12px; left: 12px; } .help { top: 115px; } }
@media (max-width: 640px) {
  #join { padding: 28px 20px; display: block; }
  .invitation { display: flex; flex-direction: column; gap: 28px; max-width: 400px; margin: 0 auto; }
  .invitation-story { text-align: center; } .school-seal { margin: 18px auto; width: 42px; height: 48px; font-size: 24px; }
  h1 { font-size: 28px; line-height: 1.5; } .invitation-kicker { font-size: 11px; }
  .eyebrow { font-size: 10px; } .invitation-desc { font-size: 12px; margin: 16px 0; }
  .invitation-details { justify-content: center; gap: 18px; font-size: 10px; } .invitation-footer { display: none; }
  .join-card { padding: 26px; } .join-title { font-size: 25px; }
  .hall-brand { top: 12px; } .topbar { top: 62px; gap: 5px; } .pill { font-size: 10px; padding: 6px 9px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

@media (max-width: 900px) { .help { display: none; } }

.volume-control { display: flex; align-items: center; gap: 8px; }
.volume-control input { width: 80px; padding: 0; accent-color: var(--gold); cursor: pointer; }
.volume-control output { min-width: 32px; font-size: 11px; font-variant-numeric: tabular-nums; }
button:disabled { opacity: .5; cursor: default; transform: none; }
#pickBanner { max-width: calc(100vw - 24px); width: max-content; flex-wrap: wrap; justify-content: center; top: 120px; font-size: 13px; }
#myWishesList { max-height: 50vh; overflow-y: auto; display: grid; gap: 10px; margin: 20px 0; }
.my-wish-item { display: grid; gap: 8px; text-align: left; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.my-wish-item small { color: #b9ad96; font-size: 11px; }
@media (max-width: 640px) { .volume-control input { width: 60px; } #myWishesBtn { font-size: 11px; padding: 8px; } .actions { flex-wrap: wrap; } #pickBanner { top: 150px; font-size: 12px; } }
.hall-brand { color: #fff6df; background: rgba(6, 13, 23, .88); border: 1px solid rgba(226,199,141,.5); border-radius: 6px; padding: 12px 16px; box-shadow: 0 4px 20px #0005; backdrop-filter: blur(8px); text-shadow: 0 1px 3px #000; }
.hall-brand > span { color: #f1cd7d; }
.hall-brand small { color: #e5d8b8; }
@media (max-width: 900px) { .hall-brand { padding: 8px 12px; } }


#placementGhost { position: fixed; z-index: 16; pointer-events: none; width: 154px; min-height: 144px; max-height: 190px; overflow: hidden; padding: 12px; color: #3d2c00; opacity: .88; border: 1px dashed #725b31; box-shadow: 0 6px 18px #0005; transform: rotate(-2deg); }
#placementGhost small { font-size: 10px; }
#placementGhostText { font: 25px/1.15 'Nanum Pen Script',cursive; margin-top: 10px; overflow-wrap: anywhere; }

/* Keep the audio iframe mounted without changing the hall's layout or focus. */
#musicDock { position: fixed; inset: 0 auto auto 0; width: 356px; height: 200px; z-index: -1; opacity: 0; pointer-events: none; contain: strict; }
#musicDock iframe { display: block; width: 356px; height: 200px; border: 0; }
.hall-brand .placement-hint { margin: 7px 0 0; font: 11px/1.5 'Gowun Dodum',sans-serif; letter-spacing: 0; color: #f6e5ba; }
@media (max-width: 900px) { .hall-brand .placement-hint { font-size: 10px; margin-top: 5px; } .topbar { top: 102px; } .help { top: 152px; } }
@media (max-width: 640px) { .topbar { top: 98px; } }
#wishView { padding: 28px 18px; cursor: pointer; }
#wishView .note-paper { width: min(420px, 88vw); min-height: 340px; max-height: 82dvh; aspect-ratio: auto; gap: 18px; overflow-y: auto; padding: 32px; }
#wishView .note-text { font-size: clamp(30px, 5vw, 42px); line-height: 1.3; word-break: keep-all; overflow-wrap: anywhere; }
.note-dismiss { font: 11px/1.5 'Gowun Dodum',sans-serif; text-align: center; opacity: .65; }
/* A small illustrated gift sits beside the hall, clear of chat and actions. */
.christmas-shop { position: absolute; top: 46%; right: 20px; width: 160px; transform: translateY(-50%); text-align: center; }
.christmas-shop a { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 7px 11px; border: 1px solid rgba(230,201,145,.35); border-radius: 18px; color: #f6dfb1; background: linear-gradient(145deg,rgba(26,45,44,.95),rgba(10,20,29,.93)); box-shadow: 0 12px 30px #0005,inset 0 1px 0 #fff1; text-decoration: none; transition: transform .2s,border-color .2s; }
.shop-eyebrow { font: 8px/1.5 'Gowun Dodum',sans-serif; letter-spacing: .12em; color: #cfb98c; }
.christmas-shop img { display: block; width: 132px; height: 132px; margin: -5px 0; transition: transform .2s; }
.shop-title { font-size: 11px; line-height: 1.6; font-weight: bold; }
.christmas-shop a:hover { transform: translateY(-3px); border-color: #e9cc8d; }
.christmas-shop a:hover img { transform: rotate(-4deg) scale(1.04); }
.christmas-shop a:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }
.christmas-shop small { display: block; margin: 7px 2px 0; padding: 4px; border-radius: 5px; background: #0a1420d9; color: #d5ccbd; font-size: 10px; line-height: 1.5; }
@media (max-width: 640px) { .christmas-shop { top: 38%; right: 12px; width: 116px; } .christmas-shop a { padding: 9px 5px; border-radius: 14px; } .christmas-shop img { width: 88px; height: 88px; } .shop-eyebrow { font-size: 6px; } .shop-title { font-size: 10px; } .christmas-shop small { font-size: 9px; margin-top: 5px; } }

.wish-invitation { display: block; margin-bottom: 4px; font: 11px/1.5 'Gowun Dodum',sans-serif; color: #4b351b; letter-spacing: .02em; }
@media (max-width: 640px) { .wish-invitation { font-size: 10px; margin-bottom: 2px; } }
/* Fit both browser chrome and the on-screen keyboard on phones. */
#hud { bottom: auto; height: var(--app-height, 100dvh); }
.overlay, #wishView { bottom: auto; height: var(--app-height, 100dvh); }
.wish-card { max-height: calc(var(--app-height, 100dvh) - 32px); overflow-y: auto; }
.joystick-label { position: absolute; top: calc(100% + 5px); width: 100%; text-align: center; color: #f4dfb4; font-size: 11px; pointer-events: none; }
.touch-guide { display: none; }
@media (max-width: 640px) {
  #join { padding: calc(20px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); }
  .invitation { gap: 18px; margin: auto; }
  .invitation-story { padding: 0; }
  .school-seal { margin: 10px auto; }
  .invitation-story h1 { font-size: 24px; line-height: 1.45; }
  .invitation-desc { margin: 12px 0; }
  .join-card { padding: 22px; width: 100%; }
  input, textarea, #nameInput, #chatInput { font-size: 16px; }
  #joinBtn, #chatForm button, .actions button, #pickBanner button { min-height: 44px; }
  .hall-brand { top: calc(10px + env(safe-area-inset-top)); left: 12px; padding: 7px 10px; }
  .hall-brand .placement-hint { margin-top: 4px; }
  .topbar { top: calc(94px + env(safe-area-inset-top)); left: 12px; right: 12px; gap: 5px; justify-content: flex-start; }
  .pill { font-size: 10px; padding: 7px 8px; }
  .volume-control { gap: 6px; }
  .volume-control input { width: 76px; min-height: 24px; }
  #joystick { display: block; top: max(182px, 32%); left: 16px; right: auto; width: 88px; height: 88px; touch-action: none; }
  #joystick .stick { width: 40px; height: 40px; margin: -20px 0 0 -20px; }
  .touch-guide { display: block; position: absolute; top: max(300px, calc(32% + 118px)); left: 12px; width: 150px; font-size: 10px; line-height: 1.6; color: #e5d3b4; text-shadow: 0 1px 4px #000; pointer-events: none; }
  .christmas-shop { top: max(182px, 32%); transform: none; width: 104px; }
  .christmas-shop img { width: 72px; height: 72px; }
  .christmas-shop .shop-eyebrow { display: none; }
  .christmas-shop .shop-title { font-size: 10px; }
  .christmas-shop small { font-size: 9px; }
  .actions { display: grid; grid-template-columns: 1fr 1.3fr; left: 12px; right: 12px; bottom: calc(10px + env(safe-area-inset-bottom)); gap: 6px; align-items: stretch; }
  .emotes { grid-column: 1 / -1; max-width: 100%; width: 100%; display: flex; justify-content: space-between; overflow-x: auto; padding: 2px 4px; }
  .emotes button { min-width: 36px; min-height: 36px; padding: 3px; font-size: 20px; flex: 0 0 auto; }
  #myWishesBtn, #wishBtn { width: 100%; margin: 0; }
  #myWishesBtn { font-size: 12px; }
  #wishBtn { padding: 8px 6px; font-size: 14px; }
  #stairsBtn, #climbBtn { grid-column: 1 / -1; }
  #chat { left: 12px; right: 12px; width: auto; bottom: calc(128px + env(safe-area-inset-bottom)); gap: 5px; }
  #chatLog { height: min(18dvh, 150px); font-size: 13px; }
  #chat[data-size="big"] #chatLog { height: min(36dvh, 280px); }
  #chatForm { gap: 5px; }
  #chatInput { padding: 10px; width: 0; }
  #chatForm button { padding: 8px 12px; }
  .chat-head button { min-height: 32px; }
  #hud:has(#chat:not([data-size="min"])) .christmas-shop { display: none; }
  #hud:has(#chat[data-size="big"]) #joystick, #hud:has(#chat[data-size="big"]) .touch-guide { display: none; }
  #hud:has(#stairsBtn:not(.hidden)) #chat, #hud:has(#climbBtn:not(.hidden)) #chat { bottom: calc(178px + env(safe-area-inset-bottom)); }
  #hud:has(#stairsBtn:not(.hidden)) .touch-guide, #hud:has(#climbBtn:not(.hidden)) .touch-guide { display: none; }
  #pickBanner { top: calc(168px + env(safe-area-inset-top)); width: calc(100% - 24px); font-size: 12px; padding: 8px; gap: 6px; }
  #pickStatus { width: 100%; text-align: center; }
  body:has(#pickBanner:not(.hidden)) .christmas-shop, body:has(#pickBanner:not(.hidden)) .touch-guide { display: none; }
  #wishView .note-paper { min-height: min(300px, calc(var(--app-height, 100dvh) * .7)); max-height: calc(var(--app-height, 100dvh) * .82); padding: 26px 22px; }
}
@media (max-height: 500px) and (max-width: 950px) and (pointer: coarse) {
  .hall-brand { top: 8px; left: 8px; font-size: 12px; padding: 5px 8px; }
  .hall-brand small, .hall-brand .placement-hint, .christmas-shop, .touch-guide { display: none; }
  .topbar { top: 8px; left: 230px; right: 8px; }
  #joystick { display: block; top: auto; bottom: 28px; left: 16px; right: auto; width: 82px; height: 82px; }
  #chat { left: 116px; width: 270px; bottom: 12px; }
  #chatLog { height: 80px; }
  #chat[data-size="big"] #chatLog { height: 140px; }
  .actions { right: 10px; bottom: 10px; left: auto; max-width: 300px; }
  .emotes { max-width: 300px; }
}
@media (max-width: 640px) {
  #pickBanner { top: auto; bottom: calc(16px + env(safe-area-inset-bottom)); }
  body:has(#pickBanner:not(.hidden)) #hud { display: none; }
  .touch-guide { background: #0a1420a6; border-radius: 5px; padding: 4px 6px; }
}
.visitor-totals { display: flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums; }
.visitor-totals > span { opacity: .5; }
@media (min-width: 901px) { .topbar { max-width: calc(100% - 320px); } }
@media (max-width: 360px) { .topbar #countdown { display: none; } }
/* iOS can pan the visual viewport as well as shrinking it for the keyboard. */
#hud, .overlay, #wishView { top: var(--app-top, 0px); }
.keyboard-open #hud > :not(#chat) { display: none !important; }
.keyboard-open #hud #chat { bottom: 8px !important; left: 12px; right: 12px; width: auto; max-width: 560px; }
.keyboard-open #chatLog { max-height: max(40px, calc(var(--app-height) - 120px)); }
.keyboard-open #chat[data-size="big"] #chatLog,
.keyboard-open #chat[data-size="normal"] #chatLog { height: min(160px, calc(var(--app-height) - 120px)); }
.keyboard-open #chatInput { font-size: 16px; min-height: 44px; }
/* Keep the nickname field in the same layout while the browser opens its keyboard. */
#join { overflow-anchor: none; scroll-behavior: auto; overscroll-behavior: contain; }
@media (max-width: 640px), (pointer: coarse) {
  #join { display: block; }
  #nameInput { font-size: 16px; }
}
.keyboard-open #wishModal { padding: 12px; }
.keyboard-open #wishModal .wish-card { padding: 18px; max-height: calc(var(--app-height) - 24px); overscroll-behavior: contain; }
.keyboard-open #wishModal .wish-head { font-size: 18px; margin-bottom: 10px; }
.keyboard-open #wishText { height: clamp(56px, calc(var(--app-height) * .24), 100px); font-size: 22px; }
.keyboard-open #wishModal .hint { display: none; }
.keyboard-open #wishModal .row.end { position: sticky; bottom: -18px; padding: 8px 0; background: #111e27; z-index: 1; }
.keyboard-open #bubbles, .keyboard-open #noteTip { display: none; }
