/*
 * Games section. Builds on ../site.css.
 * In Kana Stops each guess is a line of four stops. A filled stop is the right
 * kana at the right stop; a double ring (the map symbol for an interchange)
 * means the kana is on the line but belongs at a different stop.
 */

.trail {
  display: flex;
  gap: 0.5rem;
  padding-top: 1.5rem;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.trail + .masthead {
  padding-top: 1.5rem;
}

.game {
  --stop-size: 3rem;
  --absent: #e3e7ea;
  --present: var(--kansai);

  max-width: 33rem;
}

.game-intro {
  margin-top: 1.5rem;
}

/* Stops */

.stop {
  position: relative;
  display: grid;
  flex: none;
  place-items: center;
  width: var(--stop-size);
  height: var(--stop-size);
  border: 3px solid var(--rule);
  border-radius: 50%;
  background: var(--plate);
  font-size: calc(var(--stop-size) * 0.48);
  font-weight: 700;
  line-height: 1;
}

.stop.is-filled {
  border-color: var(--ink);
}

.stop.is-pending {
  border-style: dashed;
  border-color: var(--ink-soft);
  color: var(--ink-soft);
  font-size: calc(var(--stop-size) * 0.3);
}

.stop.is-correct {
  border-color: var(--line);
  background: var(--line);
  color: var(--plate);
}

.stop.is-present {
  border-color: var(--present);
  box-shadow:
    inset 0 0 0 3px var(--plate),
    inset 0 0 0 5px var(--present);
}

.stop.is-absent {
  border-color: var(--absent);
  background: var(--absent);
  color: var(--ink-soft);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.5rem;
  margin: 1.25rem 0 0;
  padding: 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
  list-style: none;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.legend .stop {
  --stop-size: 1.9rem;

  border-width: 2px;
}

.legend .stop.is-present {
  box-shadow:
    inset 0 0 0 2px var(--plate),
    inset 0 0 0 3px var(--present);
}

/* Board */

.try-count {
  margin-top: 2rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 700;
}

.board {
  display: grid;
  gap: 0.6rem;
  margin: 0.6rem 0 0;
  padding: 0;
  list-style: none;
}

.guess {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: max-content;
}

/* The track the four stops sit on. */
.guess::before {
  content: "";
  position: absolute;
  left: calc(1.7rem + var(--stop-size) / 2);
  right: calc(var(--stop-size) / 2);
  top: 50%;
  height: 4px;
  background: var(--rule);
  transform: translateY(-50%);
}

.guess-number {
  width: 1.1rem;
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 700;
  text-align: right;
}

@media (prefers-reduced-motion: no-preference) {
  .guess.is-new .stop {
    animation: arrive 0.28s ease-out backwards;
  }

  .guess.is-new .stop:nth-child(3) {
    animation-delay: 0.1s;
  }

  .guess.is-new .stop:nth-child(4) {
    animation-delay: 0.2s;
  }

  .guess.is-new .stop:nth-child(5) {
    animation-delay: 0.3s;
  }
}

@keyframes arrive {
  from {
    border-color: var(--ink);
    background: var(--plate);
    box-shadow: none;
    color: var(--ink);
    transform: scale(0.82);
  }
}

.game-status {
  min-height: 1.5rem;
  margin-top: 0.75rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Result */

.result {
  margin-top: 1rem;
  padding: 1.25rem 1.25rem 1.1rem;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--plate);
}

.result p {
  margin: 0;
}

.result-outcome {
  font-weight: 700;
}

.result .result-word {
  margin-top: 0.6rem;
  font-size: 2.4rem;
  font-weight: 900;
  line-height: 1.2;
  letter-spacing: 0.1em;
}

.result-reading {
  color: var(--ink-soft);
}

.result .result-meaning {
  margin-top: 0.4rem;
  font-size: 1.15rem;
  font-weight: 700;
}

.result .result-share {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-top: 1rem;
}

.share-button {
  min-height: 2.5rem;
  padding: 0 1.25rem;
  border: 1px solid var(--ink);
  border-radius: 6px;
  background: var(--ink);
  color: var(--plate);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.share-message {
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.result .result-next {
  margin-top: 0.75rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.result-next:empty {
  display: none;
}

/* Keyboard */

.keyboard {
  margin-top: 1rem;
}

.key-chart {
  display: grid;
  grid-template-rows: repeat(5, 2.5rem);
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-auto-flow: column;
  gap: 0.3rem;
}

.key-actions {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1.4fr;
  gap: 0.3rem;
  margin-top: 0.5rem;
}

.key {
  min-width: 0;
  min-height: 2.5rem;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--plate);
  color: var(--ink);
  font: inherit;
  font-size: 1.1rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.key:hover {
  border-color: var(--ink);
}

.key:focus-visible,
.share-button:focus-visible,
.text-button:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

.key.is-correct {
  border-color: var(--line);
  background: var(--line);
  color: var(--plate);
}

.key.is-present {
  border-color: var(--present);
  box-shadow: inset 0 0 0 2px var(--present);
}

.key.is-absent {
  border-color: var(--absent);
  background: var(--absent);
  color: var(--ink-soft);
}

.key-action {
  font-size: 0.95rem;
  font-weight: 700;
}

.key-check {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--plate);
}

.game-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  margin-top: 1.5rem;
}

.text-button {
  padding: 0.25rem 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  cursor: pointer;
}

@media (max-width: 26rem) {
  .game {
    --stop-size: 2.6rem;
  }

  .key-chart {
    grid-template-rows: repeat(5, 2.35rem);
    gap: 0.22rem;
  }

  .key {
    font-size: 1rem;
  }
}

/* Kana Crossword */

/* Lets the hidden attribute win over the display rules below. */
.game [hidden] {
  display: none;
}

.levels {
  display: flex;
  gap: 0.4rem;
  margin-top: 1.5rem;
}

.level-tab {
  flex: 1;
  min-height: 2.5rem;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: var(--plate);
  color: var(--line);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.level-tab[aria-pressed="true"] {
  background: var(--line);
  color: var(--plate);
}

.puzzle-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
}

.puzzle-nav p {
  margin: 0;
}

.puzzle-label {
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
}

.text-button:disabled {
  color: var(--ink-soft);
  text-decoration: none;
  cursor: default;
  opacity: 0.5;
}

.crossword-frame {
  margin-top: 0.75rem;
  container-type: inline-size;
}

/* The ink background shows through as the black squares and the grid lines. */
.crossword {
  --columns: 7;
  --cell-size: 2.9rem;

  display: grid;
  grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
  gap: 2px;
  width: min(100%, calc(var(--columns) * var(--cell-size)));
  margin: 0 auto;
  border: 3px solid var(--ink);
  border-radius: 4px;
  background: var(--ink);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--plate);
  color: var(--ink);
  font: inherit;
  font-size: min(1.4rem, calc(100cqw / var(--columns) * 0.5));
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

/* A solved grid turns the colour of its line. */
.crossword.is-solved {
  border-color: var(--line);
  background: var(--line);
}

.crossword.is-solved .cell:not(.is-block) {
  background: var(--plate);
  color: var(--ink);
  cursor: default;
}

.cell.is-block {
  background: none;
  cursor: default;
}

.cell.is-in-word {
  background: color-mix(in srgb, var(--line) 18%, var(--plate));
}

.cell.is-cursor {
  background: var(--line);
  color: var(--plate);
}

.cell:focus-visible {
  z-index: 1;
  outline: 3px solid var(--ink);
  outline-offset: 1px;
}

/* A slash through the square, so a mistake does not rely on colour alone. */
.cell.is-wrong {
  background-image: linear-gradient(
    to top right,
    transparent 46%,
    var(--kyushu) 46%,
    var(--kyushu) 54%,
    transparent 54%
  );
}

.cell-number {
  position: absolute;
  top: 0.12em;
  left: 0.2em;
  font-size: 0.42em;
  font-weight: 700;
  line-height: 1;
}

.cell-kana.is-pending {
  font-size: 0.55em;
  font-weight: 500;
}

.crossword-page .key-actions {
  grid-template-columns: 1.2fr 1fr 1.3fr 1fr;
}

.result-solved {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  font-size: 1.3rem;
  font-weight: 900;
}

/* 正解 (correct), set like an ink stamp. */
.result-stamp {
  padding: 0.2rem 0.5rem;
  border: 3px solid var(--line);
  border-radius: 6px;
  color: var(--line);
  line-height: 1.2;
  transform: rotate(-4deg);
}

.result .result-outcome {
  margin-top: 0.75rem;
}

.active-clue {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
  margin-top: 1rem;
  padding: 0.6rem 0.9rem;
  border-left: 6px solid var(--line);
  border-radius: 4px;
  background: var(--plate);
}

.clue-number {
  flex: none;
  font-weight: 900;
}

.active-clue .clue-text {
  font-weight: 500;
}

.option-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.95rem;
  cursor: pointer;
}

.option-toggle input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--line);
}

