:root {
  color-scheme: dark;
  --bg: #101318;
  --panel: #181d24;
  --panel-alt: #202733;
  --panel-soft: #141922;
  --ink: #f1f4f0;
  --text: #d7ddd4;
  --muted: #9ca59a;
  --faint: #70796f;
  --line: #2b3440;
  --line-strong: #3a4654;
  --accent: #d99b35;
  --accent-active: #f0b54d;
  --accent-soft: #2a2316;
  --error: #e06f62;
  --radius: 10px;
  --radius-sm: 7px;
  --sans:
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Arial,
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  scroll-padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

body {
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--sans);
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-width: 0;
  border: 0;
  cursor: pointer;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease,
    transform 120ms ease;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.shell {
  width: 100%;
  max-width: 680px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 14px 12px calc(96px + env(safe-area-inset-bottom));
}

.top-meta {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.build-version {
  color: var(--faint);
  font-size: 0.68rem;
  font-weight: 650;
  white-space: nowrap;
}

.repo-link,
.meta-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  color: var(--muted);
  background: var(--panel);
  font-size: 0.76rem;
  font-weight: 720;
  text-decoration: none;
}

.repo-link:hover,
.meta-button:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.meta-button {
  line-height: 1;
}

.intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
  border-bottom: 1px solid var(--line);
  padding: 4px 2px 12px;
}

.kicker {
  order: 2;
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0;
  text-transform: none;
}

h1 {
  order: 1;
  margin: 0;
  color: var(--ink);
  font-size: clamp(1.55rem, 8vw, 2.25rem);
  font-weight: 820;
  letter-spacing: 0;
  line-height: 1.05;
}

.lede {
  order: 3;
  max-width: 32rem;
  margin: 4px 0 0;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.45;
}

.lookup-panel {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.rating-source {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 760;
}

.source-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 2px;
  background: var(--panel-soft);
}

.source-button {
  height: 30px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-size: 0.78rem;
  font-weight: 780;
}

.source-button.is-active {
  color: #141006;
  background: var(--accent);
}

.search-form {
  padding: 10px;
}

.search-form label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 760;
}

.search-form label {
  display: block;
  margin: 0 0 7px;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

input,
textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: var(--panel-soft);
  outline: none;
}

textarea {
  height: 98px;
  min-height: 98px;
  max-height: 98px;
  resize: none;
  padding: 10px 11px;
  font-size: 0.95rem;
  line-height: 1.45;
}

input::placeholder,
textarea::placeholder {
  color: var(--faint);
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: none;
}

.search-form button {
  width: 100%;
  min-height: 40px;
  border-radius: var(--radius-sm);
  padding: 0 16px;
  color: #141006;
  background: var(--accent);
  font-size: 0.9rem;
  font-weight: 780;
}

.search-form button:hover,
.search-form button:active {
  background: var(--accent-active);
}

.ghost-button,
.filter-button,
.refresh-button {
  width: auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: var(--panel);
  font-size: 0.76rem;
  font-weight: 720;
}

.ghost-button:hover,
.filter-button:hover,
.refresh-button:hover {
  border-color: var(--line-strong);
  background: var(--panel-alt);
}

.status {
  min-height: 28px;
  padding: 8px 2px 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 620;
  line-height: 1.35;
}

.status.error {
  color: var(--error);
}

.progress {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 6px 2px 2px;
}

.progress[hidden] {
  display: none;
}

.progress-track {
  height: 6px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

.progress-label {
  color: var(--faint);
  font-size: 0.68rem;
  font-weight: 720;
  white-space: nowrap;
}

.rules-dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: min(760px, calc(100dvh - 28px));
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0;
  color: var(--text);
  background: var(--panel);
}

.rules-dialog::backdrop {
  background: rgb(6 8 11 / 0.72);
}

.rules-panel {
  margin: 0;
  padding: 12px;
  overflow: auto;
}

.rules-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.rules-kicker {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 0.66rem;
  font-weight: 820;
}

.rules-head h2 {
  margin: 0;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 820;
  line-height: 1.2;
}

.dialog-close {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 1rem;
  line-height: 1;
}

.rules-summary,
.rules-note {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px;
  background: var(--panel-soft);
}

.rules-summary strong {
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 840;
  white-space: nowrap;
}

.rules-summary span,
.rules-note span {
  color: var(--text);
  font-size: 0.76rem;
  font-weight: 620;
  line-height: 1.45;
}

.rules-grid {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.rules-board {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px;
  background: var(--panel-soft);
}

.rules-board h3 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 840;
  line-height: 1.2;
}

