body:has(.ht-forest-game) {
  display: block;
  min-height: 0;
  overflow: hidden;
  background: #f9f2e3;
}
body:has(.ht-forest-game) .ht-student-top { display: contents; }
body:has(.ht-forest-game) #ht-header { display: none; }
body:has(.ht-forest-game) #ht-fullscreen {
  position: absolute;
  top: 12px;
  right: clamp(.55rem, 2.3vw, 1.35rem);
  z-index: 2;
  width: 44px;
  min-height: 44px;
  justify-content: center;
  margin: 0;
  padding: 0;
  border: 1px solid #537029;
  border-radius: .65rem;
  background: #fff9e5;
  color: #365021;
  font-size: 0;
}
body:has(.ht-forest-game) #ht-fullscreen::after { content: "⤢" / ""; font-size: 1.35rem; }
body:has(.ht-forest-game) #ht-fullscreen[aria-pressed="true"]::after { content: "⤡" / ""; }
body[data-hanja-role="student"]:has(.ht-forest-game) #ht-main {
  padding: 0;
  min-height: 0;
  height: var(--ht-visible-height, 100dvh);
  overflow: hidden;
}
.ht-forest-game {
  --forest-ink: #263b14;
  --forest-pad: min(38vw, max(14rem, calc(var(--ht-visible-height, 100dvh) - 248px)), 27rem);
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  padding: .52rem clamp(.6rem, 2.1vw, 1.55rem) max(.8rem, env(safe-area-inset-bottom));
  color: var(--forest-ink);
  background: #f9f2e3 url("/assets/hanja-tree/forest-trail.webp") left bottom / cover no-repeat;
}
.ht-forest-bar {
  display: grid;
  grid-template-columns: 1fr auto 1.45fr;
  align-items: center;
  gap: clamp(.55rem, 3vw, 2.6rem);
  min-height: 54px;
  margin: 0 0 9px;
  padding-right: 68px;
}
.ht-forest-bar h1 { margin: 0; font-size: clamp(1.26rem, 3.45vw, 2.15rem); white-space: nowrap; }
.ht-forest-bar h1 button { border: 0; padding: 0 .35rem; min-height: 44px; background: none; color: inherit; font-weight: 900; }
.ht-forest-leaf { margin: 0 .32em 0 .1em; vertical-align: .025em; background: linear-gradient(130deg, #aec44b, #638117); }
.ht-forest-wave, .ht-forest-bar dl div {
  display: flex;
  align-items: center;
  gap: .55rem;
  width: max-content;
  border: 1px solid #b7bb75;
  border-radius: 99px;
  background: #fff9e388;
  padding: .15rem .7rem;
  box-shadow: 0 2px 3px #6b5c2121;
  white-space: nowrap;
}
.ht-forest-wave { font-size: clamp(.85rem, 2vw, 1.18rem); }
.ht-forest-wave span { display: flex; gap: .23rem; }
.ht-forest-wave i { width: .68em; aspect-ratio: 1; border: 1px solid #adb765; border-radius: 50%; background: #e5e4aa; }
.ht-forest-wave .is-past { background: #789b26; border-color: #668420; }
.ht-forest-wave .is-current { background: #c5d87d; border-color: #839c31; }
.ht-forest-bar dl { display: flex; justify-content: flex-end; gap: clamp(.25rem, 1.6vw, .95rem); margin: 0; }
.ht-forest-bar dt { font-size: clamp(.75rem, 1.6vw, 1rem); font-weight: 800; }
.ht-forest-bar dd { font-size: clamp(1.1rem, 2.9vw, 1.75rem); font-weight: 900; line-height: 1; margin: 0; font-variant-numeric: tabular-nums; }
.ht-forest-lives dd { display: flex; gap: .15em; color: #c63832; }
.ht-forest-lives .is-empty { color: #922d2d; }
.ht-forest-clock { position: absolute; top: 68px; right: 1.6rem; padding: .15rem .6rem; background: #f7e8bb; border-radius: .7rem; font-weight: 750; }
.ht-forest-prompt > span {
  display: inline-block;
  border-radius: .55rem;
  color: #fffdf3;
  background: #315b3d;
  padding: .22rem .7rem;
  font-weight: 800;
}

.ht-forest-play {
  display: grid;
  grid-template-columns: minmax(0, 34%) minmax(0, 1fr);
  align-items: start;
  width: min(100%, 1220px);
  margin: 1.65rem auto 0;
  padding-inline: clamp(.5rem, 3vw, 2.4rem);
}
.ht-forest-prompt { align-self: center; padding-inline: clamp(.5rem, 2.6vw, 2rem); padding-bottom: 5.1rem; }
.ht-forest-prompt h2 { font-size: clamp(1.8rem, 4.9vw, 3.4rem); letter-spacing: -.025em; line-height: 1.2; margin: 1rem 0 .45rem; word-break: keep-all; overflow-wrap: anywhere; }
.ht-forest-prompt > span { font-size: 1.2rem; padding: .32rem 1rem; }
.ht-forest-prompt p { font-size: clamp(.95rem, 2.15vw, 1.28rem); }
.ht-forest-prompt .ht-write-feedback { font-size: 1rem; margin: 0; }
.ht-forest-prompt .ht-write-feedback:empty { display: none; }
.ht-forest-input { display: grid; justify-items: center; gap: 1.4rem; min-width: 0; }
#ht-main .ht-forest-game .ht-forest-board {
  display: block;
  width: var(--forest-pad);
  max-width: 100%;
  height: auto;
  aspect-ratio: 1;
  border: 2px solid #9c9989;
  border-radius: .65rem;
  background: #fbf8ef;
  touch-action: none;
}
.ht-forest-board [data-write-ink] polyline { stroke: #2b2723; }
.ht-forest-board .ht-write-grid { stroke: #c9c0aa; stroke-width: .4; }
.ht-forest-actions { display: flex; justify-content: center; gap: clamp(.45rem, 1.4vw, 1rem); }
.ht-forest-actions button, .ht-forest-confirm, .ht-forest-lobby header button {
  min-height: 48px;
  padding: .45rem .9rem;
  border: 2px solid #2e563e;
  border-radius: .75rem;
  background: #fbf6e9;
  color: var(--forest-ink);
  font-weight: 800;
}
.ht-forest-input .ht-forest-actions button { font-size: clamp(1rem, 2.35vw, 1.48rem); min-height: clamp(48px, 10.4vh, 67px); }
.ht-forest-input .ht-forest-actions { width: 100%; }
.ht-forest-input .ht-forest-actions button { flex: 1; }
.ht-forest-actions .ht-forest-confirm, .ht-forest-confirm { background: #14543e; color: #fffdf3; }
.ht-forest-rain {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: clamp(.45rem, 4.2vh, 1.55rem);
  min-height: 0;
  padding-bottom: .6rem;
}
.ht-forest-field {
  --forest-card-height: clamp(46px, 10.8vh, 72px);
  position: relative;
  isolation: isolate;
  min-height: 0;
  border: 1px solid #b4b970;
  border-radius: 1.1rem;
  background: #fffaf012;
}
.ht-forest-ground {
  position: absolute;
  inset: auto 1.3% -1px 7%;
  height: 4px;
  border-radius: 50% 40% 35% 30%;
  background: linear-gradient(90deg, #769531, #56711f 85%, #8a9f4a);
}
.ht-forest-tile {
  position: absolute;
  z-index: 1;
  display: grid;
  place-items: center;
  top: calc((100% - var(--forest-card-height) - 3px) * var(--fall, 0));
  left: var(--lane);
  transform: translateX(-50%);
  min-width: clamp(3.1rem, 11.2vw, 7rem);
  height: var(--forest-card-height);
  padding-inline: .65rem;
  border: 2px solid #789430;
  border-radius: .9rem;
  color: #223910;
  background: radial-gradient(ellipse at 33% 10%, #fff9df, #faf0cb);
  box-shadow: inset 0 -2px 0 #7f8b4d34, 0 3px 4px #78683135;
}
.ht-forest-tile::before {
  content: "";
  position: absolute;
  bottom: 100%;
  width: 35%;
  height: min(10vh, 52px);
  opacity: min(1, calc(var(--fall, 0) * 6));
  background: repeating-linear-gradient(90deg, #aab86d88 0 4px, transparent 4px 43%);
  mask-image: linear-gradient(transparent, black);
  pointer-events: none;
}
.ht-forest-tile strong { font: 400 clamp(1.4rem, 4.45vw, 2.6rem)/1 "ClassAimate Hanja Reading", var(--serif); white-space: nowrap; }
.ht-forest-tile:has(.ht-forest-danger:not([hidden])) { border-color: #c28216; }
.ht-forest-danger {
  position: absolute;
  bottom: calc(100% + 4px);
  border-radius: 99px;
  padding: .12rem .52rem;
  color: #fffaf0;
  background: #8c5205;
  font-size: clamp(.58rem, 1.45vw, .85rem);
  font-weight: 750;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.ht-forest-entry { display: grid; grid-template-columns: minmax(0, 1fr) minmax(72px, 24%); width: min(100%, 32.65rem); gap: .72rem; margin: 0 auto; }
.ht-forest-entry input, .ht-forest-entry button { min-height: clamp(44px, 9.65vh, 62px); }
.ht-forest-entry input {
  min-width: 0;
  padding: .4rem clamp(.6rem, 2.6vw, 1.4rem);
  border: 1px solid #748b37;
  border-radius: .95rem;
  background: #fffae8ce;
  color: var(--forest-ink);
  font-family: inherit;
  font-size: clamp(1rem, 2.65vw, 1.55rem);
  font-weight: 750;
  box-shadow: 0 2px 4px #70643a28;
}
.ht-forest-entry input::placeholder { color: #666b4e; }
.ht-forest-entry button {
  border-color: #536d2f;
  border-radius: .95rem;
  background: linear-gradient(145deg, #557d2d, #344e1a);
  font-size: clamp(1rem, 2.65vw, 1.55rem);
  box-shadow: 0 3px 4px #70643a40;
}
.ht-forest-status {
  position: absolute;
  inset: auto 10px 1px;
  text-align: center;
  color: #344c1c;
  font-size: .76rem;
  pointer-events: none;
}
.ht-forest-status:empty { display: none; }
@media (prefers-reduced-motion: reduce) {
  .ht-forest-tile::before { display: none; }
}
.ht-forest-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.ht-forest-lobby { width: min(100%, 760px); margin: auto; padding: clamp(.85rem, 3vw, 1.65rem); display: grid; gap: .75rem; }
.ht-forest-lobby header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .55rem; }
.ht-forest-lobby .ht-forest-actions { justify-content: flex-start; flex-wrap: wrap; }
.ht-forest-ranking { margin: 0; padding: 0; list-style: none; }
.ht-forest-ranking li { display: grid; grid-template-columns: auto 2rem 1fr auto; align-items: center; gap: .65rem; padding: .35rem .15rem; border-bottom: 1px solid #dfd2ba; }
.ht-forest-ranking img, .ht-forest-avatar { width: 2rem; height: 2rem; object-fit: cover; border-radius: 50%; background: #e8edd5; }
.ht-forest-avatar { display: grid; place-items: center; }

@media (min-width: 850px) {
  .ht-forest-tile[data-kind="word"] { min-width: 7rem; }
  .ht-forest-tile[data-kind="word"]:has(.ht-forest-danger:not([hidden])) { min-width: 7.8rem; }
  .ht-forest-entry { transform: translateX(min(7.5vw, 90px)); }
}
@media (max-width: 720px) {
  body:has(.ht-forest-game) #ht-fullscreen { top: 7px; }
  .ht-forest-game { --forest-pad: min(70vw, 38dvh, max(120px, calc(var(--ht-visible-height, 100dvh) - 235px))); }
  .ht-forest-bar { grid-template-columns: 1fr auto; gap: .15rem .35rem; padding-right: 48px; }
  .ht-forest-bar dl { grid-column: 1 / -1; justify-content: flex-start; }
  .ht-forest-bar dl div, .ht-forest-wave { gap: .28rem; padding-inline: .4rem; }
  .ht-forest-tile { left: var(--narrow-lane); padding-inline: .23rem; }
  .ht-forest-tile strong { font-size: clamp(1.1rem, 6.4vw, 1.8rem); }
  .ht-forest-clock { top: 65px; right: .65rem; font-size: .8rem; }
  .ht-forest-play { grid-template-columns: 1fr; padding-inline: 0; gap: .45rem; margin-top: .5rem; }
  .ht-forest-prompt { padding: 0; text-align: center; }
  .ht-forest-prompt h2 { margin: .25rem 0 .1rem; }
  .ht-forest-input { gap: .5rem; }
  .ht-forest-input .ht-forest-actions { max-width: 30rem; }
  .ht-forest-input .ht-forest-actions button { padding-inline: .3rem; }
}
@media (max-height: 590px) {
  .ht-forest-game { padding-top: .3rem; }
  .ht-forest-rain { gap: .45rem; padding-bottom: .35rem; }
  .ht-forest-play { margin-top: .65rem; }
  .ht-forest-input { gap: .5rem; }
}
