/* The students' page: one team on one tablet, laptop or phone. */

#app { height: 100%; overflow: hidden; position: relative; }
.screen { display: none; position: absolute; inset: 0; }
#app[data-screen="loading"] #loading,
#app[data-screen="story"] #story,
#app[data-screen="house"] #house,
#app[data-screen="locked"] #locked { display: flex; }

h1, h2 { font-family: var(--title); font-weight: 400; margin: 0; }

/* ---------- Loading ---------- */
#loading {
  flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  padding: 20px; text-align: center;
  background: radial-gradient(ellipse at 50% 30%, var(--night-2), var(--night) 70%);
}
#loading h1 { font-size: clamp(28px, 6vw, 60px); color: var(--gold-soft); text-shadow: 0 3px 0 #000; }
.bar { width: min(420px, 80vw); height: 14px; border: 2px solid var(--gold); border-radius: 8px; overflow: hidden; }
#loadbar { height: 100%; width: 0; background: var(--gold); transition: width .2s; }

/* ---------- Story ---------- */
#story {
  align-items: center; justify-content: center; padding: 16px;
  background: url("../img/intro-hill.webp?v=2") center / cover no-repeat;
}
.paper {
  background: var(--paper);
  color: var(--ink);
  border: 6px solid var(--wood);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .7);
  padding: clamp(14px, 3vw, 30px);
  max-width: 760px;
  max-height: 100%;
  overflow: auto;
}
.paper h1 { font-size: clamp(24px, 4.5vw, 40px); color: var(--wood); text-align: center; margin-bottom: 10px; }
.go { text-align: center; margin: 16px 0 0; }

