:root {
  --blue: #3788d8;
  --blue-dark: #2377c9;
  --blue-soft: #9fc6ec;
  --border: #cfcfcf;
  --border-dark: #a8a8a8;
  --text: #6f6f6f;
  --muted: #8a8a8a;
  --light-gray: #eeeeee;
  --mid-gray: #d4d4d4;
  --dark-gray: #9d9d9d;
  --white: #ffffff;
  --shadow: 0 3px 8px rgba(0, 0, 0, 0.16);
}

* {
  box-sizing: border-box;
}

#toolTitle{font-size: 48px;}

html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background: #ffffff;
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.page-shell {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 100px 24px 64px;
}

.tool-card {
  position: relative;
  width: 100%;
  max-width: 600px;
  min-height: 700px;
  border: 4px solid var(--border);
  border-radius: 5px;
  background: var(--white);
  padding: 30px 18px 18px;
}

.tool-header h1,
.success-content h1 {
  margin: 0;
  color: var(--text);
  font-size: clamp(2.6rem, 8vw, 3.95rem);
  line-height: 1.08;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.tool-header p {
  margin: 14px 5px 76px;
  font-size: 1.08rem;
  line-height: 1.3;
  font-style: italic;
}

.rule-line {
  width: 100%;
  height: 3px;
  margin-top: 26px;
  background: var(--dark-gray);
}

.field-stack {
  display: grid;
  gap: 18px;
  margin-bottom: 18px;
}

.guidance-prompt {
  position: relative;
  min-height: 38px;
  margin: -2px 0 16px;
  padding: 7px 12px 7px 15px;
  border-left: 4px solid var(--blue);
  background: #f7f9fc;
  color: var(--text);
}

.guidance-prompt.is-complete {
  border-left-color: var(--dark-gray);
}

.guidance-prompt p {
  margin: 0;
  font-size: 0.87rem;
  line-height: 1.32;
}

.text-field,
.select-field {
  width: 100%;
  min-height: 43px;
  border: 2px solid var(--border);
  border-radius: 3px;
  background-color: var(--white);
  color: #111111;
  line-height: 1.2;
}

.text-field {
  padding: 9px 12px;
  color: var(--text);
}

.text-field::placeholder {
  color: var(--muted);
  opacity: 1;
}

.select-field {
  padding: 7px 36px 7px 10px;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 19px) 50%,
    calc(100% - 11px) 50%;
  background-size: 8px 8px, 8px 8px;
  background-repeat: no-repeat;
}

.select-field:disabled {
  color: var(--muted);
  background-color: var(--white);
  opacity: 0.78;
}

.full-select {
  margin-bottom: 14px;
  font-size: 1.1rem;
}

.rule-builder {
  border: 3px solid var(--border);
  border-radius: 4px;
  padding: 19px 10px 13px;
}

.rule-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(80px, 0.62fr) minmax(0, 1.75fr);
  gap: 12px;
  align-items: end;
}

.rule-col label {
  display: block;
  margin-bottom: 4px;
  color: #111111;
  font-size: 1.08rem;
  line-height: 1.1;
}

.advanced-toggle,
.advanced-panel {
  width: 100%;
  border: 2px solid var(--border-dark);
  background: var(--mid-gray);
}

.advanced-toggle {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 29px;
  margin-top: 13px;
  border-radius: 3px;
  color: #111111;
  font-size: 0.94rem;
}

.caret {
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 7px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--muted);
}

.advanced-toggle[aria-expanded="true"] .caret {
  border-top: 0;
  border-bottom: 6px solid var(--muted);
}

.advanced-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: center;
  min-height: 58px;
  border-top: 0;
  padding: 13px 43px 16px;
  color: var(--text);
}

.advanced-panel[hidden] {
  display: none;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #111111;
  line-height: 1.2;
}

.check-label input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--dark-gray);
}

.advanced-check {
  color: var(--text);
  white-space: nowrap;
}

.formula-preview,
.meaning-preview,
.estimate-box {
  display: block;
  width: 100%;
}

.formula-preview {
  min-height: 50px;
  margin-top: 14px;
  padding: 13px 8px;
  background: var(--mid-gray);
  color: var(--muted);
  text-align: center;
  font-size: 1.08rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.meaning-preview {
  min-height: 58px;
  padding: 17px 8px 7px;
  color: var(--muted);
  text-align: center;
  font-size: 1rem;
  font-style: italic;
  line-height: 1.28;
}

.rule-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 39px;
}

