:root {
  --bg: #151a26;
  --bar: #1c2232;
  --line: rgba(255, 255, 255, .12);
  --text: #f1ede2;
  --muted: #b5bccb;
  --accent: #f5c84c;
  --accent-ink: #2a2110;
  --chip: rgba(22, 27, 40, .72);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font-family: "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }

#app {
  height: 100dvh;
  display: grid;
  grid-template-rows: 1fr auto;
}

#stage { position: relative; min-height: 0; overflow: hidden; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#cv:active { cursor: grabbing; }

#top {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 4px;
  pointer-events: none;
}
#top > * { pointer-events: auto; }
.chip {
  background: var(--chip); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; font-size: 14px; cursor: pointer; backdrop-filter: blur(6px);
}
.period {
  font-size: 14px; color: var(--muted); white-space: nowrap; background: var(--chip);
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; backdrop-filter: blur(6px);
}
.period b { color: var(--text); font-variant-numeric: tabular-nums; margin-left: 4px; }
.icon {
  background: var(--chip); border: 1px solid var(--line); border-radius: 12px;
  width: 38px; height: 34px; cursor: pointer; font-size: 16px; backdrop-filter: blur(6px);
}
.icon.small { width: 32px; height: 30px; font-size: 14px; }

#sub {
  position: absolute; left: 16px; right: 16px; top: calc(56px + env(safe-area-inset-top));
  display: flex; gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted);
  text-shadow: 0 1px 3px rgba(0, 0, 0, .7); pointer-events: none;
}
#sub b { color: var(--text); font-variant-numeric: tabular-nums; }
#globalCount { margin-left: auto; }

#hint {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); margin: 0;
  font-size: 12px; color: var(--muted); background: var(--chip); padding: 5px 10px; border-radius: 999px;
  transition: opacity .6s; pointer-events: none;
}
#hint.gone { opacity: 0; }

#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.bub {
  position: absolute; transform: translate(-50%, -100%); white-space: nowrap;
  background: #fffdf6; color: #2a2622; font-weight: 700; font-size: 15px;
  padding: 7px 13px; border-radius: 999px; box-shadow: 0 4px 14px rgba(0, 0, 0, .3);
}
.bub::after {
  content: ""; position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: #fffdf6; border-bottom: 0;
}
.tag {
  position: absolute; transform: translate(-50%, -100%); white-space: nowrap;
  background: rgba(20, 24, 34, .85); color: var(--text); font-size: 12px; font-weight: 600;
  padding: 4px 9px; border-radius: 999px;
}
.zz {
  position: absolute; transform: translate(-50%, -100%); font-weight: 800; color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .6); font-size: 15px; animation: zz 1.8s infinite;
}
@keyframes zz { 0% { opacity: 0; translate: 0 6px; } 30% { opacity: 1; } 100% { opacity: 0; translate: 10px -16px; } }
.heart {
  position: absolute; color: #ff7b93; font-size: 20px; animation: heart 1.6s forwards;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}
@keyframes heart { from { opacity: 1; translate: 0 0; } to { opacity: 0; translate: 0 -60px; } }

#sleepShade {
  position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .8s;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, .35), rgba(0, 0, 0, .85));
}
#sleepShade.on { opacity: 1; }

#ctrl {
  display: grid; grid-template-columns: 1.5fr repeat(5, 1fr); gap: 6px;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); background: var(--bar);
  border-top: 1px solid var(--line);
}
#ctrl button {
  background: #262e42; border: 1px solid var(--line); border-radius: 14px;
  min-height: 50px; padding: 4px 2px; font-size: 12.5px; cursor: pointer; line-height: 1.25;
}
#ctrl button:active { transform: translateY(1px); }
#ctrl button:disabled { opacity: .38; }
.primary {
  background: var(--accent) !important; color: var(--accent-ink) !important;
  border-color: transparent !important; font-weight: 700;
}
#studyBtn.on { background: #3b4a3c !important; color: #d9f2d5 !important; }

#toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(12px);
  background: rgba(20, 24, 34, .94); border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; max-width: calc(100vw - 32px); text-align: center; z-index: 5;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

#intro {
  position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; justify-content: space-between;
  padding: calc(28px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
  background:
    linear-gradient(to bottom, rgba(8, 10, 18, .78) 0%, rgba(8, 10, 18, 0) 34%),
    linear-gradient(to top, rgba(8, 10, 18, .92) 0%, rgba(8, 10, 18, .55) 38%, rgba(8, 10, 18, 0) 62%);
}
#intro.hide { display: none; }
.intro-top, .intro-bottom { width: min(460px, 100%); margin: 0 auto; }
.kicker { margin: 0; color: var(--accent); font-size: 14px; letter-spacing: .08em; font-weight: 700; }
#intro h1 {
  margin: 6px 0 6px; font-size: clamp(48px, 13vw, 76px); line-height: 1; letter-spacing: -0.04em; font-weight: 900;
  color: #fff7df; text-shadow: 0 0 24px rgba(255, 214, 120, .35), 0 4px 18px rgba(0, 0, 0, .6);
}
.lead { margin: 0; font-size: 17px; color: #efe9da; text-shadow: 0 2px 8px rgba(0, 0, 0, .7); }
.live {
  display: inline-block; margin: 14px 0 0; padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 700;
  background: rgba(245, 200, 76, .16); color: var(--accent); border: 1px solid rgba(245, 200, 76, .35);
}
.how { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 8px; }
.how li { display: flex; gap: 10px; align-items: center; font-size: 14px; color: #e3ddcf; text-shadow: 0 1px 6px rgba(0, 0, 0, .8); }
.how span { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 10px; background: rgba(255, 255, 255, .1); flex: none; }
.me {
  display: flex; align-items: center; gap: 8px; background: rgba(38, 46, 66, .85);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; border: 1px solid var(--line);
}
.me span { color: var(--muted); }
.me b { flex: 1; }
.big { width: 100%; min-height: 56px; border-radius: 16px; border: 0; font-size: 18px; cursor: pointer; box-shadow: 0 8px 30px rgba(245, 200, 76, .3); }
.fine { margin: 10px 0 0; color: var(--muted); font-size: 12px; text-align: center; }

#seatBar {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 6;
  width: min(420px, calc(100vw - 32px)); background: rgba(20, 24, 34, .92); border: 1px solid var(--line);
  border-radius: 16px; padding: 12px; text-align: center; backdrop-filter: blur(6px);
}
#seatBar.hide { display: none; }
#seatBar p { margin: 0 0 10px; font-size: 14px; color: var(--muted); }
#seatBar p b { color: var(--text); }
#seatBar button { width: 100%; min-height: 46px; border-radius: 12px; border: 0; font-size: 16px; cursor: pointer; }

@media (max-width: 380px) {
  #ctrl button { font-size: 11.5px; }
  .period { font-size: 12.5px; }
}

/* 교실에 들어가기 전에는 상단 정보와 버튼을 숨긴다 */
body:not(.in) #top, body:not(.in) #sub, body:not(.in) #hint, body:not(.in) #ctrl { visibility: hidden; }

/* 다혈질 선생님이 소리칠 때 */
.bub.hot {
  background: #d93a2f; color: #fff; font-size: 17px; font-weight: 900;
  animation: shout .12s infinite alternate; box-shadow: 0 0 0 3px rgba(255, 255, 255, .6), 0 6px 20px rgba(217, 58, 47, .5);
}
.bub.hot::after { border-top-color: #d93a2f; }
@keyframes shout { from { translate: -1.5px 0; } to { translate: 1.5px 0; } }
.tang { position: absolute; transform: translate(-50%, -50%); font-size: 26px; animation: tang .5s infinite alternate; }
@keyframes tang { from { scale: .85; } to { scale: 1.15; } }
