/* Trace Training (tricky letters): a training field. On a wide screen the coach, the training meter and the
   Watch button are on the left and the big tracing board on the right; on a tall screen the coach and meter
   are on top, the board in the middle and the button underneath. Everything he taps is at least 80px, and
   the board doesn't scroll or zoom under his finger (touch-action: none). */
.game.trace { background: repeating-linear-gradient(90deg, #a2d97d 0 72px, #97d172 72px 144px); }
.trace button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.trace .game-top { padding-top: 5px; padding-bottom: 5px; }
.trace .tr-back { min-height: 60px; min-width: 60px; white-space: nowrap; }
.trace .game-top h2 { white-space: nowrap; }
.trace .tr-count { white-space: nowrap; }

.trace .tr-body {
  flex: 1; min-height: 0; position: relative; display: grid; gap: 12px 18px;
  grid-template-columns: clamp(230px, 25vw, 310px) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "side main" "tools main";
  padding: 12px max(16px, env(safe-area-inset-right, 0px)) 14px max(16px, env(safe-area-inset-left, 0px));
}

/* ---------- the coach and the training meter ---------- */
.trace .tr-side {
  grid-area: side; min-height: 0; display: flex; flex-direction: column; gap: 14px; padding: 12px;
  background: rgba(255, 255, 255, .93); border: 4px solid var(--ink); border-radius: 24px; box-shadow: var(--shadow);
}
.trace .tr-coachrow { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.trace .tr-coach { position: relative; flex: none; width: clamp(88px, 15vh, 136px); height: clamp(88px, 15vh, 136px); font-size: clamp(88px, 15vh, 136px); line-height: 0; }
.trace .tr-whistle { position: absolute; right: -14px; bottom: 4px; width: 38px; height: auto; }
.trace .tr-bubble {
  position: relative; align-self: stretch; display: flex; align-items: center; min-height: clamp(64px, 11vh, 104px); padding: 8px 12px;
  background: #fff8d6; border: 3px solid var(--ink); border-radius: 18px; color: var(--ink); font-weight: 800; font-size: clamp(18px, 2.7vh, 23px); line-height: 1.25;
}
.trace .tr-bubble::before { content: ''; position: absolute; left: 30px; top: -13px; border: 12px solid transparent; border-top: 0; border-bottom: 13px solid var(--ink); }
.trace .tr-bubble::after { content: ''; position: absolute; left: 33px; top: -8px; border: 9px solid transparent; border-top: 0; border-bottom: 9px solid #fff8d6; }
.trace .tr-bubble.new span { animation: tr-new .35s ease-out; }
@keyframes tr-new { from { opacity: .2; transform: translateY(4px); } }

/* the player above the meter (a row of its own on a tall screen) */
.trace .tr-team { display: flex; flex-direction: column; align-items: stretch; gap: 8px; margin-top: auto; }
.trace .tr-me { flex: none; align-self: center; width: clamp(60px, 11vh, 96px); }
.trace .tr-me .avatar-svg { display: block; width: 100%; height: auto; }
.trace .tr-me.pump { animation: tr-pump .9s ease-out; }
@keyframes tr-pump { 20% { transform: translateY(-14px) scale(1.06); } 45% { transform: none; } 65% { transform: translateY(-7px); } }
.trace .tr-meters { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.trace .tr-meter { display: flex; align-items: center; gap: 8px; min-width: 0; }
.trace .tr-meter.pump .tr-ml { animation: tr-pop .6s ease-out; }
.trace .tr-ml { flex: none; width: 30px; text-align: center; font-size: clamp(34px, 5vh, 44px); font-weight: 700; line-height: 1; color: var(--ink); }
.trace .tr-bar { flex: 1; min-width: 0; display: flex; gap: 4px; }
.trace .tr-bar i { flex: 1; min-width: 12px; height: clamp(30px, 5vh, 40px); display: grid; place-items: center; background: #e6edf3; border: 2.5px solid var(--ink); border-radius: 8px; transition: background .3s; }
.trace .tr-bar i.on { background: #4cd07d; animation: tr-pop .45s ease-out; }
.trace .tr-bar i.gold { background: #ffd23f; }
.trace .tr-bar em { font-style: normal; font-size: clamp(16px, 2.6vh, 22px); line-height: 1; filter: grayscale(1); opacity: .45; transition: opacity .3s; }
.trace .tr-bar i.on em { filter: none; opacity: 1; }
@keyframes tr-pop { 40% { transform: scale(1.3); } }

/* ---------- the board ---------- */
.trace .tr-main { grid-area: main; min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.trace .tr-board {
  position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  background: #fffdf7; border: 4px solid var(--ink); border-radius: 26px; box-shadow: var(--shadow); cursor: crosshair;
}
.trace .tr-board.yay .tr-fill { animation: tr-yay .6s ease-out; transform-box: fill-box; transform-origin: center; }
@keyframes tr-yay { 35% { transform: scale(1.06); } }
.trace .tr-svg { position: absolute; inset: 6px; width: calc(100% - 12px); height: calc(100% - 12px); overflow: visible; }

.tr-lines path { fill: none; stroke-width: 1.2; }
.tr-lines .top { stroke: #bcd6ef; }
.tr-lines .mid { stroke: #bcd6ef; stroke-dasharray: 4 4; }
.tr-lines .base { stroke: #f0a0a0; stroke-width: 1.8; }
.tr-lines .tail { stroke: #d8e4ef; stroke-dasharray: 3 5; }
.m-dot .tr-lines, .m-arrows .tr-lines, .m-watch .tr-lines { opacity: .7; }

.tr-lane { fill: none; stroke: #e1e8f1; stroke-width: 24; stroke-linecap: round; stroke-linejoin: round; transition: stroke .3s, fill .3s; }
circle.tr-lane { fill: #e1e8f1; stroke: none; }
.tr-lane.now { stroke: #fff0ae; }
circle.tr-lane.now { fill: #fff0ae; }
.tr-mid { fill: none; stroke: #b4c2d3; stroke-width: 1.6; stroke-dasharray: 3 5; }
.tr-ink { fill: none; stroke: var(--ink); stroke-width: 14; stroke-linecap: round; stroke-linejoin: round; }
.l-j .tr-ink, .l-y .tr-ink, .l-g .tr-ink { stroke: #2f6fd0; }
.tr-mask { fill: none; stroke: #fff; }
.tr-pic { transform-box: fill-box; transform-origin: center; }
.tr-pic.pop { animation: tr-pop .5s ease-out; }
.tr-dotfill { fill: #2f6fd0; transform-box: fill-box; transform-origin: center; transform: scale(0); transition: transform .3s cubic-bezier(.2, 1.6, .4, 1); }
.tr-dotfill.on { transform: none; }

.tr-arrow { opacity: 0; transition: opacity .25s; }
.tr-arrow.show { opacity: .45; }
.tr-arrow.show.now { opacity: 1; }
.tr-arrow path { fill: none; stroke: #ff7a1f; stroke-width: 3.6; stroke-linecap: round; stroke-linejoin: round; transform-box: fill-box; transform-origin: center; }
.tr-arrow.nudge path { animation: tr-nudge .4s ease-in-out 4; }
@keyframes tr-nudge { 50% { transform: translateX(4px) scale(1.35); } }
.tr-go { opacity: 0; transition: opacity .25s; }
.tr-go.show { opacity: .5; }
.tr-go.show.now, .tr-go.tr-hot { opacity: 1; }
.tr-dot { fill: #2bb673; stroke: #fff; stroke-width: 3; }
.tr-go text { font: 800 12px var(--font, sans-serif); fill: #fff; text-anchor: middle; pointer-events: none; }
.tr-halo { fill: #ffd23f; opacity: 0; transform-box: fill-box; transform-origin: center; }
.tr-go.show.now .tr-halo { animation: tr-halo 1.8s ease-out infinite; }
.tr-go.tr-hot .tr-halo { animation: tr-glow .45s ease-in-out infinite alternate; }
.tr-go.tr-hot .tr-dot { animation: tr-glowdot .45s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
@keyframes tr-halo { from { opacity: .8; transform: scale(.6); } to { opacity: 0; transform: scale(1.5); } }
@keyframes tr-glow { from { opacity: .55; transform: scale(1); } to { opacity: .95; transform: scale(1.45); } }
@keyframes tr-glowdot { to { transform: scale(1.25); } }
.m-check .tr-arrow, .m-check .tr-go { display: none; }

.tr-trail { fill: none; stroke: rgba(58, 42, 74, .16); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.tr-head { fill: none; stroke: #ffb52e; stroke-width: 4; opacity: 0; pointer-events: none; }
.tr-head.show { opacity: 1; animation: tr-blink 1.1s ease-in-out infinite; }
@keyframes tr-blink { 50% { opacity: .35; } }
.tr-ghost { pointer-events: none; }
.tr-board:not(.demo) .tr-ghost { display: none; }
.tr-ghost circle { fill: rgba(255, 255, 255, .9); stroke: var(--grape); stroke-width: 3; }
.tr-ghost circle.in { fill: var(--grape); stroke: none; }
.tr-ripple { fill: none; stroke-width: 3; transform-box: fill-box; transform-origin: center; animation: tr-rip .75s ease-out forwards; pointer-events: none; }
.tr-ripple.no { stroke: #ff7a1f; }
.tr-ripple.yes { stroke: #2bb673; }
@keyframes tr-rip { from { opacity: 1; transform: scale(.5); } to { opacity: 0; transform: scale(2.2); } }
.tr-pen { fill: none; stroke: var(--ink); stroke-width: 12; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- a game check: the word with its gap ---------- */
.trace .tr-word {
  flex: none; display: none; align-items: center; justify-content: center; gap: 16px; padding: 4px 14px;
  background: #fff; border: 4px solid var(--ink); border-radius: 22px; box-shadow: var(--shadow);
}
.trace .tr-word.show { display: flex; }
.trace .tr-word.shake { animation: tr-shake .4s; }
@keyframes tr-shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.trace .tr-wtext { font-size: clamp(48px, 4vw + 3vh, 92px); font-weight: 700; line-height: 1.2; letter-spacing: .04em; color: var(--ink); white-space: nowrap; }
.trace .tr-gap { display: inline-block; min-width: .62em; margin: 0 .05em; text-align: center; border-radius: 12px; outline: 4px dashed #ffb52e; outline-offset: -2px; background: #fff8d6; }
.trace .tr-gap.ok { outline: none; background: #dcf8e3; color: #1d8a4a; }
.trace .tr-gap.bad { outline: none; background: #ffe1e3; color: #c0392b; }
.trace .tr-gap.land { animation: tr-pop .45s ease-out; }
.trace .tr-hear { flex: none; width: 80px; height: 80px; border-radius: 50%; border: 4px solid var(--ink); background: #fff8d6; font-size: 36px; box-shadow: 0 4px 0 rgba(58, 42, 74, .2); cursor: pointer; }

/* ---------- the buttons under the coach ---------- */
.trace .tr-tools { grid-area: tools; display: flex; gap: 10px; }
.trace .tr-tool {
  flex: 1; display: none; min-height: 84px; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 4px 10px;
  font: inherit; font-size: 18px; font-weight: 800; color: var(--ink); background: #fff; border: 4px solid var(--ink); border-radius: 22px; box-shadow: var(--shadow); cursor: pointer;
}
.trace .tr-tool b { font-size: 34px; line-height: 1; }
.trace .tr-tool:active { transform: translateY(2px); }
.trace .is-rep .tr-tool[data-watch], .trace .is-check .tr-tool[data-clear] { display: flex; }

/* ---------- before the round ---------- */
.trace .tr-start { position: absolute; inset: 0; z-index: 12; display: none; place-items: center; padding: 16px; background: rgba(30, 70, 40, .35); }
.trace .tr-start.show { display: grid; }
.trace .tr-card { width: min(600px, 100%); padding: 14px 20px 18px; text-align: center; background: #fff; border: 4px solid var(--ink); border-radius: 28px; box-shadow: var(--shadow); }
.trace .tr-hero { display: flex; justify-content: center; align-items: flex-end; gap: 22px; height: clamp(90px, 16vh, 140px); }
.trace .tr-hcoach { position: relative; height: 100%; aspect-ratio: 1; font-size: clamp(90px, 16vh, 140px); line-height: 0; }
.trace .tr-clip { position: absolute; right: -18%; bottom: 4%; width: 34%; height: auto; transform: rotate(10deg); }
.trace .tr-hme { height: 100%; }
.trace .tr-hme .avatar-svg { height: 100%; width: auto; display: block; }
.trace .tr-lead { margin: 10px 0 12px; font-size: 21px; font-weight: 800; color: var(--ink); }
.trace .tr-green { color: #1d8a4a; }
.trace .tr-off { font-weight: 700; color: var(--coral-dark); margin: 0 0 10px; }
.trace .tr-sets { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.trace .tr-set {
  display: flex; align-items: center; justify-content: center; gap: 6px; min-width: 190px; min-height: 120px; padding: 8px 18px;
  font: inherit; color: var(--ink); background: #fff8d6; border: 4px solid var(--ink); border-radius: 24px; box-shadow: var(--shadow); cursor: pointer;
}
.trace .tr-set.main { background: #dff7ef; }
.trace .tr-set:active { transform: translateY(2px); }
.trace .tr-sl { display: block; width: 56px; height: 90px; }
.trace .tr-sl.txt { width: auto; height: auto; font-size: 70px; font-weight: 700; line-height: 1.2; padding: 0 4px; }
.trace .tr-play { margin-left: 8px; font-size: 40px; color: var(--grape); }

/* ---------- a tall screen: coach and meter on top, the board, the button underneath ---------- */
@media (orientation: portrait) {
  .trace .tr-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "side" "main" "tools"; gap: 10px; padding-top: 10px; padding-bottom: 12px; }
  .trace .tr-side { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px 12px; padding: 8px 10px; }
  .trace .tr-coachrow { flex: 1 1 100%; flex-direction: row; align-items: center; }
  .trace .tr-bubble { flex: 1; align-self: center; }
  .trace .tr-bubble::before { left: -13px; top: 50%; margin-top: -12px; border: 12px solid transparent; border-left: 0; border-right: 13px solid var(--ink); }
  .trace .tr-bubble::after { left: -8px; top: 50%; margin-top: -9px; border: 9px solid transparent; border-left: 0; border-right: 9px solid #fff8d6; }
  .trace .tr-team { flex: 1 1 100%; flex-direction: row; align-items: center; margin-top: 0; }
  .trace .tr-me { width: 52px; }
  .trace .tr-meters { flex-direction: row; gap: 14px; }
  .trace .tr-meter { flex: 1; }
}
@media (orientation: portrait) and (max-width: 600px) {
  .trace .game-top h2 { font-size: 20px; }
  .trace .tr-coach { width: 62px; height: 62px; font-size: 62px; }
  .trace .tr-whistle { width: 28px; right: -10px; }
  .trace .tr-bubble { font-size: 16px; min-height: 56px; padding: 6px 10px; }
  .trace .tr-me { width: 40px; }
  .trace .tr-meters { gap: 10px; }
  .trace .tr-meter { gap: 4px; }
  .trace .tr-ml { width: 18px; font-size: 26px; }
  .trace .tr-bar { gap: 3px; }
  .trace .tr-bar i { min-width: 9px; height: 26px; border-width: 2px; border-radius: 6px; }
  .trace .tr-bar em { font-size: 13px; }
  .trace .tr-tool { min-height: 80px; font-size: 16px; }
  .trace .tr-wtext { font-size: 54px; }
  .trace .tr-word { gap: 10px; padding: 2px 10px; }
  .trace .tr-board { border-radius: 20px; }
  .trace .tr-lead { font-size: 18px; }
  .trace .tr-set { min-width: 150px; min-height: 104px; padding: 6px 12px; }
  .trace .tr-sl { width: 46px; height: 76px; }
  .trace .tr-sl.txt { font-size: 58px; }
}
@media (prefers-reduced-motion: reduce) {
  .tr-go.show.now .tr-halo, .tr-head.show { animation: none; }
}
