@font-face {
  font-family: "Karuta Mincho";
  src: url("./assets/mincho.woff") format("woff");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --night: #141e2e;
  --panel: #1b283a;
  --ink: #282637;
  --ivory: #fbefd9;
  --sand: #eab87b;
  --pale-blue: #c1cbd6;
  --teal: #a0d0cd;
  --red: #ac3d31;
  --line: #445267;
  --display: "Karuta Mincho", "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif CJK JP", serif;
  --body: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans CJK JP", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-height: 100%; background: var(--night); }

body {
  margin: 0;
  min-height: 100svh;
  color: var(--ivory);
  font-family: var(--body);
  font-size: 1rem;
  background-color: var(--night);
  background-image:
    radial-gradient(ellipse at 50% 0%, #26374f55, transparent 66%),
    linear-gradient(90deg, #131d2d15, #131d2da0 43%, #131d2da0 57%, #131d2d15),
    url("./assets/night.webp");
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
}

button {
  font: inherit;
  cursor: pointer;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 3px solid #f8cd8f;
  outline-offset: 3px;
}

h1, h2, p { margin: 0; }
p, h2 { overflow-wrap: anywhere; }

.game {
  width: min(100%, 32rem);
  margin-inline: auto;
  padding: max(12px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
}

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 0 10px;
  border-bottom: 1px solid #8d9db344;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  line-height: 1.42;
}

.seal {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 36px;
  aspect-ratio: 1;
  background: #913b35;
  color: var(--ivory);
  border: 1px solid #e2856d;
  border-radius: 4px;
  box-shadow: inset 0 0 0 3px #913b35, inset 0 0 0 4px #ffd2a672;
  font: 700 1.18rem/1 var(--display);
  padding-bottom: 2px;
}

.series {
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.episode {
  color: var(--pale-blue);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  margin-top: 1px;
}

.sound-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  flex-shrink: 0;
  min-height: 44px;
  min-width: 82px;
  border: 1px solid #66748b;
  border-radius: 6px;
  background: #111b2abf;
  color: var(--ivory);
  padding: 5px 9px;
  font-size: 0.75rem;
  font-weight: 700;
}

.sound-icon { position: relative; width: 18px; height: 18px; }
.sound-icon::before {
  content: "";
  position: absolute;
  inset: 1px 7px 1px 0;
  background: currentColor;
  clip-path: polygon(0 34%, 40% 34%, 100% 7%, 100% 93%, 40% 66%, 0 66%);
}

.sound-icon::after, .sound-icon i {
  position: absolute;
  content: "";
  width: 8px;
  height: 12px;
  top: 3px;
  right: 0;
  border-right: 1px solid currentColor;
  border-radius: 50%;
}

.sound-icon i { width: 5px; height: 8px; top: 5px; right: 3px; }
.sound-button[aria-pressed="false"] .sound-icon::after {
  border: 0;
  border-radius: 0;
  height: 2px;
  width: 19px;
  top: 8px;
  left: 0;
  background: #ffd6a5;
  box-shadow: 0 0 0 1px #141e2e;
  transform: rotate(44deg);
}
.sound-button[aria-pressed="false"] .sound-icon i { opacity: 0; }

.intro {
  text-align: center;
  padding: 13px 0 14px;
}

.intro h1 {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: var(--display);
  font-weight: 700;
  line-height: 1.25;
}

.title-lead {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #f3bd83;
  font-size: clamp(0.98rem, 4.2vw, 1.14rem);
  letter-spacing: 0.11em;
}

.title-lead::before, .title-lead::after {
  content: "";
  width: 19px;
  height: 6px;
  border-block: 1px solid #cf8d63aa;
  transform: skewX(-28deg);
}

.title-main {
  margin-top: 0;
  padding-left: 0.065em;
  font-size: clamp(2.36rem, 10.8vw, 3.62rem);
  letter-spacing: 0.065em;
  text-shadow: 0 3px #070b1488;
}

.intro p {
  margin-top: 6px;
  color: #d7dce3;
  font-size: 0.875rem;
  letter-spacing: 0.07em;
}

.scoreboard {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 60px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(120deg, #5942363b, transparent 45%), linear-gradient(250deg, #284d5255, transparent 47%), #1c283a;
  box-shadow: 0 5px 14px #080e1935, inset 0 0 0 2px #0f18284d;
}

.score-side {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  min-width: 0;
  padding-inline: 2px;
}

.cpu-side { text-align: right; }

.score-details {
  flex-shrink: 0;
  font-size: 0.8125rem;
  line-height: 1.25;
  font-weight: 700;
}

.score {
  display: block;
  min-width: 1ch;
  color: var(--sand);
  font: 700 2.15rem/1 var(--display);
  font-variant-numeric: lining-nums tabular-nums;
}

.cpu-side .score { color: var(--teal); }

.versus {
  color: #bbc5d4;
  font: italic 700 0.8rem/1 Georgia, serif;
  letter-spacing: 0.04em;
}

.pips {
  display: flex;
  gap: 5px;
  margin-top: 6px;
}

.cpu-side .pips { justify-content: flex-end; }
.pips i {
  display: block;
  width: 13px;
  height: 5px;
  border-radius: 2px;
  border: 1px solid #7b889b;
}
.pips i.filled { background: var(--sand); border-color: var(--sand); }
.cpu-side .pips i.filled { background: var(--teal); border-color: var(--teal); }
.score.bump { animation: score-bump 340ms ease-out; }
@keyframes score-bump { 45% { transform: scale(1.27); } }

.table {
  margin-top: 10px;
  border: 1px solid #465469;
  border-radius: 10px;
  padding: 8px;
  background: linear-gradient(155deg, #263750, #1c283a 65%);
  box-shadow: 0 10px 20px #02071145, inset 0 0 0 2px #111a2966;
}

.question {
  min-height: 79px;
  display: grid;
  grid-template-rows: auto 1fr;
  align-items: center;
  padding: 8px 12px 9px;
  margin-bottom: 8px;
  border: 1px solid #e7c696;
  border-radius: 6px;
  color: var(--ink);
  background: radial-gradient(ellipse at 33% 0%, #fff3d9, #f0dfbc);
  box-shadow: inset 0 0 0 2px #ffedcd;
}

.question-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-width: 0;
  padding-bottom: 4px;
}

.question-tag {
  border-radius: 2px;
  padding: 2px 8px;
  background: #9a352d;
  color: #fff1da;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1.35;
}

.question-context {
  color: #644d40;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.question h2 {
  color: #292538;
  font: 700 clamp(1.075rem, 4.45vw, 1.375rem)/1.32 var(--display);
  text-wrap: balance;
  outline: none;
}

.arena { position: relative; isolation: isolate; }

.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.card {
  --paper: #f7e8c8;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 1px solid #cfad7b;
  border-radius: 6px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 3px #0d1729, inset 0 0 0 2px #fff2d4;
  transition: box-shadow 120ms ease, border-color 120ms ease, transform 100ms ease;
  overflow: hidden;
  text-align: center;
}

.card:disabled { cursor: default; opacity: 1; }
.card[aria-disabled="true"] { cursor: default; }
.card:focus-visible { z-index: 3; outline-offset: 2px; }
.card:enabled:not([aria-disabled="true"]):active { transform: translateY(2px); }

.art {
  display: grid;
  place-items: center;
  height: clamp(84px, 24vw, 122px);
  margin: 3px 3px 0;
  border-radius: 4px 4px 1px 1px;
  overflow: hidden;
  background: radial-gradient(ellipse at center, #f6e7c7 25%, #efd9b2 100%);
}

.art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  position: relative;
  min-height: 0;
  min-width: 0;
  -webkit-mask-image: radial-gradient(ellipse 56% 64% at center, black 81%, transparent 100%);
  mask-image: radial-gradient(ellipse 56% 64% at center, black 81%, transparent 100%);
  pointer-events: none;
}

.card-copy {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  min-height: 47px;
  padding: 4px 4px 6px;
}

.card-name {
  font-size: clamp(0.875rem, 3.8vw, 1.0625rem);
  line-height: 1.24;
  font-weight: 800;
}

.card-detail {
  color: #4a3b3d;
  font-size: clamp(0.75rem, 3.3vw, 0.875rem);
  line-height: 1.3;
  font-weight: 700;
  text-wrap: balance;
}

.card.seek {
  border-color: #9ac7c6;
  box-shadow: 0 0 0 2px #9ac7c6, 0 0 15px #a3d4ce77;
  z-index: 1;
}

.card.taken-player, .card.taken-cpu, .card.answer {
  z-index: 2;
  border-color: var(--take-color);
  box-shadow: 0 0 0 2px var(--take-color), 0 0 19px var(--take-shadow);
}
.card.taken-player, .card.taken-cpu { animation: card-take 450ms cubic-bezier(.2,.8,.24,1); }
.card.taken-player, .card.answer { --take-color: #efb65d; --take-shadow: #ffba605c; }
.card.taken-cpu { --take-color: #87c7c4; --take-shadow: #9cd5d170; }
.card.player-foul, .card.cpu-foul { border-color: #bd5a48; }

@keyframes card-take {
  33% { transform: scale(0.955) rotate(-1.4deg); }
  65% { transform: scale(1.015); }
}

.card-mark {
  position: absolute;
  z-index: 2;
  top: 7px;
  left: 7px;
  background: #81362d;
  color: #ffefd5;
  border-radius: 3px;
  padding: 3px 6px;
  font-size: 0.75rem;
  line-height: 1.25;
  font-weight: 800;
  box-shadow: 0 2px 4px #1b172d33;
}
.card.taken-player .card-mark, .card.answer .card-mark { background: #5f381d; }
.card.taken-cpu .card-mark { background: #234e53; }

.cpu-hand {
  position: absolute;
  z-index: 4;
  top: 0;
  left: 0;
  width: clamp(38px, 11.2vw, 53px);
  will-change: transform;
  pointer-events: none;
  filter: drop-shadow(2px 5px 3px #1317298e);
}

.cpu-hand img {
  display: block;
  width: 100%;
  height: auto;
  transform: translate(-52.5%, -96.1%) rotate(var(--tilt, 0deg)) scale(var(--scale, 1));
  transform-origin: 52.5% 96.1%;
  user-select: none;
}

.hit {
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  z-index: 5;
  pointer-events: none;
}

.hit::before, .hit::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 3px solid var(--hit-color, #fdd28e);
  border-radius: 50%;
  opacity: 0;
  animation: impact 420ms ease-out both;
}
.hit::after { animation-delay: 66ms; }
.hit[data-side="cpu"] { --hit-color: #afe4e0; }
@keyframes impact {
  from { transform: scale(0.28); opacity: 1; }
  to { transform: scale(1.65); opacity: 0; }
}

.controls { margin-top: 10px; }

.action-button {
  display: flex;
  position: relative;
  width: 100%;
  min-height: 54px;
  justify-content: center;
  align-items: center;
  gap: 11px;
  padding: 7px 12px;
  border: 1px solid #eb9472;
  border-radius: 7px;
  background: linear-gradient(180deg, #b64838, #9b302a);
  box-shadow: 0 3px #541f24, inset 0 0 0 2px #f4b08724, 0 8px 16px #05091345;
  color: #fff2d8;
  font: 700 1.32rem/1.2 var(--display);
  letter-spacing: 0.1em;
}

.action-button:active { transform: translateY(2px); box-shadow: 0 1px #541f24; }

.action-ornament {
  position: relative;
  width: 15px;
  height: 15px;
  border: 1px solid #ffd9a6;
  transform: rotate(45deg);
  margin-right: 2px;
}
.action-ornament::after {
  content: "";
  position: absolute;
  inset: 3px;
  background: #ffe6bd;
}

.feedback {
  min-height: 54px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 6px 10px;
  border: 1px solid #536177;
  border-left: 3px solid var(--feedback-accent, #9bafc5);
  border-radius: 6px;
  color: #eae8e1;
  background: #101b2ceb;
}

.feedback[data-tone="player"] { --feedback-accent: var(--sand); }
.feedback[data-tone="cpu"] { --feedback-accent: var(--teal); }
.feedback[data-tone="foul"] { --feedback-accent: #f1927a; }

#feedback-title {
  font-size: 0.9375rem;
  font-weight: 800;
  line-height: 1.32;
  color: var(--feedback-accent, #f8eddb);
}

#feedback-detail { font-size: 0.8125rem; line-height: 1.4; }
#feedback-detail:empty { display: none; }

.rule {
  margin-top: 11px;
  text-align: center;
  color: #c7ced8;
  font-size: 0.75rem;
  line-height: 1.5;
}

.result { margin-top: 10px; }
.result-paper {
  padding: 16px 14px 22px;
  margin-bottom: 12px;
  text-align: center;
  color: var(--ink);
  background: radial-gradient(ellipse at 45% 22%, #fff0d5, #efd8b1);
  border: 1px solid #e8b978;
  border-radius: 9px;
  box-shadow: inset 0 0 0 4px #f4dfba, inset 0 0 0 5px #bd9260b3, 0 8px 22px #03071368;
}
.result-paper img {
  width: 126px;
  height: 101px;
  object-fit: contain;
  mask-image: radial-gradient(ellipse 55% 61% at center, black 72%, transparent 99%);
}
.result-tag { margin: 6px 0; color: #8f3a31; font-weight: 800; font-size: 0.875rem; letter-spacing: .14em; }
.result h2 { font: 700 clamp(1.52rem, 6.5vw, 2rem)/1.3 var(--display); outline: none; }
.result-scores { display: flex; gap: 12px; justify-content: center; align-items: baseline; margin: 6px 0; font: 700 2.8rem/1.2 var(--display); }
.result-scores :first-child { color: #8c4225; }
.result-scores :last-child { color: #2a5d62; }
.result-detail { font-weight: 700; font-size: 0.875rem; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media (hover: hover) {
  .sound-button:hover { background: #314057; }
  .action-button:hover { background: linear-gradient(180deg, #bf4f3f, #a5322b); }
  .card:enabled:not([aria-disabled="true"]):hover { box-shadow: 0 0 0 2px #ffe1ac, 0 4px #10192b; }
}

@media (min-width: 550px) {
  .game { padding-top: 19px; }
  .masthead { padding-bottom: 12px; }
  .intro { padding-top: 16px; padding-bottom: 17px; }
  .scoreboard { min-height: 64px; padding-inline: 15px; }
  .score-details { font-size: 0.875rem; }
  .table { margin-top: 12px; padding: 10px; }
  .question { min-height: 83px; padding-inline: 14px; margin-bottom: 10px; }
  .cards { gap: 10px; }
  .art { height: 113px; }
  .card-copy { min-height: 51px; }
}

@media (max-width: 370px) {
  .game { padding-inline: 12px; }
  .table { padding: 7px; }
  .card-detail { font-size: 0.75rem; }
}

@media (max-height: 730px) and (max-width: 549px) {
  .intro { padding: 9px 0 10px; }
  .title-main { font-size: clamp(2.1rem, 9.7vw, 2.6rem); }
  .intro p { margin-top: 3px; }
  .art { height: clamp(67px, 19.5vw, 86px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}

/* Keep the first tap above the post and floating address bar in mobile in-app browsers. */
@media (max-width:650px) {
  .game { padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
  .game[data-phase="title"] { display: grid; grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "header" "intro" "start" "score" "table" "rule"; }
  .masthead { grid-area: header; }
  .intro { grid-area: intro; }
  .controls { grid-area: start; }
  .scoreboard { grid-area: score; }
  .table { grid-area: table; }
  .rule { grid-area: rule; }
  .game[data-phase="title"] .controls { margin: 0 0 12px; }
}
@media (max-width:650px) and (max-height:730px) {
  .game:not([data-phase="title"]) .intro { padding-block: 5px; }
  .game:not([data-phase="title"]) .intro h1 { display: flex; align-items: baseline; justify-content: center; gap: 6px; }
  .game:not([data-phase="title"]) .title-main { font-size: 1.4rem; }
  .game:not([data-phase="title"]) .intro p { display: none; }
  .game:not([data-phase="title"]) .art { height: clamp(44px, 10svh, 72px); }
  .result-paper img { width: 70px; height: 52px; }
}
