:root {
  --bg: #FBF3E6;
  --ink: #3B2416;
  --line: #1A1A1A;
  --card: #FFFFFF;
  --muted: #8A7563;
  --accent: #FFD23F;
  --red: #E53935;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

.loading {
  position: fixed; inset: 0; display: flex; flex-direction: column; gap: 10px;
  align-items: center; justify-content: center; font-size: 20px;
}
.loading img { animation: bob 1s ease-in-out infinite alternate; }
@keyframes bob { from { transform: translateY(0) rotate(-6deg); } to { transform: translateY(-10px) rotate(6deg); } }

/* ---------- select screen */
#select { max-width: 980px; margin: 0 auto; padding: 18px 16px 110px; }
.top h1 { margin: 0; font-size: clamp(30px, 6vw, 46px); font-weight: 800; line-height: 1.1; text-align: center; }
.top p { margin: 4px 0 14px; text-align: center; color: var(--muted); }

.slots { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 14px; }
.slot {
  flex: 1 1 0; max-width: 340px; display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 3px solid var(--line); border-radius: 18px; padding: 8px 12px;
  box-shadow: 0 4px 0 var(--line); text-align: left; transition: transform .1s;
}
.slot.active { outline: 4px solid var(--accent); outline-offset: 2px; }
.slot-img { width: 54px; height: 54px; border-radius: 50%; background: #EFE4D2 center/contain no-repeat; flex: none; }
.slot-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.slot-text small { color: var(--muted); font-size: 13px; }
.slot-text b { font-size: 19px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vs { font-weight: 800; font-size: 26px; -webkit-text-stroke: 1px var(--line); color: #fff; text-shadow: 0 2px 0 var(--line); }

.grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.card[hidden] { display: none; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 0 0 12px; }
.chip {
  font-size: 14px; font-weight: 800; padding: 4px 12px; border-radius: 99px; background: var(--card);
  border: 2px solid var(--line); box-shadow: 0 2px 0 var(--line); color: var(--line);
}
.chip.on { background: var(--accent); }
@media (max-width: 860px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 640px) { .chip { font-size: 12px; padding: 3px 9px; } .filters { gap: 5px; } }
@media (max-width: 640px) {
  .grid { gap: 6px; }
  .card { padding: 6px 2px 5px; border-radius: 14px; border-width: 2px; box-shadow: 0 3px 0 var(--line); }
  .card img { width: 86%; }
  .card b { font-size: 13px; }
  .card .tag { font-size: 10px; padding: 0 5px; border-width: 1.5px; }
  .card .meta { display: none; }
  .card .pick { font-size: 10px; padding: 0 5px; top: 3px; right: 3px; }
  .slot { padding: 6px 8px; gap: 6px; }
  .slot-img { width: 42px; height: 42px; }
  .slot-text b { font-size: 16px; }
}
.card {
  position: relative; background: var(--card); border: 3px solid var(--line); border-radius: 18px;
  padding: 10px 8px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  box-shadow: 0 4px 0 var(--line); transition: transform .08s;
}
.card:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.card img { width: min(110px, 80%); aspect-ratio: 1; object-fit: contain; }
.card b { font-size: 17px; font-weight: 800; line-height: 1.1; text-align: center; min-height: 2.2em; display: flex; align-items: center; }
.card .meta { font-size: 13px; color: var(--muted); }
.card .tag { font-size: 12px; font-weight: 800; color: #fff; border-radius: 99px; padding: 1px 9px; border: 2px solid var(--line); }
.card .pick {
  position: absolute; top: 6px; right: 6px; font-size: 12px; font-weight: 800; padding: 0 8px;
  border-radius: 99px; border: 2px solid var(--line); background: var(--accent);
}
.card.sel0, .card.sel1 { outline: 4px solid var(--accent); outline-offset: 1px; }

.detail {
  margin-top: 14px; background: var(--card); border: 3px solid var(--line); border-radius: 18px;
  padding: 12px 16px; box-shadow: 0 4px 0 var(--line); min-height: 60px;
}
.detail h3 { margin: 0 0 2px; font-size: 22px; font-weight: 800; }
.detail .sub { color: var(--muted); font-size: 14px; margin-bottom: 6px; }
.detail dl { margin: 0; display: grid; grid-template-columns: 120px 1fr; gap: 4px 10px; font-size: 15px; }
.detail dt { font-weight: 800; }
.detail dd { margin: 0; }
@media (max-width: 520px) { .detail dl { grid-template-columns: 1fr; } .detail dd { margin-bottom: 4px; } }

.actions {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 10px; justify-content: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 35%);
}

.btn {
  border: 3px solid var(--line); border-radius: 14px; background: #fff; padding: 8px 18px;
  font-weight: 800; font-size: 17px; box-shadow: 0 4px 0 var(--line); white-space: nowrap;
  display: inline-flex; align-items: center; gap: 8px;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.btn.primary { background: var(--accent); font-size: 20px; padding: 10px 34px; }
.btn.ghost { background: #F3EADB; }
.btn.rec .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--red); border: 2px solid var(--line); }
.btn.rec.on { background: var(--red); color: #fff; }
.btn.rec.on .dot { background: #fff; animation: blink 1s infinite; }
.btn:disabled { opacity: .5; pointer-events: none; }
@keyframes blink { 50% { opacity: .2; } }

/* ---------- battle screen */
#battle { display: flex; align-items: center; justify-content: center; gap: 18px; height: 100dvh; padding: 10px; }
.stage { height: 100%; display: flex; align-items: center; justify-content: center; min-width: 0; }
#cv {
  height: min(100%, calc((100vw - 20px) * 16 / 9)); max-height: 100%; aspect-ratio: 9 / 16; width: auto;
  border-radius: 16px; box-shadow: 0 0 0 3px var(--line), 0 8px 0 var(--line); background: var(--bg);
}
.side { display: flex; flex-direction: column; gap: 12px; width: 220px; }
.controls { display: flex; flex-direction: column; gap: 10px; }
.recinfo {
  background: #fff; border: 3px solid var(--line); border-radius: 14px; padding: 10px 12px; font-size: 14px;
  box-shadow: 0 4px 0 var(--line); line-height: 1.35;
}
.recinfo a { color: #1565C0; font-weight: 800; word-break: break-all; }

@media (max-aspect-ratio: 4/5) {
  #battle { flex-direction: column; gap: 8px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
  .stage { flex: 1 1 auto; min-height: 0; width: 100%; }
  #cv { height: 100%; max-width: 100%; }
  .side { width: 100%; }
  .controls { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 6px; }
  .controls .btn { font-size: 14px; padding: 6px 10px; border-width: 2px; box-shadow: 0 3px 0 var(--line); }
  .recinfo { font-size: 13px; }
}
