/* Huarong Road. Safari 14.0 (iOS 14) has to draw all of this: no inset, no flex gap, no
   aspect-ratio, and svh only inside @supports. The stage and everything on it are sized and
   placed by the script; nothing here gives them a size. */
.game-root[data-game="huarong-road"] {
  padding: clamp(12px, 2.4vw, 22px);
  background: linear-gradient(180deg, #f6eee1 0%, #ead9c0 100%);
  border-color: #d9c4a3;
  text-align: left;
}
.klo { position: relative; width: 100%; display: flex; flex-direction: column; align-items: center; }
/* Level on the left, the level's name in the middle, the moves on the right. The outer columns
   are equal so the name sits on the tray's centre line. */
.klo-bar {
  width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr);
  align-items: baseline; column-gap: 12px; margin-bottom: 10px;
}
.klo-level { grid-column: 1; margin: 0; color: #4a3220; font: 700 1.02rem/1.2 Georgia, 'Iowan Old Style', 'Times New Roman', serif; }
.klo-name {
  grid-column: 2; margin: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-align: center;
  color: #3a2414; font: italic 700 1.14rem/1.3 Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  -webkit-text-stroke: .35px currentColor;
}
.klo-moves { grid-column: 3; justify-self: end; margin: 0; color: #9a8268; font-size: .85rem; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* The box the tray is fitted into. measure() reads max-height back as the tray's height
   budget, so it has to stay a length that resolves to pixels. */
.klo-fit {
  width: 100%; display: flex; justify-content: center; align-items: center;
  max-height: max(260px, min(640px, calc(100vh - 250px)));
}
@supports (height: 1svh) {
  .klo-fit { max-height: max(260px, min(640px, calc(100svh - 250px))); }
}

/* A finger on the floor, the frame or the disc still scrolls the page; only the blocks take
   the whole gesture. */
.klo-stage {
  position: relative; flex: none;
  touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
/* The tray: a frame of mid-brown wood, its inner edge sunk below the floor's level. */
.klo-frame {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0; border-radius: calc(var(--rim, 20px) * .55);
  background:
    repeating-linear-gradient(90deg, rgba(60, 30, 10, 0) 0, rgba(60, 30, 10, .06) 3px, rgba(60, 30, 10, 0) 7px, rgba(255, 220, 170, .04) 11px, rgba(60, 30, 10, 0) 15px),
    linear-gradient(180deg, #9a6438 0%, #7c4c27 55%, #6a3e1e 100%);
  box-shadow: 0 14px 30px rgba(70, 40, 15, .38), inset 0 2px 0 rgba(255, 228, 185, .35), inset 0 -3px 0 rgba(0, 0, 0, .3);
}
.klo-floor {
  position: absolute; background: #3b2416 center / cover no-repeat;
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, .55), inset 0 0 0 1px rgba(0, 0, 0, .35);
}
/* The gap the red block leaves by: floor carried out through the frame, brass on either jamb. */
.klo-gate {
  position: absolute; background: linear-gradient(180deg, #2a180d, #140b05);
  box-shadow: inset 0 6px 8px rgba(0, 0, 0, .5);
  transition: box-shadow .5s ease, background .5s ease;
}
.klo-gate::before, .klo-gate::after {
  content: ''; position: absolute; top: 0; bottom: 0; width: 5px;
  background: linear-gradient(90deg, #8a6a2c, #e6c574 45%, #a07a30);
}
.klo-gate::before { left: -5px; border-radius: 2px 0 0 2px; }
.klo-gate::after { right: -5px; border-radius: 0 2px 2px 0; }
.klo-stage.is-out .klo-gate {
  background: linear-gradient(180deg, #6b4a20, #2a180d);
  box-shadow: inset 0 6px 8px rgba(0, 0, 0, .3), 0 0 22px rgba(255, 210, 120, .7);
}

/* The turntable: the box rocks when it is held, the plate inside it turns. */
.klo-disc { position: absolute; z-index: 1; border-radius: 50%; }
.klo-disc[hidden] { display: none; }
.klo-plate {
  position: absolute; top: 2%; left: 2%; width: 96%; height: 96%; border-radius: 50%;
  background: center / 100% 100% no-repeat;
  transition: transform .46s cubic-bezier(.35, .9, .3, 1.05);
}
.klo-disc.is-plain .klo-plate { background: radial-gradient(circle at 50% 45%, #f1d68c, #b98d3a 70%, #8a6526); }
.klo-disc.is-stuck { animation: klo-rock .32s ease; }
@keyframes klo-rock {
  0%, 100% { transform: rotate(0); }
  30% { transform: rotate(5deg); }
  65% { transform: rotate(-3deg); }
}
.klo-disc::after {
  content: ''; position: absolute; top: 0; right: 0; bottom: 0; left: 0; border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(255, 214, 120, 0); transition: box-shadow .25s ease;
}
/* The disc's rim over the blocks: thin enough to read as a line on the tray, not as a thing. */
.klo-ring {
  position: absolute; z-index: 4; border-radius: 50%; pointer-events: none;
  box-shadow: inset 0 0 0 2px rgba(240, 205, 120, .6), 0 0 6px rgba(240, 205, 120, .35);
}
.klo-disc.is-cue::after { box-shadow: 0 0 0 4px rgba(255, 214, 120, .65), 0 0 22px rgba(255, 214, 120, .7); }

.klo-post {
  position: absolute; z-index: 1;
  background: radial-gradient(circle at 50% 40%, #6d4a2e 0 36%, #3d2617 37% 44%, rgba(0, 0, 0, 0) 45%) center / 72% 72% no-repeat;
  filter: drop-shadow(0 2px 2px rgba(30, 15, 5, .45));
}

.klo-blocks { position: absolute; top: 0; left: 0; z-index: 2; }
.klo-block {
  position: absolute; top: 0; left: 0; z-index: 2; cursor: grab; touch-action: none;
  filter: drop-shadow(0 2px 2px rgba(30, 15, 5, .5));
  transition: transform .09s ease-out;
}
.klo-block.is-held { z-index: 6; cursor: grabbing; filter: drop-shadow(0 7px 7px rgba(30, 15, 5, .45)); transition: transform .07s ease-out; }
.klo-block.is-turning { z-index: 5; transition: transform .46s cubic-bezier(.35, .9, .3, 1.05); }
.klo-block.is-leaving {
  z-index: 6; opacity: 0;
  transition: transform .62s cubic-bezier(.5, 0, .75, .45), opacity .4s ease-in .26s;
}
.klo-shell { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
.klo-shell.is-knock { animation: klo-knock .2s ease-out; }
@keyframes klo-knock {
  0%, 100% { left: 0; top: 0; }
  40% { left: var(--kx, 0); top: var(--ky, 0); }
}
.klo-face {
  position: absolute; background: center / 100% 100% no-repeat;
  transition: transform .2s ease;
}
.klo-face.is-plain { border-radius: 10%; box-shadow: inset 0 2px 0 rgba(255, 255, 255, .35), inset 0 -3px 0 rgba(0, 0, 0, .25); }
.klo-face.is-plain.is-B { background: linear-gradient(160deg, #c2402c, #8e2416); }
.klo-face.is-plain.is-H, .klo-face.is-plain.is-V { background: linear-gradient(160deg, #e2b77c, #b98648); }
.klo-face.is-plain.is-S { background: linear-gradient(160deg, #efd6a8, #c9a46c); }
.klo-stage.is-still .klo-block, .klo-stage.is-still .klo-face, .klo-stage.is-still .klo-plate { transition: none; }
.klo-stage .jj-confetti { top: 0; left: 0; }

/* The lessons: a faint copy of the block the hand drags, and the hand. */
.klo-ghost { position: absolute; left: 0; top: 0; z-index: 7; pointer-events: none; }
.klo-ghost .klo-block { transition: none; filter: drop-shadow(0 8px 10px rgba(0, 0, 0, .35)); }
.klo-hand {
  position: absolute; left: 0; top: 0; z-index: 9; pointer-events: none; width: 46px; height: 49px;
  margin: -3px 0 0 -16px; transform-origin: 34.4% 5.9%; transition: transform .12s ease;
}
.klo-hand.is-down { transform: scale(.86); }
.klo-hand[hidden], .klo-ghost[hidden] { display: none; }
.klo-hand svg { display: block; width: 100%; height: 100%; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .4)); }
.klo-guide {
  margin: 12px 0 0; min-height: 1.4em; color: #6f5640; font-size: .9rem; text-align: center;
  transition: transform .25s ease, text-shadow .25s ease;
}
.klo-guide.is-cue { transform: translateY(-3px); text-shadow: 0 0 10px rgba(230, 170, 70, .55); }

.klo-controls { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; margin: 2px -4px 0; }
.klo-controls > * { margin: 8px 4px 0; }
.klo-ctl {
  display: inline-flex; align-items: center;
  border: 1px solid #d3bb98; border-radius: 10px; padding: 8px 12px; background: #fffaf1; color: #4a3220;
  font: inherit; font-size: .86rem; font-weight: 700; cursor: pointer;
}
.klo-ctl > .klo-icon + span { margin-left: 6px; }
.klo-ctl:hover:not(:disabled) { background: #fff1db; }
.klo-ctl:disabled { opacity: .4; cursor: default; }
.klo-nav { display: inline-flex; align-items: center; }
.klo-nav > * + * { margin-left: 6px; }
.klo-step { padding: 7px 10px; }
/* A level arrow that cannot be pressed is not shown, but keeps its room: with display: none the
   tray would change size and shift sideways from level to level. */
.klo-step:disabled, .klo-side:disabled { visibility: hidden; }
.klo-where { min-width: 3.6em; color: #4a3220; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
/* The arrows beside the tray, on a computer only; the small ones in the row below stand in for
   them on a phone. measure() takes their width and margins off the tray's room. */
.klo-side { display: none; }
@media (min-width: 1000px) {
  .klo-side {
    display: flex; flex: none; align-items: center; justify-content: center;
    width: 54px; height: 54px; margin: 0 22px; padding: 0;
    border: 1px solid #d3bb98; border-radius: 50%; background: #fffaf1; color: #4a3220;
    box-shadow: 0 3px 10px rgba(70, 40, 15, .16); cursor: pointer;
  }
  .klo-side:hover:not(:disabled) { background: #fff1db; }
  .klo-side .klo-icon { width: 30px; height: 30px; stroke-width: 3; }
  .klo-nav .klo-step { display: none; }
}
.klo-icon { flex: none; width: 18px; height: 18px; }

/* The end of a level, laid over the whole game rather than the tray: the tray can be shorter
   than the card. */
.klo-win {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 10px;
  background: rgba(45, 28, 14, .35);
}
.klo-win:empty { display: none; }
.klo-card {
  width: 100%; max-width: 360px; max-height: 100%; overflow-y: auto; padding: 18px 20px 16px;
  border-radius: 18px; background: #fffaf1; color: #3a2414; text-align: center;
  box-shadow: 0 16px 40px rgba(45, 28, 14, .35);
  animation: klo-pop .34s cubic-bezier(.3, 1.4, .5, 1);
}
@keyframes klo-pop { from { opacity: 0; transform: scale(.88); } to { opacity: 1; transform: scale(1); } }
.klo-card-title { margin: 0 0 8px; color: #9a3a22; font-size: .95rem; font-weight: 800; }
.klo-card-name { margin: 0; color: #3a2414; font: italic 700 1.25rem/1.3 Georgia, 'Iowan Old Style', 'Times New Roman', serif; }
.klo-card-line { margin: 6px 0 0; color: #6f5640; font-size: .92rem; line-height: 1.45; }
.klo-card-small { margin: 10px 0 0; color: #a8937c; font-size: .8rem; }
.klo-card-best { margin: 2px 0 0; color: #a07a30; font-size: .8rem; font-weight: 700; }
.klo-card-btns { display: flex; flex-wrap: wrap; justify-content: center; margin: 6px -4px 0; }
.klo-card-btns > * { margin: 8px 4px 0; }
.klo-card-btn { display: inline-flex; align-items: center; }
.klo-card-btn > .klo-icon { margin-right: 6px; }
.klo-feel { margin: 14px 0 0; color: #6f5640; font-size: .86rem; font-weight: 700; }
.klo-moods { display: flex; flex-wrap: wrap; justify-content: center; margin: 2px -3px 0; }
.klo-moods > * { margin: 6px 3px 0; }
.klo-mood {
  display: inline-flex; align-items: center; padding: 6px 11px; border: 1px solid #d3bb98; border-radius: 999px;
  background: #fff; color: #4a3220; font: inherit; font-size: .82rem; font-weight: 700; cursor: pointer;
}
.klo-mood > .klo-icon { margin-right: 5px; }
.klo-mood.is-on { border-color: #9a3a22; background: #fbe9dc; color: #9a3a22; }
.klo-more-row { margin: 10px 0 0; }
.klo-more { font-size: .88rem; padding: 8px 14px; }
.klo-more-row .klo-note { margin-top: 6px; }
.klo-note { min-height: 1.3em; margin: 8px 0 0; color: #6f5640; font-size: .8rem; line-height: 1.4; }
.klo-note kbd { padding: 1px 5px; border: 1px solid #d3bb98; border-radius: 4px; background: #fff; font: inherit; font-size: .78rem; }

/* Review build only: a row of tools under the game. */
.klo-review {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; margin: 10px 0 0;
  color: #8a7560; font-size: .8rem;
}
.klo-review > * { margin: 4px 5px; }
.klo-review-sel { max-width: 240px; padding: 6px 8px; border: 1px solid #d3bb98; border-radius: 8px; background: #fff; font: inherit; }
.klo-review-note { max-width: 100%; overflow-wrap: anywhere; }

/* Mode 3 — phone: the panel sheds its card and reaches the page gutter. */
@media (max-width: 640px) {
  .game-root[data-game="huarong-road"] {
    padding: 10px 8px 14px; margin-left: -8px; margin-right: -8px;
    border-left: 0; border-right: 0; border-radius: 0; box-shadow: none;
  }
  .klo-bar { grid-template-columns: minmax(0, 1fr) auto; row-gap: 4px; }
  .klo-name { grid-column: 1 / -1; grid-row: 1; }
  .klo-level { grid-row: 2; }
  .klo-moves { grid-column: 2; grid-row: 2; }
  .klo-fit { max-height: max(240px, min(64vh, calc(100vh - 230px))); }
  @supports (height: 1svh) {
    .klo-fit { max-height: max(240px, min(64svh, calc(100svh - 230px))); }
  }
  .klo-ctl { padding: 8px 10px; }
}

/* Mode 2 — page-filling. The panel is game-layout.css's; the rows stay together as one group in
   the middle and measure() sizes the tray from the panel. */
html.fills-window .game-root[data-game="huarong-road"] .klo { height: 100%; justify-content: center; }
html.fills-window .game-root[data-game="huarong-road"] .klo > * { flex: none; }
html.fills-window .game-root[data-game="huarong-road"] .klo-fit { max-height: none; }
