*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #475569;
  --border: #cbd5e1;
  --primary: #1e3a8a;
  --primary-hover: #1d4ed8;
  --primary-soft: #dbeafe;
  --notice-bg: #eff6ff;
  --trap-bg: #fffbeb;
  --trap-border: #b45309;
  --trap-ink: #78350f;
  --correct-bg: #dcfce7;
  --correct-border: #15803d;
  --correct-ink: #14532d;
  --wrong-bg: #fee2e2;
  --wrong-border: #b91c1c;
  --wrong-ink: #7f1d1d;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  overflow-wrap: break-word;
}

[hidden] {
  display: none !important;
}

.page {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 0.875rem 2.75rem;
}

.site-header {
  margin-bottom: 1rem;
}

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
  font-size: 0.95rem;
}

.back-link:hover,
.back-link:focus-visible {
  text-decoration: underline;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.pill {
  display: inline-block;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  background-color: #e2e8f0;
  color: #1e293b;
  font-size: 0.8rem;
  font-weight: 600;
}

.pill-primary {
  background-color: var(--primary-soft);
  color: var(--primary);
}

.pill-warn {
  background-color: var(--trap-bg);
  color: var(--trap-ink);
  border: 1px solid #fde68a;
}

.site-header h1 {
  margin: 0.125rem 0 0.5rem;
  font-size: 1.75rem;
  line-height: 1.18;
}

.study-notice {
  margin: 0;
  padding: 0.625rem 0.875rem;
  background-color: var(--notice-bg);
  border-left: 4px solid var(--primary);
  border-radius: 6px;
  font-size: 0.9rem;
  color: #1e293b;
}

.card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
}

h2 {
  margin: 0 0 0.5rem;
  font-size: 1.28rem;
  line-height: 1.25;
}