.clues {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.5rem;
  margin-top: 2rem;
}

.clues h2 {
  margin: 0;
  padding-bottom: 0.4rem;
  border-bottom: 3px solid var(--line);
  font-size: 1.1rem;
}

.clue-list {
  margin: 0.4rem 0 0;
  padding: 0;
  list-style: none;
}

.clue-button {
  display: flex;
  flex-wrap: wrap;
  gap: 0 0.6rem;
  align-items: baseline;
  width: 100%;
  padding: 0.35rem 0.4rem;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
}

.clue-button .clue-number {
  width: 1.4rem;
}

.clue-button .clue-text {
  flex: 1;
  min-width: 0;
}

.clue-button.is-filled {
  color: var(--ink-soft);
}

.clue-button.is-active {
  background: color-mix(in srgb, var(--line) 18%, var(--plate));
  color: var(--ink);
}

.clue-button:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 1px;
}

.clue-answer {
  width: 100%;
  padding-left: 2rem;
  font-weight: 700;
}

.word-list {
  display: grid;
  gap: 0.4rem;
  margin: 0.75rem 0 0;
  padding: 0;
  list-style: none;
}

.word-list li {
  display: grid;
  grid-template-columns: 6.5rem minmax(0, 1fr);
  gap: 0 0.75rem;
  align-items: baseline;
}

