:root {
  --bg: #f3f0e9;
  --panel: #fbf8f2;
  --panel-soft: #f7f1e4;
  --ink: #161412;
  --ink-soft: #4e4740;
  --line: #d8cfbf;
  --line-strong: #c8bca9;
  --ok: #2f7548;
  --bad: #8d3445;
  --shadow: 0 16px 42px rgba(25, 20, 15, 0.07);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 680px at 100% -20%, #ddd2bf 0%, transparent 60%),
    radial-gradient(900px 620px at -20% 20%, #ece3d5 0%, transparent 62%),
    linear-gradient(180deg, #f6f2eb 0%, var(--bg) 100%);
}

.app-shell {
  width: min(1220px, calc(100vw - 44px));
  margin: 16px auto 34px;
}

.reveal {
  animation: rise 360ms ease both;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(165deg, var(--panel), var(--panel-soft));
  box-shadow: var(--shadow);
}

.masthead {
  padding: 26px 28px 24px;
}

.masthead-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1 1 auto;
  min-width: 0;
}

.castle-logo {
  width: 52px;
  height: auto;
  flex: 0 0 auto;
  margin-top: 0;
}

.masthead-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex: 0 0 auto;
  padding-top: 6px;
}

.masthead-actions .overline {
  color: #6f665a;
  white-space: nowrap;
}

.masthead-actions .ghost-btn {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 0.95rem;
}

.overline,
.field-label {
  margin: 0;
  color: #756d62;
  text-transform: uppercase;
  letter-spacing: 0.17em;
  font-size: 0.68rem;
  font-family: "IBM Plex Mono", monospace;
}

.brand-lockup h1 {
  margin: 3px 0 0;
  font-family: "Instrument Serif", serif;
  font-size: clamp(2.7rem, 4.9vw, 4.5rem);
  line-height: 0.95;
  letter-spacing: -0.02em;
  font-weight: 400;
}

.brand-lockup h1 em {
  font-style: normal;
  font-weight: 600;
}

.lede {
  margin: 12px 0 0;
  color: var(--ink-soft);
  max-width: 66ch;
  font-size: clamp(1rem, 1.24vw, 1.12rem);
  line-height: 1.58;
}

.status-rack {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.rack-item {
  min-height: 146px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.55);
}

.rack-metric strong {
  font-size: clamp(2.4rem, 4.2vw, 4rem);
  letter-spacing: -0.03em;
  line-height: 0.95;
  font-weight: 700;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  border: 1px solid #c9bca7;
  background: #f7f2e8;
  padding: 10px 14px;
  font-size: 1rem;
}

.pill::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #a59a8b;
}

.pill.ok {
  color: var(--ok);
  border-color: rgba(112, 170, 137, 0.58);
  background: rgba(204, 232, 215, 0.35);
}

.pill.ok::before {
  background: var(--ok);
}

.pill.bad {
  color: var(--bad);
  border-color: rgba(178, 114, 127, 0.58);
  background: rgba(236, 202, 211, 0.35);
}

.pill.bad::before {
  background: var(--bad);
}

.pill.neutral {
  color: #665e53;
}

.ghost-btn,
.primary-btn,
.ghost-inline,
.dismiss-btn {
  border: 1px solid #25201b;
  color: #f5eee2;
  background: linear-gradient(145deg, #28221c, #14110f);
  border-radius: 10px;
  min-height: 46px;
  padding: 0 18px;
  font-family: "Manrope", sans-serif;
  font-size: 1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: transform 130ms ease, box-shadow 130ms ease, filter 130ms ease;
}

.ghost-btn:hover,
.primary-btn:hover,
.ghost-inline:hover,
.dismiss-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(21, 17, 14, 0.2);
  filter: brightness(1.04);
}

.ghost-btn:disabled,
.primary-btn:disabled,
.ghost-inline:disabled,
.dismiss-btn:disabled {
  opacity: 0.65;
  cursor: wait;
  transform: none;
  box-shadow: none;
}

.intake {
  margin-top: 18px;
  padding: 22px;
}

.section-head h2 {
  margin: 8px 0 0;
  font-family: "Instrument Serif", serif;
  font-size: clamp(1.9rem, 2.8vw, 2.5rem);
  line-height: 0.98;
  font-weight: 400;
}

