:root {
  --bg: #eef4fb;
  --card: #ffffff;
  --line: #d6e2f0;
  --blue: #2b6cb0;
  --blue-dark: #1e4e8c;
  --blue-soft: #ebf4ff;
  --text: #1a202c;
  --muted: #5a6778;
  --good: #2f855a;
  --bad: #c53030;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}
body { display: flex; flex-direction: column; height: 100dvh; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

#topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
#brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; white-space: nowrap; }
#tabs { flex: 1; display: flex; gap: 6px; justify-content: center; }
.tab {
  padding: 9px 16px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-weight: 800;
  font-size: 15px;
  white-space: nowrap;
}
.tab.active { border-color: var(--blue); background: var(--blue-soft); color: var(--blue-dark); }
#collected { font-size: 15px; color: var(--muted); white-space: nowrap; }
#collected b { color: var(--text); }

#main { flex: 1 1 auto; overflow-y: auto; padding: 16px; }
.page { max-width: 980px; margin: 0 auto; }
.intro h1 { margin: 0 0 4px; font-size: 26px; }
.intro p { margin: 0 0 16px; color: var(--muted); font-size: 16px; }

/* ---------- collection grid ---------- */

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 12px; }
.grid.small { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); max-width: 640px; margin: 0 auto 16px; }
.mini {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 170px;
  padding: 0 10px 12px;
  border: 0;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 2px 0 var(--line), 0 0 0 2px var(--line);
  text-align: center;
  overflow: hidden;
  transition: transform .1s;
}
.mini:not(.locked) { box-shadow: 0 3px 0 color-mix(in srgb, var(--c) 60%, #000), 0 0 0 3px var(--c); }
.mini::before {
  content: "";
  display: block;
  align-self: stretch;
  height: 14px;
  margin: 0 -10px 4px;
  background: var(--c, #cbd5e0);
}
.mini:active { transform: scale(.97); }
.m-emoji { font-size: 44px; line-height: 1.15; }
.m-name { font-weight: 800; font-size: 15px; line-height: 1.2; }
.m-inv { font-size: 12px; color: var(--muted); font-weight: 600; line-height: 1.25; }
.mini.locked { background: repeating-linear-gradient(45deg, #f7fafc 0 10px, #edf2f7 10px 20px); }
.mini.locked .m-name { color: var(--muted); }
.teacher { margin-top: 22px; text-align: center; color: var(--muted); font-size: 14px; }
.link { border: 0; background: none; color: var(--blue); text-decoration: underline; font-weight: 600; padding: 0; }

/* ---------- big card ---------- */

.card.big {
  width: 280px;
  max-width: 100%;
  border-radius: 20px;
  background: #fff;
  border: 6px solid var(--c);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .14);
  overflow: hidden;
  animation: flip .35s ease-out;
}
@keyframes flip { from { transform: rotateY(80deg); } to { transform: none; } }
.c-head { padding: 8px 12px 6px; background: var(--c); color: #fff; }
.c-name { display: block; font-weight: 800; font-size: 18px; line-height: 1.2; }
.c-meta { display: block; font-size: 12px; font-weight: 600; opacity: .9; }
.c-art {
  position: relative;
  display: grid;
  place-items: center;
  height: 120px;
  background: radial-gradient(circle at 50% 60%, color-mix(in srgb, var(--c) 18%, #fff), #fff 70%);
}
.c-emoji { font-size: 72px; line-height: 1; }
.c-init {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--c);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
}
.c-inv { padding: 6px 12px; font-weight: 800; font-size: 15px; text-align: center; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #fafcff; }
.c-year { font-weight: 600; color: var(--muted); }
.c-stats { padding: 6px 8px 8px; display: flex; flex-direction: column; gap: 4px; }
.stat {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: #f4f7fb;
  font-size: 14px;
  text-align: left;
}
.stat .si { font-size: 18px; }
.stat .sl { flex: 1; font-weight: 600; }
.stat .sv { font-weight: 800; font-size: 16px; }
.stat sup { color: var(--muted); }
.choosing .stat { border-color: var(--c); background: #fff; animation: glow 1.4s ease-in-out infinite; }
.choosing .stat:active { transform: scale(.97); }
@keyframes glow { 50% { background: color-mix(in srgb, var(--c) 12%, #fff); } }
.stat.chosen { border-color: var(--blue); }
.stat.win { border-color: var(--good); background: #e6ffed; }
.stat.lose { border-color: var(--bad); background: #fff0f0; }
.stat.draw { border-color: #d69e2e; background: #fffbea; }

.card.face-down {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 430px;
  border: 6px solid #2c5282;
  background: repeating-linear-gradient(45deg, #2b6cb0 0 14px, #2c5282 14px 28px);
  color: #fff;
}
.back-logo { font-size: 64px; }
.back-text { font-weight: 800; font-size: 20px; margin-top: 6px; }

/* ---------- battle ---------- */

.scorebar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 15px;
  flex-wrap: wrap;
}
.scorebar .round { color: var(--muted); font-weight: 700; }
.msg {
  margin: 12px auto;
  max-width: 680px;
  padding: 10px 16px;
  border-radius: 14px;
  background: #fffbea;
  border: 1px solid #f6e05e;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
}
.arena { display: flex; justify-content: center; align-items: flex-start; gap: 18px; flex-wrap: wrap; }
.slot { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.who { font-weight: 800; color: var(--muted); }
.vs { align-self: center; font-size: 28px; font-weight: 900; color: #a0aec0; }
.actions { display: flex; gap: 10px; justify-content: center; margin: 16px 0 6px; flex-wrap: wrap; }
.primary, .secondary {
  height: 52px;
  padding: 0 22px;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 800;
}
.primary { border: 0; background: var(--blue); color: #fff; box-shadow: 0 3px 0 var(--blue-dark); }
.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--blue-dark); }
.secondary { border: 2px solid var(--line); background: #fff; }
.note { text-align: center; color: var(--muted); font-size: 13px; }

.end { text-align: center; padding: 20px 0; }
.end .big { font-size: 64px; }
.end h1 { margin: 6px 0; }
.end p { font-size: 17px; }

/* ---------- quiz ---------- */

.quiz { max-width: 720px; }
.qhead { display: flex; justify-content: space-between; font-weight: 800; color: var(--muted); }
.qbar { height: 10px; border-radius: 5px; background: #dbe5f1; margin: 8px 0 16px; overflow: hidden; }
.qbar div { height: 100%; background: var(--blue); transition: width .2s; }
.prompt { font-size: 22px; line-height: 1.35; margin: 0 0 16px; font-weight: 600; }
.prompt .quote { display: block; margin-top: 8px; padding: 10px 14px; border-left: 5px solid var(--blue); background: #fff; border-radius: 8px; font-style: italic; font-size: 19px; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.option {
  min-height: 64px;
  padding: 10px 14px;
  border: 3px solid var(--line);
  border-radius: 14px;
  background: #fff;
  font-size: 17px;
  font-weight: 700;
  text-align: left;
}
.option:not(:disabled):active { transform: scale(.98); }
.option.right { border-color: var(--good); background: #e6ffed; }
.option.wrong { border-color: var(--bad); background: #fff0f0; }
.option:disabled:not(.right):not(.wrong) { opacity: .55; }
.reveal {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-top: 16px;
  padding: 14px;
  border-radius: 16px;
  background: #fff;
  border-left: 8px solid var(--c);
  animation: pop .2s ease-out;
}
.reveal p { margin: 4px 0 0; color: var(--muted); line-height: 1.4; }
.r-emoji { font-size: 44px; }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- modal ---------- */

#modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(26, 32, 44, .5);
  z-index: 50;
}
#modal[hidden] { display: none; }
#modal-card {
  width: min(100%, 760px);
  max-height: 92dvh;
  overflow-y: auto;
  padding: 20px;
  border-radius: 20px;
  background: var(--bg);
}
#modal-card h2 { margin-top: 0; }
#modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }
#modal-actions button { height: 46px; font-size: 16px; }
.detail { display: flex; gap: 18px; align-items: flex-start; }
.detail .card { flex: 0 0 auto; }
.detail-text { font-size: 16px; line-height: 1.5; }
.detail-text > p:first-child { margin-top: 0; }
.box { padding: 10px 14px; border-radius: 14px; background: #fff; margin-bottom: 10px; }
.box p { margin: 4px 0 0; }
.box.fact { border-left: 6px solid #d69e2e; }
.box.lesson { border-left: 6px solid var(--good); }
.detail .note { text-align: left; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(90%, 480px);
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(26, 32, 44, .92);
  color: #fff;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  z-index: 60;
}
#toast.show { opacity: 1; }

@media (max-width: 760px) {
  #brand span { display: none; }
  .tab { padding: 8px 10px; font-size: 14px; }
  .detail { flex-direction: column; align-items: center; }
  .options { grid-template-columns: 1fr; }
  .vs { display: none; }
}
