:root {
  --bg: #f6f7f9;
  --ink: #15191d;
  --muted: #667079;
  --line: #d3d8dc;
  --block: #b8b8b6;
  --board-border: #44484b;
  --grid-line: rgba(69, 74, 78, 0.18);
  --tile: #eef3f4;
  --active: #fff3ae;
  --hint: #ffffff;
  --toast: #20272c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

/* Buttons set their own display, which would otherwise override hidden. */
[hidden] {
  display: none !important;
}

.app {
  width: min(100%, 460px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 34px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #0b6f5a;
  color: #fff;
  font-family: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.22), 0 1px 2px rgba(17, 24, 39, 0.18);
}

h1,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1;
  letter-spacing: 0;
}

.brand p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.1;
}

.actions {
  display: flex;
  gap: 10px;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 0;
  background: transparent;
  color: #343a40;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 38px;
  line-height: 1;
}

.actions .icon-button {
  color: #70777d;
  font-size: 31px;
}

.lang-button {
  min-width: 42px;
  height: 42px;
  border: 1px solid #c8ced3;
  border-radius: 8px;
  background: #fff;
  color: #343a40;
  cursor: pointer;
  font-size: 17px;
  font-weight: 900;
}

.lang-button.icon-only {
  display: grid;
  place-items: center;
}

