*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f14;
  --surface: #1a1a24;
  --surface-2: #252532;
  --border: #3a3a4f;
  --text: #e8e8f0;
  --text-muted: #8888a0;
  --team-a: #4a9eff;
  --team-b: #ff6b6b;
  --accent: #ffd93d;
  --cell-light: #2a2a3a;
  --cell-dark: #222230;
  --group-sp: #ffd93d;
  --group-nf: #54b08b;
  --group-nt: #a29bfe;
  --group-sj: #4a9eff;
  --radius: 10px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

body {
  font-family: 'Noto Sans SC', system-ui, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(74, 158, 255, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(255, 107, 107, 0.08) 0%, transparent 50%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  justify-content: center;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.control-group label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.control-group-switch {
  align-items: center;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 26px;
  cursor: pointer;
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.2s, border-color 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 18px;
  height: 18px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
  background: rgba(74, 158, 255, 0.25);
  border-color: var(--team-a);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(18px);
  background: var(--team-a);
}

select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.875rem;
  cursor: pointer;
}

.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:hover {
  background: var(--border);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--team-a);
  border-color: var(--team-a);
  color: #fff;
}

.btn-primary:hover {
  background: #3a8eef;
}

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1a24;
}

.btn-accent:hover {
  background: #f0cc2a;
}

.match-info {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.team-card {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.team-a { border-color: rgba(74, 158, 255, 0.4); }
.team-b { border-color: rgba(255, 107, 107, 0.4); }

.team-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.team-mbti {
  font-size: 1.25rem;
  font-weight: 700;
}

.team-roster {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  max-width: 100%;
  align-items: center;
}

.mbti-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 5px 2px 2px;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 700;
  color: #fff;
  background: var(--surface-2);
}

.mbti-chip img {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  object-fit: contain;
  flex-shrink: 0;
  background: var(--surface);
}

.mbti-chip.group-sp { border: 2px solid var(--group-sp); }
.mbti-chip.group-nf { border: 2px solid var(--group-nf); }
.mbti-chip.group-nt { border: 2px solid var(--group-nt); }
.mbti-chip.group-sj { border: 2px solid var(--group-sj); }

.mbti-chip.team-a-chip { box-shadow: inset 0 0 0 1px rgba(74, 158, 255, 0.8); }
.mbti-chip.team-b-chip { box-shadow: inset 0 0 0 1px rgba(255, 107, 107, 0.8); }

.mbti-chip.fallen {
  border-color: #4a4a58 !important;
  background: #1e1e28;
  box-shadow: none !important;
  opacity: 0.55;
}

.mbti-chip.fallen img {
  filter: grayscale(1);
  opacity: 0.45;
}

.mbti-chip.fallen span {
  color: #666;
  text-decoration: line-through;
}

.team-skill {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.vs {
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.main-area {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: nowrap;
}

.board-wrap {
  flex-shrink: 0;
  position: sticky;
  top: 16px;
  align-self: flex-start;
  z-index: 1;
}

.board {
  display: grid;
  width: min(480px, 92vw);
  aspect-ratio: 1;
  border: 3px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: var(--shadow);
  flex-shrink: 0;
  position: relative;
}

.board::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: linear-gradient(
    to bottom,
    rgba(255, 107, 107, 0.07) 0%,
    rgba(255, 107, 107, 0.07) var(--zone-top-end, 37.5%),
    transparent var(--zone-top-end, 37.5%),
    transparent var(--zone-bottom-start, 62.5%),
    rgba(74, 158, 255, 0.07) var(--zone-bottom-start, 62.5%),
    rgba(74, 158, 255, 0.07) 100%
  );
}

.cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: default;
  transition: background 0.12s;
  z-index: 1;
}

.cell-light { background: var(--cell-light); }
.cell-dark { background: var(--cell-dark); }

.cell.valid-move,
.cell.valid-capture {
  cursor: pointer;
}

.cell.valid-move::after,
.cell.valid-capture::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}

.cell.valid-move::after {
  width: 28%;
  height: 28%;
  background: rgba(255, 217, 61, 0.9);
  box-shadow: 0 0 8px rgba(255, 217, 61, 0.45);
}

.cell.valid-capture::after {
  width: 72%;
  height: 72%;
  box-sizing: border-box;
  background: rgba(255, 217, 61, 0.28);
  border: 3px solid rgba(255, 107, 107, 0.85);
  box-shadow: inset 0 0 0 1px rgba(255, 217, 61, 0.35);
}

.cell.selected {
  background: rgba(255, 217, 61, 0.25) !important;
}

.cell.last-move {
  background: rgba(74, 158, 255, 0.2) !important;
}

.cell.anim-hidden .piece {
  visibility: hidden;
}

