/* Self-hosted OFL fonts, subset by tools/build_fonts.py. */
@font-face {
  font-family: "Noto Sans Mono";
  src: url("../assets/fonts/NotoSansMono.woff2") format("woff2");
  font-weight: 400 900;
  font-display: block;
}

@font-face {
  font-family: "Noto Sans JP";
  src: url("../assets/fonts/NotoSansJP.woff2") format("woff2");
  font-weight: 400 900;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #101318;
  --panel: #171c24;
  --line: #2b3545;
  --text: #f3f6fb;
  --muted: #9da9b8;
  --good: #66d19e;
  --bad: #ff6b6b;
  --gold: #f6c85f;
  --sky: #86b8ff;
  --font-mono: "Noto Sans Mono", "Noto Sans JP", "Cascadia Mono", "Consolas", monospace;
  --ticker-font: clamp(28px, 4vw, 48px);
  --font-jp: "Noto Sans JP", "Yu Gothic", "YuGothic", "Meiryo", "Hiragino Sans", sans-serif;
}

* {
  box-sizing: border-box;
}

/* Portals embed the game in an iframe: no page scrolling, no text selection,
   no context menu on long tap, no dragging of images and canvas. */
html,
body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

img,
canvas {
  -webkit-user-drag: none;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
}

button,
select,
input {
  font: inherit;
}

.app {
  display: grid;
  grid-template-rows: 58px minmax(220px, 1fr) auto minmax(180px, 35vh);
  min-height: 100vh;
  position: relative;
}

.hud {
  display: grid;
  grid-template-columns: auto auto 1fr auto 48px;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
  background: #151a22;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.hud__group {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.hud__label,
.hud__group span {
  color: var(--muted);
  font-size: 14px;
}

.icon-button,
.primary-button,
.secondary-button {
  min-height: 42px;
  border: 1px solid var(--line);
  background: #202735;
  color: var(--text);
  cursor: pointer;
}

.icon-button {
  width: 42px;
  border-radius: 8px;
  font-size: 20px;
}

.primary-button,
.secondary-button {
  border-radius: 8px;
  padding: 0 18px;
}

.primary-button {
  background: var(--gold);
  color: #1b1710;
  border-color: #ffe08a;
  font-weight: 700;
}

.stage {
  position: relative;
  overflow: hidden;
  background: linear-gradient(#111820, #131922 70%, #151a22);
}

.ticker-viewport {
  position: absolute;
  inset: 20% 0 20%;
  overflow: hidden;
}

.ticker-track {
  position: absolute;
  left: 0;
  top: 42%;
  display: flex;
  align-items: center;
  font-size: var(--ticker-font);
  line-height: 1.2;
  white-space: pre;
  will-change: transform;
}

.unit {
  position: relative;
  display: inline-block;
  flex: none;
  text-align: center;
}

/* Japanese: kanji phrase (read only), kana units, romaji that is actually typed. */
.ticker-track--ja {
  top: calc(50% - 1.6em);
  align-items: stretch;
}

.ticker-track--ja .unit {
  display: inline-grid;
  grid-template-columns: 100%;
  grid-template-rows: 0.9em 1.1em 1.2em;
  align-items: end;
  justify-items: center;
}

/* The phrase starts at its first kana and may run over the following units. */
.unit__phrase {
  position: absolute;
  left: 0;
  top: 0;
  font-family: var(--font-jp);
  font-size: 0.42em;
  color: var(--muted);
  white-space: pre;
}

.unit__kana {
  grid-row: 2;
  font-family: var(--font-jp);
  font-size: 0.5em;
  line-height: 1.6;
}

.unit__romaji {
  grid-row: 3;
  line-height: 1.2;
}

.unit__typed {
  color: var(--good);
}

.unit--current {
  background: rgba(246, 200, 95, 0.2);
  text-decoration: underline;
  text-decoration-thickness: 3px;
  text-underline-offset: 0.18em;
}

.unit--correct {
  color: var(--good);
  opacity: 0.48;
}

.unit--missed {
  color: var(--bad);
  transform: translateY(20px);
  opacity: 0;
  transition: transform 400ms ease, opacity 400ms ease;
}

.ticker-track.is-shaking {
  animation: shake 150ms linear;
}

.unit.is-flashing {
  background: rgba(255, 107, 107, 0.28);
}

.miss-line {
  position: absolute;
  left: 15%;
  top: 10%;
  bottom: 10%;
  width: 2px;
  background: repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.25), rgba(255, 255, 255, 0.25) 8px, transparent 8px, transparent 16px);
  z-index: 2;
}

