/* ==========================================================================
   Little Heaven (#/cosytown) — RPG 3D ấm cúng luyện IELTS, nhúng IFRAME cùng origin
   (/cosytown/). Mọi luật nằm dưới .ct-root; full-bleed bằng lề âm huỷ padding của
   .view; chiều cao trừ chrome app theo đúng các con số css/catcafe.css đã chép
   (60px thanh trên / 56px thanh tab).

   File này CỐ Ý ngắn: game có CSS RIÊNG bên trong iframe (cosytown/css/style.css).
   Ba luật: mọi selector bắt đầu bằng .ct-; không luật nào trên :root; không khai
   lớp xếp chồng nào (trần của repo là 70).
   ========================================================================== */
.ct-root {
  --ct-bg: #e9f5e1;
  margin: -18px -16px -64px;
  background: var(--ct-bg);
}

/* .view-wide có padding 0 0 64px ⇒ ba lề âm về 0, giữ lề đáy. */
.ct-root:is(.view-wide *) { margin-top: 0; margin-left: 0; margin-right: 0; }

.ct-root #ctApp {
  position: relative;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 60px);              /* Safari cũ không hiểu dvh — đường lùi */
  height: calc(100dvh - 60px);
  min-height: 320px;
  overflow: hidden;
}

.ct-root #ctStage {
  position: relative;
  flex: 1;
  min-height: 0;
  overscroll-behavior: none;
}

.ct-root #ctFrame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: var(--ct-bg);
}

/* ---- khổ điện thoại: thêm 56px thanh tab dưới ---- */
@media (max-width: 719px) {
  .ct-root #ctApp { height: calc(100vh - 124px); }
  .ct-root #ctApp {
    height: calc(100dvh - 60px - 56px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
}

/* ---- body.s8-play: thanh tab dưới đã ẩn ⇒ trả lại 56px ---- */
@media (max-width: 979px) {
  .ct-root:is(body.s8-play *) { margin-bottom: 0; }
}
@media (max-width: 719px) {
  .ct-root:is(body.s8-play *) #ctApp {
    height: calc(100dvh - 60px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
}

/* ---- body.s8-imm: thanh trên cũng đi ⇒ trả lại nốt 60px ---- */
.ct-root:is(body.s8-play.s8-imm *) { padding-top: env(safe-area-inset-top); }
.ct-root:is(body.s8-play.s8-imm *) #ctApp {
  height: calc(100vh - env(safe-area-inset-top));
  height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}

/* Nhường góc trên-phải cho nút thoát ⤢ của vỏ app (48px nút + 8px lề); khai thẳng bề rộng vì
   width:auto trên iframe rơi về 300px. */
@media (min-width: 720px) {
  .ct-root:is(body.s8-play.s8-imm *) #ctFrame {
    width: calc(100% - env(safe-area-inset-right) - 56px);
  }
}
@media (max-width: 719px) {
  .ct-root:is(body.s8-play.s8-imm *) #ctApp {
    height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
  .ct-root:is(body.s8-play.s8-imm *) #ctFrame {
    width: 100%;
    top: 56px;
    height: calc(100% - 56px);
  }
}

/* ---- lớp nói với người dân (#ctSpeak, js/cosytown/overlay.js) ----------------------------------------
   Anh em của #ctStage, phủ cả khung game: nền mờ chặn chạm xuống game, tờ giấy trượt từ đáy. Để trống
   ~20% trên cùng cho bong bóng lời thoại của Mr. Finch trong iframe. Nút dùng .btn của app. */
