@font-face {
  font-family: Jua;
  src: url('../assets/fonts/Jua-Regular.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Noto Sans KR';
  src: url('../assets/fonts/NotoSansKR.ttf') format('truetype');
  font-weight: 100 900;
  font-display: swap;
}
:root {
  --background: #e8f6fa;
  --surface: #fff;
  --text: #153e50;
  --muted: #496776;
  --primary: #167da5;
  --accent: #ffd166;
  --opponent: #e87967;
  --border: #bedde7;
  --back-ink: #b9e9f4;
  --back-shadow: #105c7b;
  --action-shadow: #c49332;
  --success: #197458;
  font-family: 'Noto Sans KR', sans-serif;
  font-synthesis: none;
  color: var(--text);
  background: var(--background);
}
* {
  box-sizing: border-box;
}
html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  position: fixed;
  inset: 0;
  margin: 0;
}

button {
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled {
  cursor: default;
}
button:focus-visible {
  outline: 3px solid var(--opponent);
  outline-offset: 4px;
}
h1,
h2,
.turn,
.score b {
  font-family: Jua, sans-serif;
  font-weight: 400;
}
h1 {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 32px;
  margin: 0;
}
h1 svg {
  width: 36px;
  height: 36px;
  color: var(--primary);
}
h2 {
  font-size: 32px;
  margin: 0 0 20px;
}
.app {
  max-width: 1400px;
  margin: auto;
  height: var(--viewport-height, 100dvh);
  overflow: hidden;
  padding: max(24px, env(safe-area-inset-top))
    max(32px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom))
    max(32px, env(safe-area-inset-left));
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.tagline {
  color: var(--muted);
  font-size: 13px;
  margin: 5px 0 0;
}
.play-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.quiet,
.primary,
.choice {
  border-radius: 10px;
  min-height: 48px;
  padding: 10px 18px;
  font-weight: 700;
}
.quiet {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.primary {
  background: var(--accent);
  color: var(--text);
  border: 0;
  box-shadow: 0 3px 0 var(--action-shadow);
}
.quiet:hover:not(:disabled),
.primary:hover:not(:disabled),
.choice:hover:not(:disabled) {
  filter: brightness(0.96);
}
.quiet:active:not(:disabled),
.primary:active:not(:disabled) {
  transform: translateY(2px);
}
.primary:disabled,
.choice:disabled {
  opacity: 0.45;
}
.arena {
  touch-action: manipulation;
  min-width: 0;
}
.scorebar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}
.score {
  display: flex;
  align-items: center;
  justify-self: start;
  gap: 20px;
  min-width: 160px;
  padding: 8px 14px;
  border-bottom: 4px solid transparent;
}
.score.opponent {
  justify-self: end;
}
.score.active {
  border-color: var(--primary);
}
.score.opponent.active {
  border-color: var(--opponent);
}
.score strong {
  overflow-wrap: anywhere;
  font-size: 14px;
  display: block;
}
.score small {
  color: var(--muted);
  font-size: 12px;
}
.score b {
  font-size: 36px;
  font-variant-numeric: tabular-nums;
}
.turn {
  font-size: 26px;
  text-align: center;
}
.turn small {
  display: block;
  font-family: 'Noto Sans KR', sans-serif;
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}
.board {
  display: grid;
  grid-template-columns: repeat(var(--cols, 6), var(--card-width, 100px));
  gap: var(--gap, 12px);
  margin: auto;
}
.card {
  width: var(--card-width, 100px);
  height: calc(var(--card-width, 100px) * 1.4);
  position: relative;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #153e50;
  perspective: 700px;
}
.card-face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  overflow: hidden;
}
.back {
  background: var(--primary);
  color: var(--back-ink);
  box-shadow: 0 4px 0 var(--back-shadow);
  display: grid;
  place-items: center;
}
.back-frame {
  position: absolute;
  inset: 7%;
  border: 1px solid var(--back-ink);
  border-radius: 3px;
}
.back svg {
  width: 60%;
  height: 45%;
  margin-top: -10%;
}
.back-name {
  position: absolute;
  bottom: 13%;
  font-family: Jua, sans-serif;
  font-size: clamp(9px, calc(var(--card-width) * 0.12), 22px);
}
body[data-deck='safari'] .back {
  background-image: repeating-linear-gradient(
    135deg,
    transparent 0,
    transparent 10px,
    #e2e8bd0c 10px,
    #e2e8bd0c 11px
  );
}
.front {
  visibility: hidden;
  background: #fff;
  border: 1px solid #b9cdd5;
  box-shadow: 0 3px 0 #bfd5df;
}
.revealed .front {
  visibility: visible;
}
.front.newly-revealed {
  animation: reveal 180ms ease-out;
}
.revealed .back {
  visibility: hidden;
}
.animal-picture {
  position: absolute;
  inset: 5% 6% 28%;
  display: grid;
  place-items: center;
}
.picture {
  display: block;
  width: 100%;
  height: 100%;
}
.card-label {
  position: absolute;
  left: 5%;
  right: 5%;
  bottom: 6%;
  text-align: center;
}
.card-label strong {
  display: block;
  font-size: min(18px, calc(var(--card-width) * 0.85 / var(--name-length, 8)));
  line-height: 1.15;
  white-space: nowrap;
}
.card-label small {
  display: block;
  font-size: clamp(9px, calc(var(--card-width) * 0.08), 13px);
  color: #496776;
  line-height: 1.2;
  margin-top: 4px;
}
.card:active:not(:disabled) {
  transform: translateY(2px);
}
.card.found .front {
  visibility: visible;
  border-color: var(--success);
}
.card.newly-found .front {
  animation: celebrate 300ms ease-out;
}
.match-mark {
  position: absolute;
  right: 4px;
  top: 4px;
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--success);
  color: white;
  font-size: 12px;
}
.dense-board .card-label small {
  display: none;
}
.dense-board .animal-picture {
  bottom: 28%;
}
.board-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  margin-top: 24px;
}
.drawer-backdrop,
.modal-scrim {
  position: fixed;
  inset: 0;
  background: #163b4455;
}
.drawer-backdrop {
  z-index: 4;
}
.settings-drawer {
  position: fixed;
  z-index: 5;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(600px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 16px 48px #16364230;
}
.field {
  margin-bottom: 16px;
}
.settings-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 20px;
}
.field-size {
  grid-column: 1 / -1;
}
.field label {
  display: block;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
}
.choices {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.choice {
  padding: 8px 14px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.choice.selected {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.deck-preview {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 0 16px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.deck-preview svg {
  width: 44px;
  height: 44px;
  color: var(--primary);
}
.deck-preview strong,
.deck-preview small {
  display: block;
}
.deck-preview small {
  color: var(--muted);
  margin-top: 4px;
}
.settings .primary {
  width: 100%;
}
.setting-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}
.setting-note:empty {
  display: none;
}
.load-error {
  background: #fce5e9;
  color: #ad3644;
  padding: 12px;
  border-radius: 6px;
  font-size: 14px;
}
.modal-scrim {
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
}
.modal {
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 32px;
  max-width: 480px;
  width: 100%;
  text-align: center;
  box-shadow: 0 16px 48px #16364230;
}
.modal p {
  color: var(--muted);
  line-height: 1.7;
}
.actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 24px;
}
.result-mark svg {
  width: 64px;
  height: 64px;
  color: var(--primary);
}
@keyframes reveal {
  from {
    transform: rotateY(70deg);
    opacity: 0.5;
  }
  to {
    transform: rotateY(0);
    opacity: 1;
  }
}
@keyframes celebrate {
  50% {
    transform: translateY(-4px);
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
@media (max-width: 700px) {
  .settings-options {
    grid-template-columns: 1fr;
  }
  .app {
    padding: max(16px, env(safe-area-inset-top))
      max(16px, env(safe-area-inset-right))
      max(16px, env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
  }
  header {
    align-items: flex-start;
    flex-wrap: wrap;
    margin-bottom: 16px;
  }
  h1 {
    font-size: 28px;
  }
  .play-controls {
    gap: 6px;
  }
  .quiet {
    padding: 8px 12px;
    font-size: 13px;
  }
  .scorebar {
    grid-template-columns: 1fr auto 1fr;
    gap: 4px;
    margin-bottom: 16px;
  }
  .score {
    min-width: 0;
    gap: 8px;
    padding: 8px 2px;
  }
  .score strong {
    overflow-wrap: anywhere;
    font-size: 12px;
  }
  .score small {
    display: none;
  }
  .score b {
    font-size: 26px;
  }
  .turn {
    font-size: 18px;
  }
  .turn small {
    font-size: 10px;
    max-width: 100px;
  }
  .board-footer {
    font-size: 11px;
    flex-wrap: wrap;
  }
  .settings-drawer {
    padding: 20px;
  }
  h2 {
    font-size: 28px;
  }
  .modal {
    padding: 24px;
  }
  .actions {
    flex-wrap: wrap;
  }
}
@media (max-height: 650px) and (min-width: 701px) {
  .app {
    padding-top: 12px;
  }
  header {
    margin-bottom: 12px;
  }
  .scorebar {
    margin-bottom: 12px;
  }
  .tagline {
    display: none;
  }
}

.field input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}
.field input:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}
.score > div {
  min-width: 0;
}
.turn {
  overflow-wrap: anywhere;
  min-width: 0;
}

.pwa-panel {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 12px;
}
.pwa-panel p {
  margin: 0 0 8px;
}
.pwa-status {
  color: var(--text);
  font-weight: 700;
}

/* English animal names wrap without shrinking the text to fit one line. */
html[lang='en'] .card-label strong {
  font-size: clamp(10px, calc(var(--card-width) * 0.11), 16px);
  white-space: normal;
  overflow-wrap: anywhere;
  text-wrap: balance;
}
html[lang='en'] .card-label small {
  overflow-wrap: anywhere;
}

html[lang='en'] .front {
  display: flex;
  flex-direction: column;
  padding: 5% 6% 6%;
  gap: 4px;
}
html[lang='en'] .animal-picture {
  position: relative;
  inset: auto;
  flex: 1;
  min-height: 0;
}
html[lang='en'] .card-label {
  position: static;
  flex-shrink: 0;
}
.scorebar.solo {
  grid-template-columns: auto 1fr;
}