.intake-form {
  margin-top: 14px;
}

.field {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: rgba(252, 249, 243, 0.7);
  display: grid;
  gap: 10px;
}

.field textarea {
  width: 100%;
  height: clamp(150px, 18vh, 200px);
  min-height: 150px;
  max-height: 360px;
  border: 1px solid #d4c9b8;
  border-radius: 10px;
  padding: 12px;
  font: inherit;
  line-height: 1.62;
  color: #24211c;
  background: #fdfaf4;
  resize: vertical;
}

.field textarea:focus {
  outline: none;
  border-color: #ac9a84;
  box-shadow: 0 0 0 3px rgba(162, 137, 106, 0.16);
}

.hint {
  color: #6c6357;
  font-size: 0.84rem;
}

.primary-btn {
  margin-top: 14px;
  width: 100%;
  min-height: 54px;
  font-family: "Instrument Serif", serif;
  font-size: clamp(1.35rem, 2.4vw, 2rem);
}

.progress-card {
  margin-top: 14px;
  padding: 14px;
}

.progress-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #5f574d;
  font-family: "IBM Plex Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.76rem;
}

.progress-track {
  margin-top: 10px;
  height: 10px;
  border-radius: 999px;
  background: #d8cebf;
  overflow: hidden;
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #8c4450 0%, #b58a58 36%, #8ea38f 100%);
  transition: width 520ms ease;
  position: relative;
  overflow: hidden;
  will-change: width;
}

.progress-fill::after {
  content: "";
  position: absolute;
  top: 0;
  left: -240px;
  width: 220px;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.5), transparent);
  transform: translate3d(0, 0, 0);
  animation: sheen 1.7s linear infinite;
  opacity: 0.9;
  pointer-events: none;
  will-change: transform;
}

.results {
  margin-top: 18px;
  padding: 22px;
}

.results-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.results-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.results-head h2 {
  margin: 8px 0 6px;
  font-family: "Instrument Serif", serif;
  font-size: clamp(1.95rem, 2.7vw, 2.45rem);
  line-height: 0.98;
  font-weight: 400;
}

.results-head p {
  margin: 0;
  color: #60584f;
}

.ghost-inline {
  min-height: 36px;
  border-radius: 999px;
  font-size: 0.84rem;
  margin-top: 4px;
}

