:root {
  color-scheme: light;
  --bg: #f7f9fc;
  --panel: #ffffff;
  --ink: #152033;
  --muted: #5e697a;
  --line: #dfe5ee;
  --red: #e23b3b;
  --red-dark: #b8232f;
  --yellow: #f7c948;
  --teal: #0f9f9a;
  --green: #2f9e44;
  --blue: #2f6fed;
  --shadow: 0 14px 36px rgba(24, 35, 56, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background:
    linear-gradient(180deg, rgba(226, 59, 59, 0.08), rgba(247, 201, 72, 0) 230px),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select {
  width: 100%;
  min-height: 52px;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 4px solid rgba(47, 111, 237, 0.24);
  outline-offset: 2px;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 40px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-actions {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 132px;
  gap: 10px;
  align-items: stretch;
  width: min(520px, 48vw);
}

.ball-mark {
  position: relative;
  width: 62px;
  height: 62px;
  flex: 0 0 auto;
  border: 4px solid #161c27;
  border-radius: 50%;
  background: linear-gradient(#f04444 0 48%, #161c27 48% 56%, #fff 56% 100%);
  box-shadow: var(--shadow);
}

.ball-mark::after {
  position: absolute;
  content: "";
  inset: 18px;
  border: 4px solid #161c27;
  border-radius: 50%;
  background: #fff;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--red-dark);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(1.7rem, 3vw, 2.7rem);
  line-height: 1.08;
  letter-spacing: 0;
}

.status-text {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-left: 8px solid var(--teal);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.78);
}

.music-button {
  color: #fff;
  background: var(--teal);
}

.music-button.active {
  background: var(--green);
}

.mode-tabs,
.quiz-modes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 8px 0 18px;
}

.quiz-modes {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.tab-button,
.quiz-mode {
  color: var(--ink);
  border: 2px solid var(--line);
  background: #fff;
}

.tab-button.active,
.quiz-mode.active {
  color: #fff;
  border-color: var(--red);
  background: var(--red);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 180px;
  gap: 12px;
  align-items: end;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.toolbar.compact {
  grid-template-columns: 180px 180px;
  justify-content: start;
  margin-top: 14px;
}

.field {
  display: grid;
  gap: 7px;
}

.field label {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
}

.primary-button {
  color: #fff;
  background: var(--red);
}

.primary-button:hover {
  background: var(--red-dark);
}

.secondary-button {
  color: var(--ink);
  border: 2px solid var(--line);
  background: #fff;
}

.secondary-button:hover {
  border-color: #bbc6d6;
  background: #f2f5f9;
}

.detail-area {
  margin-top: 18px;
}

.pokemon-detail {
  display: grid;
  grid-template-columns: minmax(230px, 330px) 1fr;
  gap: 22px;
  align-items: center;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.art-panel {
  display: grid;
  place-items: center;
  min-height: 280px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(247, 201, 72, 0.42), rgba(15, 159, 154, 0.16));
}

.art-panel img {
  width: min(100%, 280px);
  height: auto;
  image-rendering: auto;
}

.detail-content h2 {
  margin: 0 0 8px;
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 1.05;
}

.detail-number {
  margin: 0 0 12px;
  color: var(--muted);
  font-weight: 800;
}

.type-row,
.tag-row,
.evolution-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.type-pill,
.tag-pill,
.evo-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 10px;
  border-radius: 8px;
  color: #fff;
  font-weight: 800;
}

.tag-pill,
.evo-pill {
  color: var(--ink);
  border: 1px solid var(--line);
  background: #f8fafc;
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.stat-box {
  min-height: 74px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.stat-box span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.stat-box strong {
  font-size: 1.15rem;
}

.description {
  margin: 14px 0 0;
  color: #2f3948;
  line-height: 1.75;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.range-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.summary-line {
  min-height: 28px;
  margin: 16px 0 8px;
  color: var(--muted);
  font-weight: 800;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.pokemon-card {
  display: grid;
  gap: 8px;
  min-height: 236px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  text-align: left;
  background: #fff;
  box-shadow: 0 8px 22px rgba(24, 35, 56, 0.08);
}

.pokemon-card:hover {
  border-color: var(--red);
  transform: translateY(-1px);
}

.pokemon-card img {
  width: 100%;
  height: 116px;
  object-fit: contain;
  border-radius: 8px;
  background: #f4f7fb;
}

.pokemon-card strong {
  font-size: 1.18rem;
  line-height: 1.25;
}

.score-strip {
  display: grid;
  grid-template-columns: 1fr 1fr 180px;
  gap: 12px;
  align-items: stretch;
  margin-bottom: 14px;
}

.quiz-settings {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.quiz-settings .field {
  min-width: 0;
}

.score-strip > div {
  min-height: 74px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.score-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.score-strip strong {
  font-size: 2rem;
}

.quiz-board {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.quiz-visual {
  display: grid;
  place-items: center;
  min-height: 320px;
  padding: 16px;
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(47, 111, 237, 0.14), rgba(47, 158, 68, 0.15)),
    #fff;
}

.quiz-visual img {
  display: none;
  width: min(56vw, 300px);
  height: 260px;
  object-fit: contain;
}

.quiz-visual img.visible {
  display: block;
}

.quiz-visual img.silhouette {
  filter: brightness(0) saturate(1);
}

.quiz-prompt {
  width: min(100%, 920px);
  max-width: calc(100% - 12px);
  margin: 0;
  padding: 0 10px;
  font-size: clamp(1.25rem, 2.8vw, 2.1rem);
  font-weight: 900;
  line-height: 1.4;
  text-align: center;
  overflow-wrap: anywhere;
  line-break: strict;
}

.quiz-prompt.long {
  font-size: clamp(1.05rem, 2.35vw, 1.7rem);
  line-height: 1.45;
}

.quiz-prompt.very-long {
  font-size: clamp(0.92rem, 2vw, 1.35rem);
  line-height: 1.52;
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.answer-button {
  min-height: 74px;
  padding: 12px;
  border: 2px solid var(--line);
  color: var(--ink);
  background: #fff;
}

.answer-button.correct {
  color: #fff;
  border-color: var(--green);
  background: var(--green);
}

.answer-button.wrong {
  color: #fff;
  border-color: var(--red);
  background: var(--red);
}

.quiz-result {
  min-height: 30px;
  margin: 0;
  color: var(--muted);
  font-weight: 900;
  text-align: center;
}

.empty-state,
.error-state {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.error-state {
  border-left: 8px solid var(--red);
}

[data-type="normal"] { background: #7b8190; }
[data-type="fire"] { background: #e4572e; }
[data-type="water"] { background: #2374ab; }
[data-type="electric"] { color: #1b2433; background: #f7c948; }
[data-type="grass"] { background: #2f9e44; }
[data-type="ice"] { color: #1b2433; background: #7bdff2; }
[data-type="fighting"] { background: #a23e48; }
[data-type="poison"] { background: #8e44ad; }
[data-type="ground"] { color: #1b2433; background: #d9a441; }
[data-type="flying"] { background: #5b7cfa; }
[data-type="psychic"] { background: #d63384; }
[data-type="bug"] { background: #759c23; }
[data-type="rock"] { background: #8d6e3f; }
[data-type="ghost"] { background: #534388; }
[data-type="dragon"] { background: #4c6ef5; }
[data-type="dark"] { background: #343a40; }
[data-type="steel"] { color: #1b2433; background: #adb5bd; }
[data-type="fairy"] { color: #1b2433; background: #f5a6c9; }

@media (max-width: 820px) {
  .app-header,
  .pokemon-detail {
    grid-template-columns: 1fr;
  }

  .app-header {
    display: grid;
  }

  .status-text {
    width: 100%;
  }

  .toolbar,
  .toolbar.compact,
  .filter-grid,
  .header-actions,
  .quiz-settings,
  .score-strip {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .mode-tabs,
  .quiz-modes,
  .answer-grid {
    grid-template-columns: 1fr 1fr;
  }

  .detail-stats {
    grid-template-columns: 1fr;
  }

  .quiz-visual {
    min-height: 260px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 18px, 1180px);
    padding-top: 12px;
  }

  .brand {
    align-items: flex-start;
  }

  .ball-mark {
    width: 52px;
    height: 52px;
  }

  .ball-mark::after {
    inset: 14px;
  }

  .mode-tabs,
  .quiz-modes,
  .answer-grid,
  .range-pair {
    grid-template-columns: 1fr;
  }
}

/* LiNest v3: タイプ色と正誤色は保ち、検索・操作面を統一 */
body.linest-themed {
  --bg: var(--linest-bg);
  --panel: var(--linest-surface);
  --ink: var(--linest-text);
  --muted: var(--linest-muted);
  --line: var(--linest-border);
  --teal: var(--linest-green);
  --green: var(--linest-green-bright);
  --shadow: var(--linest-shadow);
}

body.linest-themed .app-shell,
body.linest-themed .app-header > *,
body.linest-themed :where(.toolbar, .filter-grid, .pokemon-detail, .quiz-settings, .score-strip) > * {
  min-width: 0;
}

body.linest-themed .app-header,
body.linest-themed .pokemon-detail,
body.linest-themed .filter-grid,
body.linest-themed .quiz-board,
body.linest-themed .score-strip > div,
body.linest-themed .pokemon-card,
body.linest-themed .stat-box {
  border-color: var(--linest-border);
  background-color: rgba(255, 255, 255, 0.97);
  box-shadow: var(--linest-shadow);
}

body.linest-themed .app-header {
  border-left: 6px solid var(--linest-green-bright);
}

body.linest-themed .ball-mark {
  background: linear-gradient(#9c5230 0 48%, #4a3728 48% 56%, #fff 56% 100%);
}

body.linest-themed .tab-button,
body.linest-themed .quiz-mode {
  min-width: 0;
  border-color: var(--linest-border);
  color: var(--linest-text);
  background: #fff;
  line-height: 1.35;
  white-space: normal;
}

body.linest-themed .tab-button.active,
body.linest-themed .quiz-mode.active {
  border-color: var(--linest-green);
  color: #fff;
  background: var(--linest-green);
}

body.linest-themed .pokemon-card:hover {
  border-color: var(--linest-green);
}

body.linest-themed .quiz-visual {
  border-color: var(--linest-border);
  background:
    radial-gradient(circle at 50% 28%, rgba(47, 158, 68, 0.12), transparent 36%),
    #f9fcf6;
}

body.linest-themed :where(.primary-button, .secondary-button, .answer-button) {
  min-width: 0;
  line-height: 1.35;
  white-space: normal;
}

@media (max-width: 560px) {
  body.linest-themed :where(.tab-button, .quiz-mode, .primary-button, .secondary-button) {
    padding-inline: 8px;
    font-size: 0.94rem;
  }
}