.board-anim-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  overflow: visible;
}

.anim-piece {
  position: absolute;
  margin: 0;
  box-sizing: border-box;
  z-index: 2;
}

.anim-piece.anim-mover {
  transition: left 0.38s ease-out, top 0.38s ease-out;
  z-index: 3;
}

.piece.piece-anim.anim-piece {
  flex: none;
}

.anim-piece.anim-victim {
  animation: capturePop 0.48s ease-in forwards;
  transform-origin: center center;
  z-index: 1;
}

.capture-flash {
  position: absolute;
  transform: translate(-50%, -50%) scale(0.4);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 107, 107, 0.75) 0%, rgba(255, 107, 107, 0) 70%);
  opacity: 0;
  z-index: 0;
  pointer-events: none;
}

.capture-flash.capture-flash-active {
  animation: captureFlash 0.48s ease-out forwards;
}

@keyframes capturePop {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(0.25);
  }
}

@keyframes captureFlash {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.55);
  }
  35% {
    opacity: 0.95;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.15);
  }
}

.piece {
  width: 90%;
  height: 90%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
  user-select: none;
  box-sizing: border-box;
  padding: 2px;
  background: var(--surface-2);
  overflow: hidden;
}

.piece img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  border-radius: 50%;
}

.piece.piece-anim {
  overflow: visible;
}

.piece.group-sp {
  border: 3px solid var(--group-sp);
  box-shadow: 0 2px 8px rgba(255, 217, 61, 0.45);
}

.piece.group-nf {
  border: 3px solid var(--group-nf);
  box-shadow: 0 2px 8px rgba(84, 176, 139, 0.45);
}

.piece.group-nt {
  border: 3px solid var(--group-nt);
  box-shadow: 0 2px 8px rgba(162, 155, 254, 0.45);
}

.piece.group-sj {
  border: 3px solid var(--group-sj);
  box-shadow: 0 2px 8px rgba(74, 158, 255, 0.45);
}

.team-badge {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  font-size: 0.48rem;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.6);
  z-index: 2;
}

.badge-a { background: var(--team-a); }
.badge-b { background: var(--team-b); }

.piece.core::before {
  content: '★';
  position: absolute;
  top: -5px;
  right: -3px;
  font-size: 0.5rem;
  color: var(--accent);
  text-shadow: 0 0 4px rgba(255, 217, 61, 0.8);
}

.skill-legend h3:not(:first-child) {
  margin-top: 14px;
}