.dash-actions {
  margin-top: 14px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.dash-alerts,
.dash-tracked {
  margin-top: 18px;
  padding: 22px;
}

.alerts-list {
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.alert-row {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(252, 248, 241, 0.72);
}

.alert-copy h4 {
  margin: 0;
  font-size: 1rem;
}

.alert-copy p {
  margin: 4px 0 0;
  color: #6c6357;
  font-size: 0.9rem;
}

.alert-metrics {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  min-width: 120px;
}

.alert-metrics .odds {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.delta {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
}

.delta.up {
  color: var(--ok);
}

.delta.down {
  color: var(--bad);
}

.watch-row {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: rgba(252, 248, 241, 0.72);
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.watch-row.major {
  border-color: rgba(175, 120, 90, 0.7);
  box-shadow: 0 12px 28px rgba(35, 24, 18, 0.08);
}

.watch-main h4 {
  margin: 0;
  font-size: 1.02rem;
}

.watch-main p {
  margin: 4px 0 0;
  color: #6c6357;
  font-size: 0.9rem;
}

.watch-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
  align-items: end;
}

.watch-odds,
.watch-delta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.watch-metrics .label {
  font-family: "IBM Plex Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.62rem;
  color: #6f665a;
}

.watch-metrics .value {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.watch-delta.up .value {
  color: var(--ok);
}

.watch-delta.down .value {
  color: var(--bad);
}

.watch-spark {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.spark {
  width: 120px;
  height: 26px;
}

.spark polyline {
  fill: none;
  stroke: rgba(35, 24, 18, 0.55);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.watch-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.risk-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.risk-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: rgba(252, 248, 241, 0.72);
}

.risk-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.risk-top h4 {
  margin: 0;
  font-size: 1rem;
}

.severity {
  border-radius: 999px;
  border: 1px solid;
  padding: 3px 8px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.severity.high {
  color: #7f2f3e;
  border-color: rgba(167, 102, 116, 0.7);
  background: rgba(231, 197, 205, 0.44);
}

.severity.medium {
  color: #856428;
  border-color: rgba(188, 157, 95, 0.7);
  background: rgba(238, 224, 190, 0.5);
}

.severity.low {
  color: #2f6d46;
  border-color: rgba(117, 174, 135, 0.66);
  background: rgba(195, 227, 207, 0.42);
}

.risk-cat {
  margin: 6px 0 2px;
  color: #796f60;
  font-family: "IBM Plex Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-size: 0.66rem;
}

.risk-card p {
  margin: 7px 0 0;
  color: #4f483f;
  font-size: 0.9rem;
  line-height: 1.5;
}

.categories-wrap {
  margin-top: 20px;
}

.theme-sections {
  margin-top: 8px;
  display: grid;
  gap: 10px;
}

.theme-group {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(251, 247, 240, 0.8);
  overflow: hidden;
}

.theme-group > summary {
  list-style: none;
  cursor: pointer;
  padding: 14px;
}

.theme-group > summary::-webkit-details-marker {
  display: none;
}

.theme-group > summary h3 {
  margin: 0;
  font-family: "Instrument Serif", serif;
  font-size: 1.74rem;
  font-weight: 400;
}

.theme-group > summary p {
  margin: 3px 0 0;
  color: #665d51;
  font-family: "IBM Plex Mono", monospace;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 0.78rem;
}

.theme-group[open] > summary {
  border-bottom: 1px solid var(--line);
}

.theme-rows {
  padding: 12px;
  display: grid;
  gap: 10px;
}

.event-row {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.52);
  padding: 12px;
  display: grid;
  gap: 10px;
}

.event-primary {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
}

.rank-badge {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #1f1b17;
  color: #f4ece2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.67rem;
}

.event-copy h4 {
  margin: 0;
  font-size: 1.01rem;
  line-height: 1.34;
}

.event-copy p {
  margin: 5px 0 0;
  color: #554d44;
  font-size: 0.87rem;
  line-height: 1.55;
}

.event-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.meta-chip {
  border: 1px solid #d4c8b6;
  border-radius: 999px;
  padding: 4px 9px;
  background: #f8f2e7;
  color: #60594f;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.64rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.meta-chip strong {
  color: #1f1a16;
  font-weight: 500;
}

.contract-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.contract-chip {
  border: 1px solid #d4c8b6;
  border-radius: 999px;
  padding: 3px 8px;
  background: #f7f1e6;
  color: #5f584d;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.63rem;
  letter-spacing: 0.04em;
}

.event-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.event-link {
  border: 1px solid #cabaa3;
  border-radius: 8px;
  min-height: 30px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: #211d19;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  background: #f7f1e7;
}

.event-link:hover {
  background: #f0e8da;
}

.dismiss-btn {
  min-height: 30px;
  border-radius: 999px;
  padding: 0 12px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.hidden {
  display: none !important;
}

.muted {
  color: #73695d;
  font-size: 0.9rem;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes sheen {
  to {
    transform: translate3d(1600px, 0, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .progress-fill {
    transition: none;
  }

  .progress-fill::after {
    display: none;
    animation: none;
  }
}

@media (max-width: 1100px) {
  .rack-item {
    min-height: 146px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: calc(100vw - 20px);
    margin: 10px auto 22px;
  }

  .panel {
    border-radius: 18px;
  }

  .masthead,
  .intake,
  .results,
  .progress-card {
    padding: 16px;
  }

  .brand-lockup {
    gap: 12px;
  }

  .castle-logo {
    width: 44px;
  }

  .brand-lockup h1 {
    font-size: clamp(2.1rem, 10vw, 3rem);
  }

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

  .rack-item {
    min-height: 124px;
  }

  .masthead-top {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .masthead-actions {
    justify-content: space-between;
    padding-top: 0;
  }

  .masthead-actions .ghost-btn {
    min-height: 42px;
    padding: 0 16px;
  }

  .field textarea {
    height: 180px;
    min-height: 180px;
  }

  .results-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .results-actions {
    justify-content: flex-start;
  }

  .dash-actions {
    justify-content: flex-start;
  }

  .dash-alerts,
  .dash-tracked {
    padding: 16px;
  }

  .watch-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .watch-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .watch-spark {
    justify-content: flex-start;
  }
}