.popups {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.popup {
  position: absolute;
  font-weight: 800;
  animation: floatScore 600ms ease forwards;
}

.popup--good {
  color: var(--good);
}

.popup--bad {
  color: var(--bad);
}

.banner,
.countdown,
.toast {
  position: absolute;
  z-index: 6;
  pointer-events: none;
}

.banner {
  left: 50%;
  top: 28%;
  transform: translate(-50%, -50%);
  color: var(--gold);
  font-size: clamp(28px, 5vw, 54px);
  font-weight: 900;
  text-shadow: 0 6px 28px rgba(0, 0, 0, 0.55);
  opacity: 0;
}

.banner.is-visible {
  animation: banner 700ms ease both;
}

.toast {
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(680px, calc(100vw - 32px));
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #202735;
  color: var(--text);
  opacity: 0;
  transition: opacity 160ms ease;
}

.toast.is-visible {
  opacity: 1;
}

.progress-panel {
  padding: 12px 18px 14px;
  background: #151a22;
  border-top: 1px solid var(--line);
}

.progress-panel__text {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 8px;
  color: var(--muted);
}

.progress-panel__text strong {
  color: var(--text);
}

.progress-bar {
  position: relative;
  height: 16px;
  overflow: hidden;
  background: #273140;
  border: 1px solid #384559;
  border-radius: 8px;
}

.progress-bar__fill {
  position: relative;
  z-index: 2;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--good), var(--gold));
}

.progress-bar__fill--danger {
  background: linear-gradient(90deg, var(--bad), var(--gold));
}

.progress-bar__danger {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 100%;
  background: rgba(255, 107, 107, 0.28);
  border-right: 3px solid var(--bad);
  z-index: 1;
}

.progress-bar__danger--active {
  animation: dangerPulse 700ms steps(2, end) infinite;
}

.scene {
  display: block;
  width: 100%;
  height: 100%;
  background: #101820;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(8, 10, 14, 0.78);
  z-index: 8;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.overlay--visible {
  opacity: 1;
  pointer-events: auto;
}

.menu,
.pause-card {
  width: min(560px, calc(100vw - 32px));
  /* The menu scrolls inside itself; the page never scrolls. */
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.45);
}

.menu h1 {
  margin: 0 0 18px;
  font-size: 34px;
}

.menu-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 16px;
}

.menu-tab {
  min-height: 36px;
  padding: 0 4px;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111820;
  color: var(--muted);
  cursor: pointer;
}

.menu-tab.is-active {
  background: #263144;
  color: var(--text);
}

.menu-panel {
  display: none;
}

.menu-panel.is-active {
  display: block;
}

.menu__row {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.menu__checks {
  gap: 12px;
}

.menu select {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111820;
  color: var(--text);
}

.theme-cards,
.meta-list {
  display: grid;
  gap: 10px;
  max-height: min(48vh, 520px);
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding-right: 4px;
}

.theme-card,
.meta-row {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111820;
}

.theme-card--current {
  border-color: var(--gold);
}

.theme-card--locked {
  opacity: 0.72;
}

.theme-card strong,
.meta-row strong {
  display: block;
}

.theme-card span,
.theme-card p,
.meta-row span {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.theme-card__actions {
  display: flex;
  justify-content: flex-end;
}

.meta-row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.meta-row--done {
  border-color: rgba(102, 209, 158, 0.6);
}

.achievement-row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111820;
}

.achievement-row--done { border-color: rgba(102, 209, 158, 0.6); }
.achievement-row__icon { width: 64px; height: 64px; image-rendering: pixelated; }
.achievement-row:not(.achievement-row--done) .achievement-row__icon { filter: grayscale(1); opacity: .45; }
.achievement-row__copy { display: grid; gap: 4px; min-width: 0; }
.achievement-row__copy span { color: var(--muted); font-size: 12px; }
.achievement-row__status { color: var(--good); font-size: 22px; }

.leaderboard-group { display: grid; gap: 5px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #111820; }
.leaderboard-group h2 { margin: 0 0 3px; font-size: 15px; color: var(--gold); }
.leaderboard-empty { margin: 0; color: var(--muted); font-size: 12px; }
.leaderboard-row { display: grid; grid-template-columns: 40px 1fr auto; gap: 8px; padding: 5px 2px; border-top: 1px solid var(--line); align-items: center; }
.leaderboard-row time, .leaderboard-rank { color: var(--muted); font-size: 12px; }

.menu__hint {
  margin: -6px 0 16px;
  color: var(--muted);
  font-size: 13px;
}

.danger-button {
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid var(--bad);
  border-radius: 8px;
  background: transparent;
  color: var(--bad);
  cursor: pointer;
}

.onboarding {
  display: grid;
  gap: 16px;
}

.onboarding h1 {
  margin: 0;
}

.onboarding__text {
  margin: 0;
  font-size: 18px;
  line-height: 1.5;
}

.onboarding__choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.onboarding__choices:empty {
  display: none;
}

.choice-button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111820;
  color: var(--text);
  cursor: pointer;
}

.choice-button.is-selected {
  border-color: var(--gold);
  background: #263144;
}

.onboarding__footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.onboarding__step {
  color: var(--muted);
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.notice {
  padding: 10px 12px;
  color: #211907;
  background: #ffd978;
  border-radius: 8px;
}

.pause-card {
  display: grid;
  gap: 20px;
  text-align: center;
}

.pause-card strong {
  font-size: 30px;
}

.pause-card__actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.countdown {
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(64px, 15vw, 150px);
  font-weight: 900;
  color: var(--gold);
  opacity: 0;
}

.countdown.is-visible {
  opacity: 1;
}

.mobile-input {
  user-select: text;
  -webkit-user-select: text;
  position: absolute;
  width: 1px;
  height: 1px;
  left: -20px;
  top: -20px;
  opacity: 0;
}

.measure {
  position: absolute;
  visibility: hidden;
  font-size: var(--ticker-font);
  white-space: pre;
}

.debug-panel {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 9;
  display: flex;
  gap: 8px;
}

.debug-panel button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #202735;
  color: var(--text);
  cursor: pointer;
}

.ad-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(8, 10, 14, 0.86);
}

