:root {
  --bg: #101011;
  --panel: #19191d;
  --panel-strong: #202024;
  --ink: #f0ece3;
  --muted: #aaa398;
  --faint: #756f68;
  --line: #333035;
  --gold: #d0aa5a;
  --gold-soft: #ead088;
  --green: #75b37e;
  --red: #db765f;
  --blue: #79aee3;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.38);
  --font: Inter, "Noto Sans JP", "Hiragino Sans", "Yu Gothic UI", system-ui, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(180deg, #181614 0%, var(--bg) 42%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
}

body {
  padding: 28px;
}

button, input, select {
  font: inherit;
}

a {
  color: var(--gold-soft);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  max-width: 1380px;
  margin: 0 auto 18px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--gold-soft);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.15;
  letter-spacing: 0;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 9px 15px;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--panel-strong);
  cursor: pointer;
  font-weight: 800;
}

.button.primary {
  border-color: rgba(208, 170, 90, 0.72);
  background: #3a3020;
}

.button.ghost {
  background: transparent;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 480px) minmax(0, 1fr);
  gap: 18px;
  max-width: 1380px;
  margin: 0 auto;
}

.builder,
.workspace {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(25, 25, 29, 0.94);
  box-shadow: var(--shadow);
}

.builder {
  display: grid;
  gap: 18px;
  padding: 18px;
}

.workspace {
  padding: 18px;
}

.field,
.group {
  min-width: 0;
}

.field label,
.field > span,
.group-title,
legend,
.query-label {
  display: block;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

input[type="search"],
input[type="number"],
select {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111114;
  color: var(--ink);
}

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

.locked-filter code {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid rgba(208, 170, 90, 0.48);
  border-radius: 8px;
  background: #16130f;
  color: var(--gold-soft);
  font-family: var(--mono);
  font-size: 13px;
}

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

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  min-height: 48px;
  min-width: 116px;
  max-width: 205px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #141418;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.chip.compact {
  min-width: 92px;
  min-height: 40px;
}

.chip[aria-pressed="true"] {
  border-color: var(--gold);
  background: #312a1d;
  box-shadow: 0 0 0 1px rgba(208, 170, 90, 0.42) inset;
}

.chip-label {
  font-size: 13px;
  font-weight: 800;
  line-height: 1.25;
}

.chip-code {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 11px;
}

.chip[aria-pressed="true"] .chip-code {
  color: var(--gold-soft);
}

.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #121215;
}

.segmented input {
  position: absolute;
  opacity: 0;
}

.segmented span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 6px 12px;
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

.segmented input:checked + span {
  color: #17130a;
  background: var(--gold);
}

.color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.color-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 43px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #141418;
  cursor: pointer;
}

.color-chip input {
  position: absolute;
  opacity: 0;
}

.color-chip img {
  width: 25px;
  height: 25px;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.5));
}

.color-chip:has(input:checked) {
  border-color: var(--gold);
  background: #312a1d;
  box-shadow: 0 0 0 1px rgba(208, 170, 90, 0.42) inset;
}

.inline-select {
  display: grid;
  gap: 7px;
}

.inline-select span {
  color: var(--muted);
  font-size: 12px;
}

.query-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: end;
  padding: 16px;
  border: 1px solid rgba(208, 170, 90, 0.34);
  border-radius: 10px;
  background: #14120f;
}

#queryOutput {
  display: block;
  margin-top: 8px;
  min-height: 46px;
  padding: 10px 12px;
  overflow-wrap: anywhere;
  border: 1px solid #3d3420;
  border-radius: 8px;
  background: #0c0b09;
  color: var(--gold-soft);
  font-family: var(--mono);
  font-size: 13px;
}

.translation-note {
  min-height: 22px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.translation-note strong {
  color: var(--gold-soft);
  font-weight: 850;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.tag-catalog {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #151519;
}

.tag-catalog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.tag-catalog-count {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.catalog-source-link {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 800;
}

.tag-catalog-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 170px;
  gap: 10px;
  margin-bottom: 12px;
}

.tag-catalog-results {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  min-height: 36px;
}

.catalog-tag {
  min-height: 32px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111114;
  color: var(--ink);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12px;
}

.catalog-tag[data-kind="oracle"] {
  border-color: rgba(117, 179, 126, 0.38);
}

.catalog-empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.preset {
  min-height: 34px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #141418;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
}

.status {
  min-height: 26px;
  margin: 6px 0 14px;
  color: var(--muted);
}

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

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

.card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #151519;
}

.card img {
  display: block;
  width: 100%;
  aspect-ratio: 488 / 680;
  object-fit: cover;
  background: #0d0d10;
}

.card-body {
  padding: 10px 11px 12px;
}

.card-name {
  margin: 0 0 4px;
  font-weight: 850;
  line-height: 1.25;
}

.card-type {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
}

.card-text {
  margin: 0;
  color: #d9d1c4;
  font-size: 12px;
}

.app-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  max-width: 1380px;
  margin: 18px auto 0;
  color: var(--muted);
  font-size: 12px;
}

@media (hover: hover) {
  .button:hover,
  .chip:hover,
  .preset:hover,
  .color-chip:hover {
    border-color: var(--gold);
  }
}

@media (max-width: 980px) {
  body {
    padding: 18px;
  }

  .app-header,
  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    justify-content: stretch;
  }

  .header-actions .button {
    flex: 1 1 160px;
  }
}

@media (max-width: 560px) {
  body {
    padding: 12px;
  }

  h1 {
    font-size: 26px;
  }

  .builder,
  .workspace {
    padding: 13px;
  }

  .split,
  .query-card,
  .tag-catalog-controls {
    grid-template-columns: 1fr;
  }

  .chip {
    flex: 1 1 138px;
    max-width: none;
  }

  .results-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
}
