:root {
  --bg: #fbfaf7;
  --paper: #fff;
  --ink: #393a42;
  --muted: #92958e;
  --line: #eeeae5;
  --mint: #dff2e8;
  --green: #8fc9a9;
  --lav: #eee8fa;
  --purple: #aa98d5;
  --peach: #fae7dc;
  --coral: #e9a48c;
  --yellow: #f7efce;
  --shadow: 0 9px 26px #393a3010;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-rounded, "Hiragino Maru Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  letter-spacing: 0.015em;
}
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}
button:focus-visible {
  outline: 3px solid #9fcdb1;
  outline-offset: 3px;
}
.app {
  max-width: 520px;
  min-height: 100svh;
  margin: auto;
  padding: env(safe-area-inset-top) 20px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}
.top {
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.brand {
  font-size: 19px;
  font-weight: 900;
  letter-spacing: 0.13em;
}
.brand i {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--green);
  border-radius: 50%;
  margin-left: 5px;
}
.brand-kana {
  display: block;
  margin-top: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3em;
  line-height: 1;
  color: var(--muted);
  white-space: nowrap;
}
/* 幅のせまい画面では、名前が右のボタンとぶつからないよう少し詰める */
@media (max-width: 340px) {
  .brand {
    font-size: 18px;
    letter-spacing: 0.07em;
  }
}
.topright {
  display: flex;
  align-items: center;
  gap: 8px;
}
.pill {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 8px 11px;
  font-size: 11px;
  font-weight: 700;
}
.hero {
  text-align: center;
  padding: 30px 0 20px;
}
.eyebrow {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.16em;
  font-weight: 800;
}
.hero h1 {
  font-size: clamp(19px, 5.4vw, 30px);
  margin: 8px 0 6px;
  letter-spacing: 0.015em;
  white-space: nowrap;
}
.hero p {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
}
.section-label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 800;
  letter-spacing: 0.12em;
  margin: 18px 2px 10px;
}
.games {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
  align-items: stretch;
}
.game {
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 15px;
  background: white;
  text-align: left;
  box-shadow: var(--shadow);
  min-height: 120px;
  transition: transform 0.15s;
}
.game:active {
  transform: scale(0.98);
}
.glyph {
  width: 39px;
  height: 39px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 21px;
  margin-bottom: 10px;
}
.g1 {
  background: var(--mint);
}
.g2 {
  background: var(--lav);
}
.g3 {
  background: var(--peach);
}
.g4 {
  background: var(--yellow);
}
.game b {
  display: block;
  font-size: 14px;
}
.game small {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: 11px;
  line-height: 1.55;
  color: var(--muted);
  text-wrap: balance;
  min-height: 34px;
}
.panel {
  background: white;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 17px;
  box-shadow: var(--shadow);
  margin-top: 13px;
}
.panelhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panelhead b {
  font-size: 13px;
}
.stats {
  display: flex;
  gap: 8px;
}
.stat {
  background: #faf9f6;
  border-radius: 13px;
  padding: 8px 12px;
  flex: 1;
  text-align: center;
}
.stat small {
  display: block;
  font-size: 10px;
  color: var(--muted);
}
.stat strong {
  font-size: 16px;
}
.difficulty {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}
.difficulty button {
  flex: 1;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 9px 2px;
  font-size: 11px;
}
.difficulty button.active {
  background: var(--mint);
  border-color: #b9dfca;
  font-weight: 800;
}
.playarea {
  min-height: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px 0;
}
.prompt {
  font-size: 14px;
  color: var(--muted);
  margin: 0 0 16px;
}
.big {
  font-size: 26px;
  font-weight: 900;
  margin: 6px;
}
.primary {
  border: 0;
  border-radius: 16px;
  background: var(--ink);
  color: white;
  padding: 14px 24px;
  font-weight: 800;
  box-shadow: 0 5px 0 #20212820;
}
.secondary {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 11px 17px;
  font-size: 12px;
}
.gridcolors {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
  width: 100%;
  max-width: 350px;
  margin: 0 auto;
}
.tile {
  aspect-ratio: 1;
  border: 0;
  border-radius: 15px;
  box-shadow: inset 0 0 0 1px #00000008;
  transition:
    transform 0.12s,
    filter 0.12s;
}
.tile:active {
  transform: scale(0.94);
}
.timer {
  font-size: 30px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.message {
  font-size: 13px;
  color: var(--muted);
  min-height: 22px;
  margin: 12px 0;
}
.result {
  font-size: 34px;
  font-weight: 900;
  margin: 10px;
}
.footer {
  margin-top: auto;
  text-align: center;
  color: #b0ada5;
  font-size: 10px;
  padding: 26px 0 5px;
}
.hidden {
  display: none !important;
}
.iconbtn {
  width: 35px;
  height: 35px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  display: grid;
  place-items: center;
  font-size: 16px;
}

/* COLOR FIND: keep the color board and prompt inside the play card on narrow screens */
.playarea {
  width: 100%;
  min-width: 0;
  overflow: hidden;
  padding: 16px 12px;
}
.playarea .prompt {
  max-width: 100%;
  padding: 0 4px;
  overflow-wrap: anywhere;
}
.gridcolors {
  width: 100%;
  max-width: 350px;
  min-width: 0;
  gap: clamp(5px, 2vw, 9px);
  box-sizing: border-box;
}
.gridcolors .tile {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  padding: 0;
  box-sizing: border-box;
}

/* Latin keeps the original rounded system font; Japanese glyph runs are explicitly wrapped below */
html,
body,
body *,
body *::before,
body *::after,
button,
input,
select,
textarea {
  font-family: ui-rounded, sans-serif;
}
.font-ja {
  font-family: "Zen Maru Gothic", sans-serif !important;
}
.flower-mark {
  display: block;
  overflow: visible;
}
#game > .panel {
  padding: 12px;
  margin-top: 9px;
}
#game .difficulty {
  margin-top: 8px;
  gap: 5px;
}
#game .difficulty button {
  padding: 8px 2px;
}
#stage.playarea {
  min-height: clamp(190px, 27svh, 238px);
  padding: 10px 10px;
  gap: 1px;
}
#stage .prompt {
  margin: 0 0 7px;
}
#stage .big {
  margin: 3px;
}
#stage .message {
  margin: 6px 0;
  min-height: 18px;
}
#stage .primary {
  padding: 11px 22px;
}
#game > div:last-of-type {
  margin-top: 8px !important;
}
#game + .footer {
  padding: 12px 0 2px;
}
body:has(#game:not(.hidden)) .top {
  height: 56px;
}
body:has(#game:not(.hidden)) .app {
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
.flower-mark {
  display: inline-block;
  vertical-align: middle;
  overflow: visible;
  flex: none;
}
@media (max-height: 760px) {
  #stage.playarea {
    min-height: 176px;
    padding: 8px;
  }
  #game > .panel {
    padding: 10px;
    margin-top: 7px;
  }
  #game > .panelhead {
    margin: 6px 2px !important;
  }
  #stage .prompt {
    margin-bottom: 4px;
  }
  #stage .message {
    margin: 3px 0;
  }
  #stage .primary {
    padding: 9px 20px;
  }
}