.legend-note {
  margin-top: 10px;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.sidebar {
  flex: 1;
  min-width: 220px;
  max-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.panel-summary::-webkit-details-marker {
  display: none;
}

.panel-summary::after {
  content: '▸';
  font-size: 0.75rem;
  color: var(--text-muted);
  transition: transform 0.2s;
}

.panel[open] .panel-summary::after {
  transform: rotate(90deg);
}

.panel-body {
  padding: 0 16px 16px;
}

.panel h3 {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

.turn-info {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 10px;
  padding: 8px;
  background: var(--surface-2);
  border-radius: 6px;
}

.turn-info.turn-notice {
  background: rgba(255, 107, 107, 0.15);
  border: 1px solid rgba(255, 107, 107, 0.45);
  color: #ffb4b4;
}

.move-log {
  max-height: 200px;
  overflow-y: auto;
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.move-log .log-entry {
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}

.skill-legend ul {
  list-style: none;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.skill-legend li {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.skill-tag {
  display: inline-block;
  width: 22px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.group-tag {
  display: inline-block;
  width: 28px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 700;
  color: #1a1a24;
  flex-shrink: 0;
}

.group-tag.sp { background: var(--group-sp); }
.group-tag.nf { background: var(--group-nf); color: #fff; }
.group-tag.nt { background: var(--group-nt); color: #fff; }
.group-tag.sj { background: var(--group-sj); color: #fff; }

.result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.result-overlay.hidden {
  display: none;
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  text-align: center;
  max-width: 360px;
  box-shadow: var(--shadow);
}

.result-card h2 {
  font-size: 1.5rem;
  margin-bottom: 12px;
}

.result-card .highlight {
  color: var(--accent);
  font-size: 0.9rem;
  margin: 12px 0 20px;
}

/* Report card for export */
.report-card {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 400px;
  background: linear-gradient(160deg, #1a1a28 0%, #12121c 100%);
  border-radius: 16px;
  overflow: hidden;
  color: #e8e8f0;
  font-family: 'Noto Sans SC', sans-serif;
}

.report-card.hidden {
  visibility: hidden;
}

.report-header {
  background: linear-gradient(90deg, #4a9eff, #a29bfe);
  padding: 16px;
  text-align: center;
  font-weight: 700;
  font-size: 1.1rem;
}

.report-body {
  padding: 24px;
  text-align: center;
}

.report-team {
  margin: 12px 0;
}

.report-label {
  display: block;
  font-size: 0.75rem;
  color: #8888a0;
  margin-bottom: 4px;
}

.report-mbti {
  font-size: 1.4rem;
  font-weight: 700;
}

.report-vs {
  font-size: 1rem;
  color: #8888a0;
  margin: 8px 0;
}

.report-result {
  font-size: 1.25rem;
  font-weight: 700;
  color: #ffd93d;
  margin: 20px 0 8px;
}

.report-highlight {
  font-size: 0.9rem;
  color: #aaa;
  margin-bottom: 12px;
}

.report-turns {
  font-size: 0.8rem;
  color: #666;
}

.report-qr {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.report-qr img {
  width: 88px;
  height: 88px;
  border-radius: 8px;
  background: #fff;
  padding: 4px;
}

.report-qr-hint {
  font-size: 0.75rem;
  color: #777;
}

.report-footer {
  padding: 12px 16px 14px;
  text-align: center;
  font-size: 0.68rem;
  color: #555;
  line-height: 1.6;
  border-top: 1px solid #333;
}

.report-footer p {
  margin: 0;
}

.site-footer {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.site-footer a {
  color: var(--team-a);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

.btn-tutorial-link {
  width: 100%;
  margin-top: 12px;
  font-size: 0.8rem;
  padding: 8px 12px;
}

.tutorial-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
  backdrop-filter: blur(6px);
}

.tutorial-overlay.hidden {
  display: none;
}

.tutorial-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: min(720px, 100%);
  max-height: min(90vh, 860px);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tutorial-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(90deg, rgba(74, 158, 255, 0.12), rgba(162, 155, 254, 0.12));
}

.tutorial-panel-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.tutorial-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.tutorial-close:hover {
  color: var(--text);
}

.tutorial-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.tutorial-tab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.tutorial-tab:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.tutorial-tab.active {
  background: var(--team-a);
  border-color: var(--team-a);
  color: #fff;
}

.tutorial-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.tutorial-footer {
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--surface-2);
}

.tutorial-color-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
  background: var(--surface-2);
}

.tutorial-color-card.group-sp { border-left: 4px solid var(--group-sp); }
.tutorial-color-card.group-nf { border-left: 4px solid var(--group-nf); }
.tutorial-color-card.group-nt { border-left: 4px solid var(--group-nt); }
.tutorial-color-card.group-sj { border-left: 4px solid var(--group-sj); }

.tutorial-color-header {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 10px;
}

.tutorial-color-header h3 {
  font-size: 0.95rem;
  margin-bottom: 2px;
}

.tutorial-color-header p {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.tutorial-members {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.tutorial-mbti {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  min-width: 52px;
  font-size: 0.72rem;
}

.tutorial-mbti strong {
  font-size: 0.75rem;
}

.tutorial-mbti em {
  font-style: normal;
  color: var(--accent);
  font-size: 0.68rem;
}

.tutorial-skill-blocks {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}

.tutorial-skill-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}

.tutorial-skill-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}

.tutorial-capture-brief {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.tutorial-skill-detail {
  max-width: 480px;
  margin: 0 auto;
}

.tutorial-skill-title {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.skill-tag-lg {
  width: 36px;
  height: 36px;
  line-height: 36px;
  font-size: 1rem;
}

.tutorial-colors-line {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tutorial-rules {
  margin-top: 16px;
  font-size: 0.85rem;
}

.tutorial-rules dt {
  color: var(--accent);
  font-weight: 600;
  margin-top: 10px;
}

.tutorial-rules dd {
  color: var(--text-muted);
  margin-left: 0;
  line-height: 1.5;
}

.mini-board {
  display: inline-flex;
  flex-direction: column;
  border: 2px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: #1a1a22;
}

.mini-row {
  display: flex;
}

.mini-cell {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.mini-empty { background: #252532; }

.mini-self {
  background: rgba(74, 158, 255, 0.35);
  color: #fff;
}

.mini-ally {
  background: rgba(74, 158, 255, 0.2);
  color: #8ab4ff;
}

.mini-enemy {
  background: rgba(255, 107, 107, 0.35);
  color: #fff;
}

.mini-move {
  background: rgba(255, 217, 61, 0.2);
  color: var(--accent);
}

.mini-land {
  background: rgba(84, 176, 139, 0.35);
  color: #fff;
}

.mini-legend {
  margin-top: 8px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

@media (max-width: 640px) {
  .main-area {
    flex-direction: column;
    align-items: center;
  }

  .sidebar {
    width: 100%;
    max-width: min(480px, 92vw);
  }
}