.tier-list {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tier-row {
  --tier: #cfd3ca;
  display: grid;
  grid-template-columns: 18px 44px minmax(0, 1fr);
  gap: 7px;
  align-items: center;
  min-height: 30px;
  border: 1px solid color-mix(in srgb, var(--tier) 36%, var(--line));
  border-radius: 7px;
  padding: 5px 7px;
  background: rgb(255 255 255 / 0.018);
}

.tier-row[data-grade="white"] {
  --tier: #cfd3ca;
}

.tier-row[data-grade="green"] {
  --tier: #36c36c;
}

.tier-row[data-grade="blue"] {
  --tier: #4a91ff;
}

.tier-row[data-grade="purple"] {
  --tier: #a46bff;
}

.tier-row[data-grade="gold"] {
  --tier: #f0b84a;
  box-shadow: inset 0 0 10px rgb(240 184 74 / 0.08);
}

.tier-swatch {
  width: 14px;
  height: 14px;
  border: 1px solid var(--tier);
  border-radius: 4px;
  background: color-mix(in srgb, var(--tier) 72%, #101318);
  box-shadow: 0 0 9px color-mix(in srgb, var(--tier) 26%, transparent);
}

.tier-row strong {
  color: var(--tier);
  font-size: 0.74rem;
  font-weight: 860;
  white-space: nowrap;
}

.tier-row span:last-child {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-mark {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 900;
}

@supports not (color: color-mix(in srgb, white, black)) {
  .tier-row {
    border-color: var(--tier);
  }

  .tier-swatch {
    background: var(--tier);
  }
}

.view-tabs {
  position: sticky;
  top: 0;
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  margin: 8px 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2px;
  background: var(--panel-soft);
}

.tab-button {
  height: 34px;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-size: 0.84rem;
  font-weight: 760;
}

.tab-button.is-active {
  color: var(--ink);
  background: var(--panel);
}

.results {
  margin-top: 8px;
}

.grade-filter {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.grade-filter::-webkit-scrollbar {
  display: none;
}

.filter-button {
  height: 30px;
  padding: 0 11px;
  white-space: nowrap;
}

.filter-button.is-active {
  border-color: var(--accent);
  color: #141006;
  background: var(--accent);
}

.result-list {
  display: grid;
  gap: 8px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.empty-state {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  color: var(--muted);
  background: var(--panel);
  font-size: 0.88rem;
  font-weight: 650;
}

.game-result {
  --grade: #cfd3ca;
  --grade-bg: #242a31;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--grade);
  border-radius: var(--radius);
  padding: 8px 9px 7px;
  background: var(--panel);
  animation: result-in 220ms ease both;
  transition:
    border-color 140ms ease,
    box-shadow 140ms ease,
    transform 140ms ease;
}

.game-result[data-grade="white"] {
  --grade: #cfd3ca;
  --grade-bg: #2c3136;
}

.game-result[data-grade="green"] {
  --grade: #36c36c;
  --grade-bg: #182c22;
}

.game-result[data-grade="blue"] {
  --grade: #4a91ff;
  --grade-bg: #17263c;
}

.game-result[data-grade="purple"] {
  --grade: #a46bff;
  --grade-bg: #281f3a;
}

.game-result[data-grade="gold"] {
  --grade: #f0b84a;
  --grade-bg: #332714;
  box-shadow:
    0 0 0 1px #6d531d,
    0 0 10px rgb(240 184 74 / 0.2),
    inset 0 0 8px rgb(240 184 74 / 0.1);
}

.game-result[data-grade="gold"]:hover {
  box-shadow:
    0 0 0 1px #f0b84a,
    0 0 18px rgb(240 184 74 / 0.3),
    inset 0 0 10px rgb(240 184 74 / 0.14);
}

.game-result:hover {
  transform: translateY(-1px);
}

.game-result.is-refreshing-card {
  pointer-events: none;
}

.game-result.is-refreshing-card::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  background:
    linear-gradient(90deg, transparent, rgb(255 255 255 / 0.05), transparent),
    rgb(16 19 24 / 0.46);
  background-size: 220% 100%, auto;
  animation: card-refresh-sweep 900ms linear infinite;
}

.game-result.is-refreshing-card::after {
  content: "鉴定中";
  position: absolute;
  right: 9px;
  bottom: 7px;
  z-index: 3;
  border: 1px solid var(--grade);
  border-radius: 999px;
  padding: 3px 7px;
  color: var(--grade);
  background: var(--panel);
  font-size: 0.66rem;
  font-weight: 820;
}

.game-result.is-unidentified {
  --grade: #7d8580;
  --grade-bg: #22272c;
  border-style: dashed;
}

.game-topline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: start;
  margin-bottom: 6px;
}

.game-title {
  min-width: 0;
}

.game-title p {
  margin: 0;
  color: var(--faint);
  font-size: 0.64rem;
  font-weight: 500;
  line-height: 1.25;
}

.game-title strong {
  display: block;
  margin-top: 2px;
  overflow-wrap: anywhere;
  color: var(--grade);
  font-size: 0.98rem;
  font-weight: 830;
  letter-spacing: 0;
  line-height: 1.18;
}

.card-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.cache-note {
  display: none;
}

.refresh-button {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 8px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
}

.refresh-button.is-refreshing {
  color: var(--accent);
}

.refresh-button.is-refreshing::before {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: refresh-spin 680ms linear infinite;
}

.refresh-button.is-refreshing {
  font-size: 0;
}

.match-warning {
  border: 1px solid rgb(224 111 98 / 0.45);
  border-radius: 7px;
  padding: 4px 5px;
  color: var(--error);
  background: rgb(224 111 98 / 0.08);
  font-size: 0.64rem;
  font-weight: 820;
  white-space: nowrap;
}

.grade-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 0;
  border-radius: 8px;
  padding: 5px 6px;
  color: var(--grade);
  background: var(--grade-bg);
  font-size: 0.68rem;
  font-weight: 820;
  white-space: nowrap;
}

.grade-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--grade);
}