h3 {
  margin: 0 0 0.5rem;
  font-size: 1.04rem;
  line-height: 1.3;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.intro-copy {
  margin: 0 0 1rem;
  color: var(--muted);
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.mode-tab {
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background-color: var(--bg);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.mode-tab.is-active {
  background-color: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

.filter-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.picker-group {
  margin-bottom: 0.875rem;
}

.picker-label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink);
}

.label-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.control-select,
.control-input {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background-color: #ffffff;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.98rem;
}

.preview-badges {
  margin-top: 0.5rem;
  margin-bottom: 0;
}

.picker-help,
.source-note,
.muted-note {
  margin: 0.35rem 0 0.65rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.timer-config {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 0.75rem;
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.timer-input-wrap {
  flex: 1 1 140px;
}

.timer-number-input {
  max-width: 120px;
}

.timer-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip-btn {
  min-height: 40px;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background-color: #ffffff;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.chip-btn.is-selected {
  background-color: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.action-row,
.summary-actions {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  border: 1.5px solid transparent;
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn-small {
  min-height: 38px;
  padding: 0.35rem 0.75rem;
  font-size: 0.88rem;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
}

.btn-primary:disabled,
.btn-secondary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-secondary {
  background-color: #ffffff;
  color: var(--ink);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--bg);
}

.btn-link {
  display: inline-flex;
}

.link-btn {
  background: none;
  border: none;
  padding: 0.25rem;
  color: var(--primary);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

.info-banner {
  margin: 0 0 0.875rem;
  padding: 0.75rem 0.875rem;
  border-radius: 8px;
  background-color: var(--notice-bg);
  border: 1px solid #bfdbfe;
  color: #1e3a8a;
  font-size: 0.92rem;
}

.error-banner {
  margin: 0 0 1rem;
  padding: 0.75rem;
  border-radius: 8px;
  background-color: var(--wrong-bg);
  border: 1px solid var(--wrong-border);
  color: var(--wrong-ink);
  font-weight: 600;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.history-header h2 {
  margin: 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.875rem;
}

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

.stat-box {
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.5rem;
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
}

.stat-value {
  display: block;
  font-size: 1.15rem;
  line-height: 1.3;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.history-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem 0.75rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background-color: var(--bg);
  font-size: 0.9rem;
}

.history-item-meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.history-empty {
  color: var(--muted);
  font-size: 0.92rem;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
  margin-bottom: 0.875rem;
}

.hud-item {
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.35rem;
  text-align: center;
}

.hud-btn-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem;
  background-color: transparent;
  border: none;
}

.hud-label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.hud-item strong {
  font-size: 1rem;
}

.timer-value.timer-warn {
  color: var(--trap-border);
}

.timer-value.timer-urgent {
  color: var(--wrong-border);
}

.prompt-box {
  padding: 0.875rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background-color: var(--bg);
  margin-bottom: 1rem;
}

.fact-pattern-box {
  padding: 0.875rem;
  background-color: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  white-space: pre-wrap;
  line-height: 1.6;
  margin-bottom: 0.65rem;
}

.call-box {
  padding: 0.65rem 0.875rem;
  background-color: var(--notice-bg);
  border-left: 4px solid var(--primary);
  border-radius: 6px;
  font-size: 0.95rem;
}

.search-section,
.selected-section,
.menu-section {
  margin-bottom: 1rem;
}

.autocomplete-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}

.autocomplete-wrap {
  position: relative;
  flex: 1 1 auto;
}

.suggestions-list {
  list-style: none;
  margin: 0.25rem 0 0;
  padding: 0.25rem;
  border: 1.5px solid var(--primary);
  border-radius: 8px;
  background-color: #ffffff;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.1);
}

.suggestion-option {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}

.suggestion-option:hover,
.suggestion-option.is-active {
  background-color: var(--primary-soft);
}

.suggestion-title {
  font-weight: 600;
  font-size: 0.94rem;
}

.suggestion-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.chips-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background-color: var(--bg);
  min-height: 46px;
  align-items: center;
}

.issue-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  background-color: var(--primary-soft);
  color: var(--primary);
  font-size: 0.86rem;
  font-weight: 600;
}

.chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background-color: rgba(30, 58, 138, 0.14);
  color: var(--primary);
  font-weight: 700;
  cursor: pointer;
}

.issue-fieldset {
  margin: 0 0 0.875rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.issue-fieldset legend {
  padding: 0 0.4rem;
  font-weight: 700;
  color: var(--primary);
}

.issue-check-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.issue-check-row {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  min-height: 44px;
  padding: 0.5rem 0.625rem;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background-color: #ffffff;
  cursor: pointer;
}

.issue-check-row:hover {
  border-color: var(--primary);
  background-color: var(--bg);
}

.issue-check-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin: 0.1rem 0 0;
  flex: 0 0 auto;
  accent-color: var(--primary);
}

.issue-check-body {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.issue-check-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.issue-check-hint {
  font-size: 0.82rem;
  color: var(--muted);
}

.summary-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.eyebrow-tag {
  margin: 0 0 0.2rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
}

.score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 68px;
  height: 56px;
  padding: 0 0.75rem;
  border-radius: 12px;
  background-color: var(--primary-soft);
  color: var(--primary);
  font-size: 1.35rem;
  font-weight: 800;
}

.breakdown-box {
  margin-bottom: 1rem;
  padding: 0.875rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background-color: var(--bg);
}

.archetype-line {
  margin: 0 0 0.45rem;
  font-size: 0.94rem;
}

.trigger-list {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 0.92rem;
}

.result-group {
  margin-bottom: 1rem;
}

.result-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.result-card {
  padding: 0.75rem 0.875rem;
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 8px;
  background-color: #ffffff;
}

.result-group-found .result-card {
  border-left-color: var(--correct-border);
  background-color: #f0fdf4;
}

.result-group-missed .result-card {
  border-left-color: var(--wrong-border);
  background-color: #fef2f2;
}

.result-group-extras .result-card {
  border-left-color: var(--trap-border);
  background-color: var(--trap-bg);
}

.result-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem 0.6rem;
  margin-bottom: 0.35rem;
}

.result-card-title {
  font-weight: 700;
  font-size: 0.98rem;
}

.result-trigger {
  margin: 0.35rem 0;
  padding: 0.45rem 0.6rem;
  background-color: rgba(255, 255, 255, 0.8);
  border: 1px solid #fecaca;
  border-radius: 6px;
  font-size: 0.9rem;
}

.result-rule {
  margin: 0.4rem 0 0;
  padding: 0.55rem 0.65rem;
  background-color: #ffffff;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
}

.result-rule p {
  margin: 0 0 0.35rem;
}

.result-rule p:last-child {
  margin-bottom: 0;
}

.result-elements {
  margin: 0.25rem 0 0.35rem;
  padding-left: 1.2rem;
}

.result-empty {
  padding: 0.6rem 0.75rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

:focus-visible {
  outline: 3px solid #60a5fa;
  outline-offset: 2px;
}

@media (min-width: 560px) {
  .page {
    padding: 1.5rem 1.25rem 3.25rem;
  }

  .card {
    padding: 1.375rem;
  }

  .filter-grid {
    grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  }

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

  .action-row,
  .summary-actions {
    flex-direction: row;
  }

  .action-row .btn,
  .summary-actions .btn {
    flex: 1 1 auto;
  }
}