.ct-root #ctSpeak {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(40, 32, 48, 0.28);
}
.ct-root #ctSpeak[hidden] { display: none; }
.ct-root .ct-say-card {
  box-sizing: border-box;
  width: min(100%, 520px);
  max-height: 78%;
  overflow-y: auto;
  padding: 16px 18px calc(18px + env(safe-area-inset-bottom));
  border-radius: 22px 22px 0 0;
  background: #fffaf0;
  color: #4a3f55;
  box-shadow: 0 -8px 24px rgba(74, 63, 85, 0.18);
  animation: ct-say-rise 0.2s ease-out;
  position: relative;
}
/* "Để sau" lúc đang xin mic: chữ nhỏ ở góc trên phải, xa chỗ nút "Bắt đầu nói" vừa nằm. */
.ct-root .ct-say-x {
  position: absolute;
  top: 8px;
  right: 10px;
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 14px;
  opacity: 0.7;
  text-decoration: underline;
  cursor: pointer;
}
@keyframes ct-say-rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.ct-root .ct-say-lead { margin: 0 0 2px; font-size: 16px; line-height: 1.45; }
.ct-root .ct-say-gloss { margin: 0 0 10px; font-size: 14px; line-height: 1.4; font-style: italic; opacity: 0.7; }
.ct-root .ct-say-capped { color: #8a6a2f; }
.ct-root .ct-say-who { margin: 0; font-size: 13px; opacity: 0.7; }
.ct-root .ct-say-q { margin: 2px 0 10px; font-size: 18px; font-weight: 700; line-height: 1.4; }
.ct-root .ct-say-label { margin: 10px 0 6px; font-size: 14px; opacity: 0.8; }
.ct-root .ct-say-note { margin: 10px 0; font-size: 15px; line-height: 1.45; }
.ct-root .ct-say-line { margin: 18px 0; font-size: 16px; text-align: center; }
.ct-root .ct-say-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ct-root .ct-chip {
  padding: 5px 12px;
  border-radius: 999px;
  background: #e3f1d9;
  color: #2f5d2a;
  font-size: 15px;
  font-weight: 600;
}
.ct-root .ct-say-starters { margin: 0; padding-left: 20px; font-size: 15px; line-height: 1.6; font-style: italic; }
.ct-root .ct-say-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.ct-root .ct-say-btns .btn { flex: 1 1 140px; min-height: 48px; }
.ct-root .ct-say-rec { display: flex; align-items: center; gap: 10px; margin: 6px 0; font-size: 26px; }
.ct-root .ct-say-goal { margin-left: -6px; font-size: 16px; opacity: 0.7; }
.ct-root .ct-say-dot { width: 12px; height: 12px; border-radius: 50%; background: #d9534f; animation: ct-say-blink 1s infinite; }
@keyframes ct-say-blink { 50% { opacity: 0.25; } }
.ct-root .ct-say-lvl { flex: 1; height: 8px; border-radius: 4px; background: #efe6d6; overflow: hidden; }
.ct-root .ct-say-lvl i { display: block; width: 0; height: 100%; background: #f4b393; transition: width 0.2s; }
.ct-root .ct-say-hint { margin: 4px 0 10px; font-size: 14px; opacity: 0.8; }
.ct-root .ct-say-score { margin: 4px 0; text-align: center; }
.ct-root .ct-say-score b { font-size: 40px; }
.ct-root .ct-say-score small { font-size: 16px; opacity: 0.7; }
.ct-root .ct-say-crit { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 6px 0; padding: 0; list-style: none; }
.ct-root .ct-say-crit li { display: flex; justify-content: space-between; padding: 6px 10px; border-radius: 10px; background: #fff; font-size: 14px; }
.ct-root .ct-say-verdict { margin: 4px 0; font-size: 28px; font-weight: 800; text-align: center; }
.ct-root .ct-say-ok { color: #3f8a3a; }
.ct-root .ct-say-no { color: #b8473f; }
.ct-root .ct-say-text { margin: 10px 0; padding: 10px 12px; border-radius: 12px; background: #fff; font-size: 15px; line-height: 1.5; }
.ct-root .ct-say-text mark { padding: 0 2px; border-radius: 4px; background: #ffe39a; color: inherit; }
.ct-root .ct-say-coins { margin: 6px 0; font-weight: 700; color: #b7791f; }