.word-kana {
  grid-row: span 2;
  font-size: 1.15rem;
  font-weight: 900;
}

.word-reading {
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.word-meaning {
  grid-column: 2;
}

@media (max-width: 26rem) {
  .clues {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* On wide screens the clues sit to the right of the grid. */
@media (min-width: 60rem) {
  .crossword-page {
    max-width: 68rem;
  }

  .crossword-page .game-intro {
    max-width: 30.5rem;
  }

  .crossword-layout {
    display: grid;
    grid-template-columns: 30.5rem minmax(0, 1fr);
    gap: 3rem;
    align-items: start;
  }

  .crossword-layout .clues {
    margin-top: 1.5rem;
  }
}

/* Shiritori */

.shiritori-page {
  --player: var(--hokkaido);
  --computer: var(--kansai);
}

.tally {
  display: flex;
  gap: 2rem;
  margin: 1.5rem 0 0;
}

.tally dt {
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 700;
}

.tally dd {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 900;
  line-height: 1.2;
}

/*
 * The chain is a line that words join at its right-hand end; older words
 * slide away to the left and fade out.
 */
.track {
  margin-top: 1rem;
  padding: 0.25rem 0 0.75rem;
  overflow-x: auto;
  mask-image: linear-gradient(to right, transparent, #000 3rem);
  scrollbar-width: none;
}

.track::-webkit-scrollbar {
  display: none;
}

.track:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

.chain {
  position: relative;
  display: flex;
  gap: 0.75rem;
  width: max-content;
  min-width: 100%;
  margin: 0;
  padding: 0 0.25rem 0 3rem;
  list-style: none;
}

/* The rail the stops sit on. */
.chain::before {
  content: "";
  position: absolute;
  top: 0.55rem;
  right: 0;
  left: 0;
  height: 4px;
  background: var(--rule);
}

.chain-word {
  --speaker: var(--computer);

  position: relative;
  display: grid;
  flex: none;
  align-content: start;
  gap: 0.15rem;
  min-width: 7.5rem;
  max-width: 13rem;
  padding-top: 1.6rem;
}

.chain-word.is-player {
  --speaker: var(--player);
}

/* Each word's stop on the rail. */
.chain-word::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 1.2rem;
  height: 1.2rem;
  border: 4px solid var(--speaker);
  border-radius: 50%;
  background: var(--plate);
  box-sizing: border-box;
}

.chain-word.is-player::before {
  background: var(--speaker);
}

.chain-speaker {
  color: var(--speaker);
  font-size: 0.8rem;
  font-weight: 700;
}

.chain-kana {
  font-size: 1.7rem;
  font-weight: 900;
  line-height: 1.3;
  white-space: nowrap;
}

/* The kana that the next word has to start with. */
.chain-link {
  color: var(--speaker);
  text-decoration: underline;
  text-decoration-thickness: 3px;
  text-underline-offset: 0.2em;
}

.chain-written {
  font-weight: 700;
}

.chain-gloss {
  color: var(--ink-soft);
  font-size: 0.9rem;
  line-height: 1.35;
}

.thinking-dots {
  font-size: 1.7rem;
  font-weight: 900;
  line-height: 1.3;
  letter-spacing: 0.15em;
}

@media (prefers-reduced-motion: no-preference) {
  .chain-word {
    animation: pull-in 0.35s ease-out backwards;
  }

  .thinking-dots span {
    animation: thinking 1.2s ease-in-out infinite;
  }

  .thinking-dots span:nth-child(2) {
    animation-delay: 0.2s;
  }

  .thinking-dots span:nth-child(3) {
    animation-delay: 0.4s;
  }

  .entry-caret {
    animation: caret 1.1s steps(1) infinite;
  }
}

@keyframes pull-in {
  from {
    opacity: 0;
    transform: translateX(2.5rem);
  }
}

@keyframes thinking {
  0%,
  60%,
  100% {
    opacity: 0.25;
  }

  30% {
    opacity: 1;
  }
}

@keyframes caret {
  50% {
    opacity: 0;
  }
}

.turn-prompt {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  min-height: 2.6rem;
  margin-top: 1rem;
  font-weight: 700;
}

.prompt-kana {
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  background: var(--computer);
  color: var(--plate);
  font-size: 1.4rem;
  font-weight: 900;
  line-height: 1;
}

.word-entry {
  display: flex;
  align-items: center;
  min-height: 3.4rem;
  margin-top: 0.6rem;
  padding: 0.4rem 0.9rem;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--plate);
}

.entry-kana {
  font-size: 1.7rem;
  font-weight: 900;
  line-height: 1.2;
  letter-spacing: 0.08em;
}

.entry-pending {
  color: var(--ink-soft);
  font-size: 1.1rem;
}

.entry-caret {
  width: 2px;
  height: 1.8rem;
  margin-left: 0.15rem;
  background: var(--player);
}

/* An instruction in place of a kana hint is set at reading size. */
.entry-kana.is-placeholder.is-instruction {
  color: var(--ink-soft);
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0;
}

/* The placeholder kana is a hint, so the caret sits in front of it. */
.entry-kana.is-placeholder {
  order: 1;
  color: var(--rule);
}

.keyboard.is-waiting {
  opacity: 0.45;
  pointer-events: none;
}

.credit {
  margin-top: 2.5rem;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

/* The explanatory text under each game. */
.game-about {
  max-width: 34rem;
  margin-top: 3rem;
  padding-top: 0.5rem;
  border-top: 4px solid var(--ink);
}

.game-about h2 {
  margin: 2rem 0 0.5rem;
  font-size: 1.2rem;
}

.game-about p {
  margin: 0;
}

.game-about ul {
  display: grid;
  gap: 0.5rem;
  margin: 0;
  padding-left: 1.2rem;
}

.game-about kbd {
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--plate);
  font: inherit;
  font-size: 0.95em;
}