/* ---------- Sentences with a Korean button ---------- */
.lines { display: flex; flex-direction: column; gap: 6px; }
.line { margin: 0; font-size: clamp(17px, 2.4vw, 23px); font-weight: 600; line-height: 1.35; }
.line .ko-btn {
  margin-left: 6px; border: 2px solid #b48a3a; background: #fff6dc; color: #6a4312;
  border-radius: 8px; font-size: .75em; font-weight: 900; padding: 0 .45em; vertical-align: 2px;
}
.line .ko { display: block; color: #1f5e8a; font-weight: 800; font-size: .92em; }
.line .ko[hidden] { display: none; }

/* ---------- The house ---------- */
#house { flex-direction: column; background: #000; }
#bar {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; flex: 0 0 auto;
  background: linear-gradient(#2b190c, #1a0f07); border-bottom: 3px solid var(--wood-light);
  font-size: clamp(13px, 1.8vw, 18px);
}
#bar .btn { padding: .35em .8em; border-radius: 10px; border-width: 2px; }
#roomName { flex: 1; font-family: var(--title); font-size: 1.5em; color: var(--gold-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--gold); color: var(--ink); font-weight: 900; border-radius: 10px; padding: .25em .6em; white-space: nowrap; }
.ko-badge { background: #cfe3f5; color: #123a5a; }
.ko-badge.out { background: #f6d2cc; color: #8a1f12; }
.hints { margin: 0 0 10px; }
.sheet > .hint-count { position: absolute; top: 12px; right: 58px; font-size: clamp(13px, 1.8vw, 17px); z-index: 2; }
@media (max-width: 640px), (max-aspect-ratio: 1/1) {
  /* Pop-ups stack on a phone or an upright tablet, so the count gets its own row instead of sitting on the picture. */
  .sheet > .hint-count { position: static; display: inline-block; grid-column: 1 / -1; justify-self: start; margin-bottom: 8px; }
}
#stageWrap { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; transition: opacity .14s ease; }
#stageWrap.out { opacity: 0; }

/* The map and a room share the stage: tap a place to go there, Map to come back. */
#house[data-view="map"] #scene, #house[data-view="map"] #toMap { display: none; }
#house[data-view="room"] #estateWrap { display: none; }
#toMap { flex: 0 0 auto; font-size: 1.1em; }
#estateWrap { position: absolute; inset: 6px; display: flex; align-items: center; justify-content: center; }
#estate .cell { cursor: pointer; }
#estate .cell:hover, #estate .cell:focus-visible { box-shadow: inset 0 0 0 3px var(--gold-soft); outline: none; background: rgba(255, 235, 170, .16); }
#estate .cell:active { background: rgba(255, 235, 170, .32); }
#estate .cell.seen .label::after { content: ' ✓'; color: #9fe39f; }
#scene {
  position: relative;
  aspect-ratio: 1664 / 928;
  width: 100%;
  max-height: 100%;
  container-type: inline-size;
}
@media (min-aspect-ratio: 1664/1000) { #scene { width: auto; height: 100%; } }
#roomImg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#hots { position: absolute; inset: 0; }

.clue-spot {
  /* Every clue glows faintly and slowly from the start. After 10 s in a room without a tap, the first
     clue not looked at yet pulses brighter (.hint). */
  position: absolute; transform: translate(-50%, -50%);
  border-radius: 50%; border: none; padding: 0;
  background: radial-gradient(closest-side, rgba(255, 244, 200, .85), rgba(255, 226, 140, .4) 45%, rgba(255, 226, 140, 0));
  mix-blend-mode: screen;
  animation: faint 4.5s ease-in-out infinite;
}
.clue-spot.hint { animation: pulse 2.4s ease-in-out infinite; }
@keyframes faint { 0%, 100% { opacity: .12; } 50% { opacity: .38; } }
@keyframes pulse { 0%, 100% { opacity: .45; } 50% { opacity: 1; } }

.suspect {
  position: absolute; bottom: 2%;
  transform: translateX(-50%);
  border: none; background: none; padding: 0;
}
.suspect img { position: relative; height: 100%; display: block; }
/* A soft shadow on the floor, so a figure stands in the room rather than on top of the picture. */
.suspect::before {
  content: ''; position: absolute; left: 50%; bottom: -2.5%; width: 110%; height: 7%; transform: translateX(-50%);
  background: radial-gradient(closest-side, rgba(0, 0, 0, .55), rgba(0, 0, 0, 0));
}
.suspect .talk-hint {
  position: absolute; top: -2%; left: 50%; transform: translate(-50%, -100%);
  background: #fff; color: var(--ink); border-radius: 14px; padding: .1em .5em;
  font-size: clamp(14px, 2.2cqw, 28px); font-weight: 900; white-space: nowrap;
  animation: bob 1.6s ease-in-out infinite;
}
.suspect.heard .talk-hint { animation: none; opacity: .75; }
@keyframes bob { 50% { transform: translate(-50%, -112%); } }

/* ---------- Pop-ups ---------- */
.modal {
  position: absolute; inset: 0; z-index: 20;
  background: rgba(0, 0, 0, .65);
  display: flex; align-items: center; justify-content: center; padding: 12px;
}
.modal[hidden] { display: none; }
.sheet {
  position: relative;
  background: var(--paper); color: var(--ink);
  border: 6px solid var(--wood); border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .7);
  padding: clamp(12px, 2.5vw, 26px);
  max-width: 980px; width: 100%; max-height: 100%; overflow: auto;
}
.sheet h2 { font-size: clamp(22px, 3.4vw, 36px); color: var(--wood); }
.close {
  position: absolute; top: 8px; right: 8px; width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid var(--wood); background: var(--paper-dark); color: var(--wood); font-size: 22px; font-weight: 900;
}
.talk { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; align-items: start; }
.talk .face { width: clamp(90px, 14vw, 150px); height: auto; aspect-ratio: 1; grid-row: span 2; }
.talk .role { margin: 0; font-weight: 800; color: #6b4a2a; font-size: clamp(15px, 2vw, 20px); }
.talk .lines { grid-column: 2; }
.talk .item { grid-column: 1 / 3; text-align: center; margin: 8px 0 0; }
.talk .item:empty { display: none; }
@media (max-width: 560px) {
  .talk { grid-template-columns: 1fr; }
  .talk .face { grid-row: auto; margin: 0 auto; }
  .talk .lines, .talk .item { grid-column: 1; }
}
.clue { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: center; }
.clue .pic { width: 100%; border-radius: 10px; border: 4px solid var(--wood); display: block; }
.picwrap { position: relative; container-type: inline-size; }
.clue h2 { margin-bottom: 8px; }
.clue .words { font-family: 'Courier New', monospace; }
@media (max-aspect-ratio: 1/1) { .clue { grid-template-columns: 1fr; } .clue .pic { max-width: 380px; margin: 0 auto; } }

.notes-body { display: flex; gap: 16px; align-items: flex-start; margin-top: 10px; }
#notePlan { flex: 1 1 auto; min-width: 0; max-width: calc((100vh - 130px) * var(--ratio, 1.5)); }
#notePlan .face, #tray .face { width: clamp(34px, 5.5vw, 54px); height: auto; aspect-ratio: 1; touch-action: none; cursor: grab; }
#tray {
  flex: 0 0 auto; display: grid; grid-template-columns: repeat(2, auto); gap: 8px;
  padding: 10px; border: 3px dashed #a78756; border-radius: 12px; min-width: 130px; min-height: 120px;
}
#tray .tok, #notePlan .tok { display: flex; flex-direction: column; align-items: center; font-size: 12px; font-weight: 800; color: var(--ink); }
#notePlan .tok span { display: none; }
.tok.picked .face { border-color: var(--red); box-shadow: 0 0 0 3px var(--gold); }
.drag-ghost { position: fixed; z-index: 50; pointer-events: none; transform: translate(-50%, -50%) scale(1.15); }
.plan .cell.drop { box-shadow: inset 0 0 0 4px #7be07b; }
@media (max-width: 640px) { .notes-body { flex-direction: column; align-items: center; } #tray { grid-template-columns: repeat(6, auto); } }

#pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 12px 0; }
#pick button {
  border: 4px solid transparent; border-radius: 14px; background: var(--paper-dark);
  display: flex; flex-direction: column; align-items: center; padding: 8px; font-weight: 900; color: var(--ink);
  font-size: clamp(15px, 2.2vw, 22px);
}
#pick .face { width: clamp(70px, 12vw, 120px); height: auto; aspect-ratio: 1; }
#pick button.chosen { border-color: var(--red); background: #ffe1a0; }
#pick button.chosen .face { border-color: var(--red); }
#lockIn:disabled { opacity: .45; }

/* ---------- Locked in: big enough for the teacher to read from the front ---------- */
#locked {
  flex-direction: column; align-items: center; justify-content: center; gap: 2vh; text-align: center;
  background: radial-gradient(ellipse at 50% 40%, #5a1416, #1a0505 75%);
}
.we { font-size: clamp(22px, 4vw, 40px); font-weight: 900; margin: 0; }
#lockedFaces { display: flex; gap: 3vw; flex-wrap: wrap; justify-content: center; }
#lockedFaces div { display: flex; flex-direction: column; align-items: center; font-weight: 900; font-size: clamp(20px, 3.4vw, 38px); }
#lockedFaces .face { width: clamp(110px, 20vw, 220px); height: auto; aspect-ratio: 1; border-color: var(--gold); }
#unlock { margin-top: 2vh; }

/* A phone held upright gets a small room picture: suggest turning it. */
@media (orientation: portrait) and (max-width: 700px) {
  #house[data-view="room"] #stageWrap { flex-direction: column; }
  #house[data-view="room"] #stageWrap::after { content: '↻ Turn your phone sideways'; color: #d8c3a0; font-weight: 800; margin-top: 14px; }
  #roomName { display: none; }
}
