:root {
  font-family: Inter, "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #171717;
  background: #fff;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-width: 0;
  background: #fff;
}

body { overflow-x: hidden; }

button,
input { font: inherit; }

button { cursor: pointer; }

.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;
}

.page-shell {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 20px 32px;
}

.search-header {
  display: grid;
  grid-template-columns: auto minmax(0, 760px);
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 18px;
}

.brand {
  color: #111;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: .04em;
  text-decoration: none;
}

.result-search-form {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 54px;
  padding: 5px;
  border: 1px solid #d2d2d7;
  border-radius: 15px;
  background: #fff;
  box-shadow: 0 7px 22px rgba(0, 0, 0, .06);
}

.result-search-form:focus-within {
  border-color: #007aff;
  box-shadow: 0 7px 24px rgba(0, 122, 255, .12);
}

.result-search-form input {
  appearance: none;
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  height: 42px;
  margin: 0;
  padding: 0 13px;
  border: 0;
  outline: 0;
  background: transparent;
  color: #171717;
  font-size: 16px;
  line-height: 42px;
}

.result-search-form button {
  display: inline-flex;
  flex: 0 0 88px;
  align-items: center;
  justify-content: center;
  height: 42px;
  margin: 0;
  padding: 0 16px;
  border: 0;
  border-radius: 11px;
  background: #111;
  color: #fff;
  font-weight: 700;
  line-height: 1;
}

.result-card {
  overflow: visible;
  border: 1px solid #e1e1e5;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 14px 42px rgba(0, 0, 0, .055);
}

.query-row {
  padding: 22px 24px 16px;
}

.query-label {
  margin: 0 0 5px;
  color: #777;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
}

.query-title {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: clamp(22px, 3.6vw, 32px);
  line-height: 1.3;
}

.primary-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  padding: 0 18px;
  border-bottom: 1px solid #e5e5e7;
}

.primary-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  padding: 10px 14px;
  border: 0;
  background: transparent;
  color: #777;
  font-weight: 700;
}

.primary-tab[aria-selected="true"] { color: #111; }

.primary-tab[aria-selected="true"]::after {
  position: absolute;
  right: 12px;
  bottom: -1px;
  left: 12px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: #111;
  content: "";
}

.primary-panel {
  padding: 18px 24px 26px;
}

.primary-panel[hidden],
.search-result-panel[hidden] { display: none; }

.secondary-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding-bottom: 16px;
}

#aiPanel .secondary-tabs {
  grid-template-columns: minmax(140px, 220px);
}

.secondary-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid #d8d8dd;
  border-radius: 12px;
  background: #fff;
  color: #555;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
}

.secondary-tab[aria-selected="true"] {
  border-color: #111;
  background: #111;
  color: #fff;
}

.ai-answer-card {
  min-height: 240px;
  padding: 20px;
  border: 1px solid #e2e2e6;
  border-radius: 16px;
  background: #fafafa;
}

.ai-status {
  display: flex;
  align-items: center;
  min-height: 24px;
  margin-bottom: 10px;
  color: #777;
  font-size: 14px;
}

.ai-status:empty { display: none; }

.ai-status.is-loading::before {
  width: 14px;
  height: 14px;
  margin-right: 9px;
  border: 2px solid #d0d0d5;
  border-top-color: #007aff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  content: "";
}

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

.ai-answer {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 16px;
  line-height: 1.8;
}

.ai-answer:empty::before {
  color: #888;
  content: "AI回答タブを開くと回答を生成します。";
}

.other-ai {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 16px;
  padding: 17px 18px;
  border: 1px solid #e2e2e6;
  border-radius: 16px;
}

.other-ai-title {
  margin: 0 0 4px;
  font-weight: 800;
}

.other-ai-copy {
  margin: 0;
  color: #777;
  font-size: 13px;
}

.other-ai-links {
  display: grid;
  grid-template-columns: repeat(2, minmax(92px, 1fr));
  gap: 8px;
}

.other-ai-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 13px;
  border: 1px solid #d8d8dd;
  border-radius: 11px;
  color: #222;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.other-ai-link:hover { border-color: #888; }

@media (max-width: 720px) {
  .page-shell {
    max-width: none;
    padding: 8px 8px 20px;
  }

  .search-header {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 10px;
  }

  .brand {
    padding: 0 4px;
    font-size: 17px;
  }

  .result-search-form {
    min-height: 50px;
    border-radius: 13px;
  }

  .result-search-form input {
    height: 40px;
    padding: 0 10px;
    line-height: 40px;
  }

  .result-search-form button {
    flex-basis: 76px;
    height: 40px;
    padding: 0 12px;
  }

  .result-card {
    border-radius: 14px;
    box-shadow: none;
  }

  .query-row {
    padding: 17px 14px 12px;
  }

  .query-title {
    font-size: 22px;
  }

  .primary-tabs {
    padding: 0 6px;
  }

  .primary-tab {
    min-height: 46px;
    padding: 8px 10px;
    font-size: 14px;
  }

  .primary-panel {
    padding: 14px 10px 18px;
  }

  .secondary-tabs {
    gap: 6px;
    padding-bottom: 12px;
  }

  .secondary-tab {
    min-height: 40px;
    padding: 7px 6px;
    border-radius: 10px;
    font-size: 12px;
  }

  #aiPanel .secondary-tabs {
    grid-template-columns: 1fr;
  }

  .ai-answer-card {
    min-height: 200px;
    padding: 15px;
    border-radius: 13px;
  }

  .other-ai {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
    padding: 15px;
    border-radius: 13px;
  }

  .other-ai-links {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