.level-stats {
  width: 100%;
  margin-top: 20px;
  border-collapse: collapse;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.level-stats th,
.level-stats td {
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.level-stats thead th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.level-stats tbody th {
  text-align: left;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stats div {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 9px 12px;
}

.stats span,
.stats small {
  display: block;
}

.stats span {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.1;
}

.stats small {
  color: var(--muted);
  margin-top: 2px;
  font-size: 12px;
}

.difficulty {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.difficulty-button {
  min-height: 38px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.difficulty-button:last-child {
  border-right: 0;
}

.difficulty-button.active {
  background: #0b8a68;
  color: #fff;
}

.board-wrap {
  position: relative;
}

.message {
  position: absolute;
  left: 50%;
  top: 12px;
  z-index: 5;
  min-height: 34px;
  max-width: calc(100% - 36px);
  transform: translateX(-50%);
  padding: 8px 12px;
  border-radius: 18px;
  background: transparent;
  color: transparent;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  pointer-events: none;
  transition: background 120ms ease, color 120ms ease;
}

.message.show {
  background: var(--toast);
  color: #fff;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--board-size, 5), 1fr);
  grid-template-rows: repeat(var(--board-size, 5), 1fr);
  gap: 1px;
  aspect-ratio: 1;
  border: 5px solid var(--board-border);
  border-radius: 13px;
  overflow: hidden;
  background: var(--grid-line);
  touch-action: none;
  user-select: none;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border: 0;
  background: linear-gradient(180deg, #f7fafb 0%, var(--tile) 100%);
  color: var(--ink);
  font-family: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: clamp(22px, calc(48vw / var(--board-size, 5)), 43px);
  font-weight: 800;
  line-height: 1;
}

.cell .component {
  position: relative;
  z-index: 3;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}

.cell .enclosure-component {
  font-size: 1.12em;
  font-weight: 700;
}

.cell.block {
  background: linear-gradient(180deg, #c3c3c1 0%, var(--block) 100%);
  border: 0;
  z-index: 4;
}

.cell.available {
  cursor: pointer;
}

.cell.hinted::after {
  content: "";
  position: absolute;
  inset: 9px;
  border: 4px solid var(--hint);
  border-radius: 999px;
  box-shadow: 0 0 0 3px rgba(17, 137, 104, 0.82);
  pointer-events: none;
}

.track {
  position: absolute;
  inset: 0;
  z-index: 1;
  color: var(--path-color);
  pointer-events: none;
}

.track::before {
  content: "";
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0.24;
}

.track .core,
.track .connector {
  position: absolute;
  background: currentColor;
}

.track .core {
  left: 50%;
  top: 50%;
  width: 45%;
  height: 45%;
  transform: translate(-50%, -50%);
}

.track.endpoint .core,
.track.corner .core {
  border-radius: 999px;
}

.track .connector.right,
.track .connector.left {
  top: 50%;
  width: 50%;
  height: 45%;
  transform: translateY(-50%);
}

.track .connector.right {
  left: 50%;
}

.track .connector.left {
  right: 50%;
}

.track .connector.down,
.track .connector.up {
  left: 50%;
  width: 45%;
  height: 50%;
  transform: translateX(-50%);
}

.track .connector.down {
  top: 50%;
}

.track .connector.up {
  bottom: 50%;
}

.track.active {
  color: var(--active);
}

.track.active::before {
  opacity: 0.38;
}

.answer.solved::after {
  content: "✓";
  position: absolute;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 3px solid currentColor;
  background: #fff;
  color: #0b8a68;
  font-size: 22px;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 800;
  line-height: 1;
}

.cell .arrow {
  position: absolute;
  z-index: 2;
  color: #111;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 30px;
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
}

.cell .arrow.right {
  right: -12px;
  top: 50%;
  transform: translateY(-50%);
}

.cell .arrow.left {
  left: -12px;
  top: 50%;
  transform: translateY(-50%) rotate(180deg);
}

.cell .arrow.down {
  bottom: -14px;
  left: 50%;
  transform: translateX(-50%) rotate(90deg);
}

.cell .arrow.up {
  top: -14px;
  left: 50%;
  transform: translateX(-50%) rotate(-90deg);
}

.answers {
  display: grid;
  gap: 8px;
  padding-top: 2px;
}

.answer {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 38px;
  gap: 4px;
}

.answer .slot {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #101416;
  font-size: 18px;
  font-weight: 900;
}

.answer .word {
  display: none;
  width: calc((var(--answer-components) * 34px) + ((var(--answer-components) - 1) * 4px));
  min-height: 34px;
  justify-content: center;
  align-items: center;
  padding: 0 11px;
  border-radius: 8px;
  font-family: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 24px;
  font-weight: 900;
}

.answer.solved .slot {
  display: none;
}

.answer.solved .word {
  display: inline-flex;
}

.answer .gloss {
  display: none;
  min-width: 0;
  flex: 1 1 auto;
  margin-left: 6px;
  line-height: 1.25;
}

.answer.solved .gloss {
  display: grid;
}

/* Learners' help: pinyin and meaning are shown in English only. */
html[lang^="zh"] .answer .gloss {
  display: none;
}

.gloss-pinyin {
  font-size: 15px;
  font-weight: 800;
}

.gloss-meaning {
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  color: var(--muted);
  font-size: 13px;
}

.answer.solved::after {
  position: static;
  margin-left: 8px;
  flex: 0 0 auto;
}

.dev-solutions {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.dev-solutions[hidden] {
  display: none;
}

.dev-solution {
  display: grid;
  grid-template-columns: minmax(52px, auto) 1fr;
  gap: 10px;
  align-items: baseline;
  font-size: 14px;
}

.dev-solution-word {
  font-family: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 20px;
  font-weight: 900;
}

.dev-solution-components {
  font-family: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--muted);
  line-height: 1.45;
  user-select: text;
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 10px;
  margin-top: auto;
}

.primary,
.secondary {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid #0e735b;
  cursor: pointer;
  font-weight: 800;
}

.primary {
  background: #0b8a68;
  color: #fff;
}

.secondary {
  background: #fff;
  color: #0b5f4d;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

@media (min-width: 720px) {
  body {
    background: #20272c;
  }

  .app {
    background: var(--bg);
  }
}

/* Dialogs: the share result and how to play. */
.modal {
  width: min(calc(100% - 32px), 440px);
  max-height: calc(100% - 48px);
  padding: 18px 20px 22px;
  border: 0;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 18px 48px rgba(17, 24, 39, 0.28);
}

.modal::backdrop {
  background: rgba(17, 24, 39, 0.5);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.modal .modal-head h2 {
  margin: 0;
  font-size: 20px;
}

.modal .modal-close {
  width: 36px;
  height: 36px;
  margin-right: -8px;
  color: var(--muted);
  font-size: 30px;
}

.share-text {
  margin: 0 0 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-family: inherit;
  font-size: 16px;
  line-height: 1.5;
  white-space: pre-wrap;
  user-select: all;
}

.modal .primary,
.modal .secondary {
  width: 100%;
}

/* Our tone app, under the countdown; learners only, so English only. */
.promo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.3;
  text-decoration: none;
}

html[lang^="zh"] .promo {
  display: none;
}

.promo img {
  flex: 0 0 auto;
  border-radius: 8px;
}

.promo-text {
  flex: 1 1 auto;
}

.promo-text small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.promo-arrow {
  color: var(--muted);
  font-size: 18px;
}

/* Under the controls: our tone app (English only) and Ko-fi. */
.page-footer {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding-top: 4px;
  text-align: center;
}

.page-footer p {
  margin: 0;
}

.made-by {
  font-size: 13px;
  line-height: 1.35;
}

html[lang^="zh"] .made-by {
  display: none;
}

.made-by a {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  text-decoration: none;
}

.made-by img {
  flex: 0 0 auto;
  border-radius: 6px;
}

.made-by b {
  color: var(--ink);
}

.kofi {
  font-size: 14px;
}

.kofi a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #0b6f5a;
  font-weight: 700;
  text-decoration: none;
}

.share-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 18px 0 0;
  text-align: center;
}

.share-stats dd {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.share-stats dt {
  color: var(--muted);
  font-size: 13px;
}

.share-stats div {
  display: flex;
  flex-direction: column-reverse;
}

.next-board {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
}

.next-board strong {
  display: block;
  margin-top: 2px;
  color: var(--ink);
  font-size: 28px;
  font-variant-numeric: tabular-nums;
}

#playTodayButton {
  margin-top: 12px;
}

/* How to play: in the page for search engines, shown in a dialog. */
.about {
  font-size: 18px;
  line-height: 1.45;
}

.howto-intro {
  margin: 0 0 20px;
}

.howto {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 20px;
}

.howto p {
  margin: 0 0 10px;
}

.demo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.demo-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), 48px);
  gap: 4px;
}

.demo-tile,
.demo-answer {
  position: relative;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-family: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 28px;
  font-weight: 800;
}

.demo-tile {
  background: color-mix(in srgb, var(--c) 30%, #fff);
  box-shadow: inset 0 0 0 2px var(--c);
}

/* The tracing order. */
.demo-tile[data-step]::after {
  content: attr(data-step);
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--c);
  color: #fff;
  font-family: inherit;
  font-size: 11px;
  font-weight: 800;
}

.demo-tile.demo-empty {
  background: var(--block);
  box-shadow: none;
}

.demo-arrow {
  color: var(--muted);
  font-size: 24px;
}

.demo-answer {
  width: 56px;
  height: 56px;
  background: var(--c);
  color: #fff;
  font-size: 34px;
}

.demo-slots {
  display: flex;
  gap: 4px;
}

.demo-slot {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--c);
}

.demo-note {
  color: var(--muted);
  font-weight: 700;
}

.howto-foot {
  margin: 22px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 16px;
}