/* PokeRila compact viewport layout: no page scrolling while a game is open */
body:has(#game:not(.hidden)) {
  overflow: hidden;
}
body:has(#game:not(.hidden)) .app {
  height: 100dvh;
  min-height: 0;
  box-sizing: border-box;
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
  padding-bottom: calc(5px + env(safe-area-inset-bottom));
}
body:has(#game:not(.hidden)) .top {
  height: 48px;
  min-height: 48px;
  flex: none;
}
#game:not(.hidden) {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}
#game > .panelhead {
  flex: none;
  margin: 5px 2px 5px !important;
}
#game > .panel {
  flex: none;
  padding: 9px 11px;
  margin-top: 6px;
}
#game .difficulty {
  margin-top: 6px;
  gap: 5px;
}
#game .difficulty button {
  padding: 7px 2px;
  min-height: 34px;
}
#stage.playarea {
  flex: 1;
  min-height: 0;
  height: auto;
  padding: 7px 9px;
  gap: 0;
  justify-content: center;
}
#stage .prompt {
  margin: 0 0 4px;
  font-size: 13px;
  line-height: 1.35;
}
#stage .timer {
  font-size: clamp(22px, 5.5vw, 28px);
  line-height: 1.1;
}
#stage .big {
  margin: 2px;
  font-size: 23px;
}
#stage .message {
  margin: 4px 0;
  min-height: 16px;
  font-size: 12px;
  line-height: 1.25;
}
#stage .primary {
  padding: 9px 20px;
}
#game > div:last-of-type {
  flex: none;
  margin-top: 5px !important;
}
#game + .footer {
  display: none;
}
#board.gridcolors {
  width: min(100%, 42svh, 320px);
  max-width: 100%;
  gap: clamp(4px, 1.5vw, 7px);
  margin: 3px auto;
}
#board.gridcolors .tile {
  border-radius: clamp(7px, 2vw, 12px);
}
#stage:has(#board:not(.hidden)) .big {
  display: none;
}
#stage:has(#board:not(.hidden)) .message {
  margin: 3px 0;
}
.flower-mark {
  display: inline-block;
  vertical-align: middle;
  color: #e9b7c8;
  font-size: 1em;
  line-height: 1;
  flex: none;
  text-shadow: 0 1px 0 #f7e8d7;
}
@media (max-height: 720px) {
  #game > .panelhead {
    margin: 3px 2px !important;
  }
  #game > .panel {
    padding: 7px 9px;
    margin-top: 4px;
  }
  #game .difficulty button {
    padding: 5px 1px;
    min-height: 30px;
  }
  #stage.playarea {
    padding: 4px 7px;
  }
  #stage .message {
    margin: 2px 0;
  }
  #stage .primary {
    padding: 8px 18px;
  }
  #game > div:last-of-type {
    margin-top: 3px !important;
  }
  #board.gridcolors {
    width: min(100%, 38svh, 290px);
  }
}

/* Clear visual state for the BGM toggle */
#music {
  transition:
    color 0.18s ease,
    background 0.18s ease,
    border-color 0.18s ease;
}
#music.music-on {
  color: #438b70;
  background: #e5f3ec;
  border-color: #b9ddca;
}
#music.music-off {
  color: #77746f;
  background: #fff;
  border-color: var(--line);
}
#music:focus-visible {
  outline: 2px solid #9acbb3;
  outline-offset: 2px;
}
#stage #prompt span {
  transition: color 0.15s ease;
}

.games .game small,
.games .game small .game-kind,
.games .game small .game-desc {
  display: block !important;
  color: var(--muted) !important;
  font-weight: 400 !important;
  font-size: 11px !important;
  line-height: 1.55 !important;
}
.reflex-sparkle {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: -0.12em;
  flex: none;
  margin: 0 !important;
  color: #f0df9d;
}
.reflex-result-line {
  display: block;
  white-space: nowrap;
  line-height: 1.45;
}
.message {
  white-space: normal;
}
