:root {
  --lime: #adff00;
  --bg: #0b1220;
  --surface: #121a2b;
  --card: #1a2438;
  --text: #e8eef9;
  --muted: #8b9bb8;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #3d8bfd;
  --border: rgba(255, 255, 255, 0.1);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-top: var(--safe-t);
  padding-bottom: var(--safe-b);
}

.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--lime);
  flex-shrink: 0;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
}

.brand-title {
  font-weight: 800;
  font-size: 14px;
}

.brand-sub {
  font-size: 11px;
  color: var(--muted);
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.pill {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
}

.pill strong {
  color: var(--lime);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px;
  background: #0e1626;
  border-bottom: 1px solid var(--border);
  align-items: center;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

.btn-primary {
  background: var(--lime);
  color: #111;
  border-color: transparent;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn-ghost {
  background: transparent;
}

.stage-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  background: #0a101c;
}

#chart {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.hint-bar {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 20, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
  overflow: auto;
}

.overlay[hidden] {
  display: none !important;
}

.card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px 18px;
  text-align: center;
}

.card h1 {
  margin: 8px 0;
  font-size: 24px;
}

.card p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.score-big {
  font-size: 42px;
  font-weight: 800;
  color: var(--lime);
  margin: 8px 0;
}

#score-detail {
  white-space: pre-line;
  font-size: 13px;
}

.legend {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  font-size: 12px;
  margin: 10px 0;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
}

.dot.ref {
  background: var(--lime);
}
.dot.player {
  background: var(--blue);
}
.dot.support {
  background: var(--green);
}
.dot.resist {
  background: var(--red);
}
.dot.miss {
  background: var(--red);
}

.btn-type-s {
  border-color: #22c55e;
  color: #111;
  background: #22c55e;
  font-weight: 800;
}

.btn-type-r {
  border-color: #ff4d6d;
  color: #fff;
  background: #ff4d6d;
  font-weight: 800;
}

.sel-bar {
  padding: 4px 12px 6px;
  font-size: 12px;
  color: var(--lime);
  background: #0e1626;
  border-bottom: 1px solid var(--border);
  min-height: 22px;
}

.sel-bar[hidden] {
  display: none !important;
}

.card-ready {
  text-align: left;
}

.card-ready h1 {
  text-align: center;
}

.card-ready .brand-mark {
  display: block;
}

.rules-lead {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  margin: 0 0 10px;
}

.rules-list {
  margin: 0 0 14px;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.rules-list li {
  margin-bottom: 4px;
}

.diff-block {
  margin-top: 4px;
}

.diff-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 8px;
  font-weight: 700;
}

.diff-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.diff-btn {
  width: 100%;
  text-align: left;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  background: var(--card);
}

.diff-btn .diff-need {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.diff-btn.is-active {
  border-color: var(--lime);
  box-shadow: 0 0 0 1px rgba(173, 255, 0, 0.35);
  background: rgba(173, 255, 0, 0.08);
  color: var(--text);
}

.diff-btn.is-active .diff-need {
  color: var(--lime);
}

.diff-hint {
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0 0;
  line-height: 1.4;
}

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 16, 28, 0.7);
  z-index: 5;
  font-weight: 700;
}

.loading[hidden] {
  display: none !important;
}

@media (max-width: 520px) {
  .brand-sub {
    display: none;
  }
  .btn {
    flex: 1 1 auto;
    min-width: 30%;
  }
}