.game-result[data-grade="gold"] .grade-badge::before {
  box-shadow: 0 0 8px rgb(240 184 74 / 0.5);
}

.attribute-list {
  display: grid;
  gap: 0;
  border-top: 1px solid var(--line);
}

.attribute-row {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  min-height: 28px;
  border-top: 1px solid var(--line);
}

.attribute-row:first-child {
  border-top: 0;
}

.attribute-row[data-grade="white"] {
  --source-grade: #cfd3ca;
}

.attribute-row[data-grade="green"] {
  --source-grade: #36c36c;
}

.attribute-row[data-grade="blue"] {
  --source-grade: #4a91ff;
}

.attribute-row[data-grade="purple"] {
  --source-grade: #a46bff;
}

.attribute-row[data-grade="gold"] {
  --source-grade: #f0b84a;
}

.attribute-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 780;
  white-space: nowrap;
}

.attribute-body {
  display: grid;
  grid-template-columns: minmax(74px, 30%) minmax(0, 1fr) auto auto;
  gap: 7px;
  align-items: baseline;
  min-width: 0;
  white-space: nowrap;
}

.attribute-name {
  min-width: 0;
  overflow: hidden;
  color: var(--faint);
  font-size: 0.66rem;
  font-weight: 620;
  text-overflow: ellipsis;
}

.attribute-value {
  grid-column: 4;
  color: var(--source-grade, var(--grade));
  font-size: 0.94rem;
  font-weight: 860;
  line-height: 1;
  letter-spacing: 0;
  text-align: right;
  white-space: nowrap;
}

.attribute-link {
  grid-column: 3;
  grid-row: 1;
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0;
  color: var(--muted);
  background: var(--panel-soft);
  font-weight: 760;
  letter-spacing: 0;
  text-decoration: none;
  white-space: nowrap;
}

.attribute-link::after {
  content: "↗";
  color: var(--source-grade, var(--grade));
  font-size: 0.72rem;
  line-height: 1;
}

.attribute-link:hover,
.attribute-link:focus-visible {
  border-color: var(--source-grade, var(--grade));
  color: var(--source-grade, var(--grade));
}

.attribute-detail {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--faint);
  font-size: 0.64rem;
  font-weight: 620;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.is-loading .lookup-panel {
  position: relative;
  overflow: hidden;
}

.is-loading .lookup-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid var(--accent);
  pointer-events: none;
}

@keyframes result-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes refresh-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes card-refresh-sweep {
  from {
    background-position: 180% 0, 0 0;
  }

  to {
    background-position: -180% 0, 0 0;
  }
}

@media (min-width: 520px) {
  .shell {
    padding: 18px 16px calc(86px + env(safe-area-inset-bottom));
  }

  .input-row {
    grid-template-columns: minmax(0, 1fr) 92px;
    align-items: stretch;
  }

  .search-form button {
    width: 92px;
  }

  .result-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 760px) {
  .shell {
    max-width: 980px;
  }

  .app-grid {
    display: grid;
    grid-template-columns: 360px minmax(0, 1fr);
    gap: 14px;
    align-items: start;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