.ad-modal__card {
  width: min(360px, calc(100vw - 32px));
  display: grid;
  gap: 14px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  text-align: center;
}

.ad-modal__card strong {
  font-size: 24px;
}

.ad-modal__card p {
  margin: 0;
  color: var(--muted);
}

.ad-modal__timer {
  font-size: 58px;
  color: var(--gold);
  font-weight: 900;
}

@keyframes shake {
  0%, 100% { transform: translateX(var(--ticker-x, 0)); }
  25% { transform: translateX(calc(var(--ticker-x, 0) - 2px)); }
  75% { transform: translateX(calc(var(--ticker-x, 0) + 2px)); }
}

@keyframes floatScore {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(-30px); opacity: 0; }
}

@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -42%) scale(0.9); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(1.05); }
}

@keyframes dangerPulse {
  50% { opacity: 0.48; }
}

@media (max-width: 760px) {
  .menu-tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .menu-tab {
    padding: 0 4px;
  }

  .app {
    grid-template-rows: auto minmax(220px, 1fr) auto minmax(160px, 30vh);
  }

  .hud {
    grid-template-columns: 1fr 1fr 1fr 1fr 42px;
    gap: 8px;
    padding: 8px;
    font-size: 14px;
  }

  .hud__label,
  .hud__group span {
    font-size: 11px;
  }

  .hud__group {
    display: grid;
    gap: 2px;
  }
}

/* "Reduced motion": no shakes, no scaling banners, no falling characters. */
.reduced-motion .ticker-track.is-shaking {
  animation: none;
}

.reduced-motion .banner.is-visible {
  animation: fade 900ms ease both;
}

.reduced-motion .unit--missed {
  transform: none;
}

.reduced-motion .popup {
  animation: fade 600ms ease forwards;
}

@keyframes fade {
  0% { opacity: 0; }
  15% { opacity: 1; }
  100% { opacity: 0; }
}

.menu input[type="range"] {
  width: 100%;
  accent-color: var(--gold);
}

/* Small portal window: Y8 shows the game in about 800x450 until the player expands it. */
@media (max-height: 560px) {
  :root {
    --ticker-font: clamp(20px, 3vw, 32px);
  }

  /* Shrink the typing area, not the scene: the pixel world keeps its full 240 px. */
  .app {
    grid-template-rows: 42px minmax(96px, 1fr) auto minmax(180px, 56vh);
  }

  .hud {
    gap: 10px;
    padding: 0 10px;
    font-size: 13px;
  }

  .hud__label,
  .hud__group span {
    font-size: 11px;
  }

  .icon-button {
    min-height: 32px;
    width: 32px;
    font-size: 16px;
  }

  .progress-panel {
    padding: 6px 12px 8px;
  }

  .progress-bar {
    height: 12px;
  }

  .menu,
  .pause-card,
  .ad-modal__card {
    padding: 14px;
  }

  .menu h1 {
    margin-bottom: 10px;
    font-size: 24px;
  }

  .menu__row,
  .menu-tabs {
    margin-bottom: 10px;
  }

  .primary-button,
  .secondary-button,
  .danger-button,
  .menu select {
    min-height: 34px;
  }

  .theme-cards,
  .meta-list {
    max-height: 40vh;
  }

  .y8-board {
    grid-template-rows: auto 150px;
  }

  .onboarding__text {
    font-size: 15px;
  }
}

.y8-account {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.y8-account p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

/* The SDK sets height:100% inline on its iframe, so the height lives on the container. */
.y8-board {
  display: grid;
  grid-template-rows: auto 240px;
  gap: 6px;
  margin-bottom: 12px;
}

.y8-board iframe {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111820;
}
