:root {
  --bg: #f6f2e8;
  --ink: #201c18;
  --muted: #6f665d;
  --panel: rgba(255, 252, 244, 0.9);
  --line: rgba(32, 28, 24, 0.14);
  --shadow: 0 24px 70px rgba(73, 58, 40, 0.16);
  --danger: #d94b3d;
  --warn: #e1912d;
  --safe: #21927d;
  --immune: #5c6070;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  width: 100vw;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  font-family: "Noto Sans SC", sans-serif;
  background:
    linear-gradient(120deg, rgba(225, 145, 45, 0.12), transparent 34%),
    linear-gradient(300deg, rgba(33, 146, 125, 0.16), transparent 42%),
    repeating-linear-gradient(90deg, rgba(32, 28, 24, 0.035) 0 1px, transparent 1px 72px),
    repeating-linear-gradient(0deg, rgba(32, 28, 24, 0.025) 0 1px, transparent 1px 72px),
    var(--bg);
}

button,
a {
  font: inherit;
}

.shell {
  width: 100vw;
  height: 100dvh;
  margin: 0 auto;
  padding: 8px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
  overflow: hidden;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.topbar {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at 88% 16%, rgba(217, 75, 61, 0.14), transparent 22%),
    linear-gradient(135deg, rgba(255, 252, 244, 0.95), rgba(245, 232, 205, 0.86));
  box-shadow: var(--shadow);
}

.kicker {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.08;
}

h1 {
  font-family: "Russo One", "Noto Sans SC", sans-serif;
  font-size: clamp(24px, 3.4vw, 40px);
  font-weight: 900;
}

h2 {
  font-size: clamp(17px, 1.8vw, 23px);
}

h3 {
  font-size: 16px;
}

.topbar-note {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.type-button:hover,
.reset-button:hover {
  transform: translateY(-1px);
}

.workspace {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(280px, 330px) minmax(0, 1fr);
  gap: 8px;
  min-height: 0;
  overflow: hidden;
}

.result-panel {
  width: 100%;
  min-width: 0;
  border-radius: 8px;
  padding: 12px;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 7px;
}

.section-heading {
  margin-bottom: 0;
}

.chart-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.selected-types {
  min-height: 48px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  overflow: hidden;
}

.badge,
.type-button {
  --type-color: #777;
  border: 1px solid color-mix(in srgb, var(--type-color) 55%, #201c18);
  background: color-mix(in srgb, var(--type-color) 18%, #fffaf0);
  color: var(--ink);
}

.badge {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 0 14px;
  font-weight: 900;
}

.badge::before,
.type-button::before,
.card-title::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--type-color);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.55);
  flex: 0 0 auto;
}

.type-picker {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.type-button {
  min-width: 0;
  min-height: 35px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.type-button.active {
  box-shadow: inset 0 0 0 2px var(--type-color);
}

.reset-button {
  width: 100%;
  min-height: 38px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #fffaf0;
  background: #201c18;
  cursor: pointer;
  font-weight: 900;
}

.summary-grid {
  display: grid;
  grid-template-rows: 0.9fr 1.1fr 1.4fr 1.25fr 0.9fr 0.9fr;
  gap: 8px;
  min-height: 0;
  overflow: hidden;
}

.summary-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: rgba(255, 250, 240, 0.72);
  min-height: 0;
  overflow: hidden;
}

.summary-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-weight: 900;
  font-size: 14px;
}

.summary-title small {
  color: var(--muted);
  font-weight: 700;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-height: none;
  overflow: hidden;
}

.chip {
  border-radius: 999px;
  padding: 2px 6px;
  background: rgba(32, 28, 24, 0.07);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.chart-panel {
  width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.type-card-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 8px;
  min-height: 0;
  overflow: hidden;
}

.type-card {
  --type-color: #777;
  min-width: 0;
  border: 1px solid color-mix(in srgb, var(--type-color) 42%, rgba(32, 28, 24, 0.12));
  border-radius: 8px;
  padding: 10px;
  background:
    linear-gradient(140deg, color-mix(in srgb, var(--type-color) 15%, #fffaf0), rgba(255, 252, 244, 0.9)),
    var(--panel);
  box-shadow: 0 16px 40px rgba(73, 58, 40, 0.1);
  cursor: pointer;
  min-height: 0;
  overflow: hidden;
}

.type-card:hover {
  outline: 2px solid color-mix(in srgb, var(--type-color) 60%, #fffaf0);
}

.card-title {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 5px;
}

.relation-group {
  margin-top: 4px;
}

.relation-label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.relation-label strong {
  color: var(--ink);
}

.empty {
  color: var(--muted);
  font-size: 12px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(300px, 46%) minmax(0, 1fr);
  }

  .result-panel {
    grid-template-columns: 180px minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    align-items: start;
  }

  .result-panel .section-heading,
  .selected-types {
    grid-column: 1;
  }

  .reset-button {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: center;
  }

  .summary-grid {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
  }

  .type-card-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .shell {
    padding: 8px;
    gap: 8px;
  }

  .topbar {
    min-height: 62px;
    padding: 9px 11px;
  }

  .topbar-note {
    display: none;
  }

  .workspace {
    grid-template-rows: minmax(360px, 58%) minmax(0, 1fr);
    gap: 8px;
  }

  .result-panel {
    padding: 10px;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto minmax(0, 1fr);
    gap: 7px;
  }

  .result-panel .section-heading,
  .selected-types,
  .reset-button,
  .summary-grid {
    grid-column: 1;
    grid-row: auto;
  }

  .selected-types {
    min-height: 30px;
  }

  .badge {
    min-height: 29px;
    padding: 0 10px;
  }

  .reset-button {
    min-height: 30px;
    font-size: 12px;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
  }

  .summary-card {
    padding: 6px;
  }

  .summary-title {
    font-size: 11px;
    margin-bottom: 3px;
  }

  .summary-title small {
    display: none;
  }

  .chip-row {
    gap: 3px;
  }

  .chip {
    padding: 2px 5px;
    font-size: 10px;
  }

  .chart-heading {
    display: none;
  }

  .chart-panel {
    grid-template-rows: minmax(0, 1fr);
  }

  .type-card-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }

  .type-card {
    padding: 6px 3px;
    display: grid;
    place-items: center;
  }

  .card-title {
    margin: 0;
    flex-direction: column;
    gap: 4px;
    font-size: 10px;
    text-align: center;
  }

  .badge::before,
  .type-button::before,
  .card-title::before {
    width: 10px;
    height: 10px;
  }

  .relation-group {
    display: none;
  }
}
