:root {
  color-scheme: light dark;
  --bg: #eef0ea;
  --surface: #fbfcf8;
  --ink: #1f2420;
  --muted: #646d65;
  --line: #cdd3c8;
  --accent: #2e6b5a;
  --accent-ink: #ffffff;
  --back: #3c5a50;
  --back-pattern: #4a6c61;
  --active: #e0a51b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16191a;
    --surface: #22272a;
    --ink: #e6ebe6;
    --muted: #9aa49c;
    --line: #3a4245;
    --accent: #4f9a84;
    --back: #2c4a42;
    --back-pattern: #365a50;
    --active: #f2c14e;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0 max(16px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  /* ダブルタップでの拡大を止めて、連続タップを素直に受け付ける */
  touch-action: manipulation;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: calc(8px + env(safe-area-inset-top));
}

.header-buttons {
  display: flex;
  gap: 6px;
}

h1 {
  margin: 8px 0;
  font-size: 1.4rem;
  letter-spacing: 0.1em;
}

h2 {
  margin: 14px 0 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.text-button {
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
}

.text-button:disabled {
  opacity: 0.45;
}

.target {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.target p {
  margin: 0;
}

.target-label {
  color: var(--muted);
  font-size: 0.75rem;
}

.target-name {
  font-size: 1.3rem;
  font-weight: 700;
}

.target-example {
  color: var(--muted);
  font-size: 0.85rem;
}

.status {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
  margin: 10px 0 8px;
}

.status p {
  margin: 0;
}

.turn {
  font-size: 0.9rem;
  font-weight: 600;
}

.scores {
  display: flex;
  gap: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.card {
  position: relative;
  aspect-ratio: 4 / 5;
  min-height: 60px;
  padding: 0;
  border: 1.5px solid var(--back);
  border-radius: 10px;
  /* 表に何も描かれていないことを、無地ではなく裏模様で示す */
  background: repeating-linear-gradient(45deg, var(--back) 0 8px, var(--back-pattern) 8px 16px);
  color: #23211d;
  font-size: 1.8rem;
  font-weight: 700;
  transition: transform 0.15s, background 0.15s;
}

.card-heard::after {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--surface);
  content: '';
  opacity: 0.8;
}

.card-active {
  border-color: var(--active);
  background: var(--active);
  transform: scale(1.05);
  animation: ring 0.6s ease-out;
}

.card-taken {
  border: 1.5px dashed var(--line);
  background: transparent;
}

.card-taken::after {
  display: none;
}

@keyframes ring {
  from {
    box-shadow: 0 0 0 0 var(--active);
  }
  to {
    box-shadow: 0 0 0 14px transparent;
  }
}

.log {
  min-height: 2.8em;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: pre-line;
}

.pairs-area {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.pairs {
  margin: 0;
  padding: 0;
  list-style: none;
}

.pair {
  margin-bottom: 4px;
  font-size: 0.85rem;
}

.action {
  min-height: 44px;
  padding: 0 16px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1rem;
  font-weight: 600;
}

dialog {
  max-width: min(480px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 20px;
  border: none;
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  line-height: 1.6;
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.45);
}

.dialog-title {
  margin-top: 0;
  color: var(--ink);
  font-size: 1.2rem;
}

.tip {
  color: var(--muted);
  font-size: 0.9rem;
}

.dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

@media (prefers-reduced-motion: reduce) {
  .card-active {
    transform: none;
    animation: none;
  }
}