.action-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.small-button,
.large-button {
  border: 0;
  border-radius: 3px;
  color: var(--white);
  background: var(--blue);
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: background-color 160ms ease, opacity 160ms ease, transform 120ms ease;
}

.small-button {
  min-width: 100px;
  min-height: 31px;
  padding: 7px 12px 6px;
  font-size: 0.76rem;
}

.large-button {
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  font-size: 1.16rem;
}

.primary:not(:disabled):hover,
.primary:not(:disabled):focus-visible {
  background: var(--blue-dark);
}

.primary:not(:disabled):active {
  transform: translateY(1px);
}

.primary:disabled {
  background: var(--mid-gray);
  color: var(--blue-soft);
}

.added-rules-wrap {
  margin-top: 10px;
}

.added-rules-wrap h3 {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
}

.added-rules {
  min-height: 56px;
  max-height: 82px;
  overflow-y: auto;
  border: 1px solid var(--border-dark);
  background: var(--light-gray);
  scrollbar-width: thin;
}

.rule-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 26px;
  padding: 3px 10px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 1rem;
}

.rule-item:hover,
.rule-item:focus-visible {
  background: #dddddd;
  outline: none;
}

.rule-item.is-selected {
  background: var(--dark-gray);
  color: var(--white);
}

.rule-item input {
  width: 14px;
  height: 14px;
  margin: 0;
  pointer-events: none;
}

.empty-rules {
  padding: 15px 10px;
  color: #a0a0a0;
  font-size: 0.86rem;
  font-style: italic;
}

.estimate-box {
  min-height: 46px;
  margin: 13px 0 19px;
  padding: 15px 16px;
  background: var(--mid-gray);
  color: var(--text);
  font-size: 0.86rem;
}

.footer-actions {
  display: grid;
  gap: 10px;
}

.status-message {
  min-height: 18px;
  margin: 10px 0 0;
  color: var(--text);
  text-align: center;
  font-size: 0.82rem;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(255, 255, 255, 0.72);
  z-index: 20;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-card {
  width: min(100%, 530px);
  padding: 26px 20px 28px;
  background: var(--mid-gray);
  box-shadow: var(--shadow);
  text-align: center;
}

.modal-card h2 {
  margin: 0 0 18px;
  color: var(--text);
  font-size: 1.18rem;
  line-height: 1.25;
}

.modal-rule {
  margin: 0 0 26px;
  color: var(--text);
  font-size: 1rem;
  font-style: italic;
  line-height: 1.35;
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
}

.is-hidden {
  display: none !important;
}

.success-card {
  min-height: 860px;
  padding: 0 38px 52px;
}

.success-content {
  display: flex;
  min-height: 804px;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-top: 86px;
}

.success-content h1 {
  max-width: 430px;
  font-weight: 400;
}

.success-line {
  width: min(100%, 365px);
  height: 4px;
  margin: 54px 0 36px;
  background: var(--text);
}

.success-content h2 {
  margin: 0 0 58px;
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1.25;
}

.success-content > p {
  margin: 0 0 84px;
  color: var(--text);
  font-size: 1.24rem;
  line-height: 1.35;
}

.success-stats {
  width: 100%;
  text-align: left;
}

.success-stats p {
  margin: 0;
  color: var(--text);
  font-size: 1.13rem;
  line-height: 1.25;
}

.audience-detail {
  width: 100%;
  margin-top: 28px;
  padding: 16px;
  border: 2px solid var(--border);
  background: #f5f5f5;
  text-align: left;
}

.audience-detail h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.audience-detail ul {
  margin: 0;
  padding-left: 19px;
}

.audience-detail li {
  margin-bottom: 6px;
  line-height: 1.35;
}

.success-button {
  width: min(100%, 230px);
  margin-top: auto;
}

.visually-hidden {
  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: 640px) {
    
    #toolTitle{font-size: 32px;}    
  .page-shell {
    padding: calc(env(safe-area-inset-top, 0px) + 32px) 14px 44px;
  }

  .tool-card {
    max-width: 600px;
    min-height: auto;
    padding: 24px 14px 16px;
  }

  .tool-header h1,
  .success-content h1 {
    font-size: clamp(2.15rem, 12vw, 3.2rem);
  }

  .tool-header p {
    margin-bottom: 54px;
    font-size: 0.98rem;
  }

  .rule-builder {
    padding-inline: 9px;
  }

  .rule-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .advanced-panel {
    grid-template-columns: 1fr;
    padding: 12px 18px 14px;
  }

  .rule-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .action-buttons {
    width: 100%;
    justify-content: flex-end;
  }

  .small-button {
    min-width: 0;
    flex: 1 1 115px;
  }

  .large-button {
    min-height: 50px;
    font-size: 1rem;
  }

  .success-card {
    min-height: calc(100dvh - env(safe-area-inset-top, 0px) - 76px);
    padding: 0 22px 44px;
  }

  .success-content {
    min-height: calc(100dvh - env(safe-area-inset-top, 0px) - 128px);
    padding-top: 56px;
  }

  .success-line {
    margin: 36px 0 32px;
  }

  .success-content h2 {
    margin-bottom: 44px;
    font-size: 1.12rem;
  }

  .success-content > p {
    margin-bottom: 56px;
    font-size: 1.05rem;
  }

  .success-stats p {
    font-size: 1rem;
  }
}

@media (max-width: 390px) {
  .page-shell {
    padding-top: calc(env(safe-area-inset-top, 0px) + 26px);
    padding-inline: 10px;
  }

  .tool-card {
    border-width: 3px;
    padding-inline: 11px;
  }

  .formula-preview {
    font-size: 0.94rem;
  }

  .rule-item {
    font-size: 0.91rem;
  }
}

/* Compact mode for iframe embeds only: use index.html?embed=true */
.embed-mode body {
  background: #ffffff;
}

.embed-mode .page-shell {
  min-height: auto;
  padding: 16px 14px 18px;
}

.embed-mode .tool-card {
  min-height: auto;
  padding: 18px 14px 14px;
  border-width: 3px;
}

.embed-mode .tool-header h1 {
  font-size: clamp(2rem, 7vw, 2.8rem);
}

.embed-mode .rule-line {
  margin-top: 14px;
}

.embed-mode .tool-header p {
  margin: 8px 4px 22px;
  font-size: 0.92rem;
}

.embed-mode .field-stack {
  gap: 9px;
  margin-bottom: 10px;
}

.embed-mode .guidance-prompt {
  min-height: 34px;
  margin-bottom: 10px;
  padding-top: 6px;
  padding-bottom: 6px;
}

.embed-mode .guidance-prompt p {
  font-size: 0.8rem;
}

.embed-mode .text-field,
.embed-mode .select-field {
  min-height: 36px;
}

.embed-mode .rule-builder {
  padding: 12px 8px 10px;
}

.embed-mode .full-select {
  margin-bottom: 10px;
  font-size: 0.98rem;
}

.embed-mode .rule-grid {
  gap: 8px;
}

.embed-mode .rule-col label {
  font-size: 0.92rem;
}

.embed-mode .advanced-toggle {
  min-height: 25px;
  margin-top: 9px;
  font-size: 0.82rem;
}

.embed-mode .advanced-panel {
  min-height: 42px;
  padding: 9px 28px 10px;
}

.embed-mode .formula-preview {
  min-height: 38px;
  margin-top: 10px;
  padding: 10px 8px;
  font-size: 0.9rem;
}

.embed-mode .meaning-preview {
  min-height: 40px;
  padding: 10px 8px 5px;
  font-size: 0.86rem;
}

.embed-mode .rule-actions {
  min-height: 32px;
}

.embed-mode .small-button {
  min-height: 27px;
  min-width: 88px;
  padding: 5px 10px;
  font-size: 0.68rem;
}

.embed-mode .added-rules-wrap {
  margin-top: 6px;
}

.embed-mode .added-rules {
  min-height: 42px;
  max-height: 58px;
}

.embed-mode .empty-rules {
  padding: 10px;
}

.embed-mode .estimate-box {
  min-height: 36px;
  margin: 9px 0 12px;
  padding: 11px 12px;
}

.embed-mode .large-button {
  min-height: 42px;
  padding: 9px 14px;
  font-size: 0.98rem;
}

.embed-mode .status-message {
  margin-top: 6px;
}
