:root {
  --ink: #17211b;
  --muted: #667267;
  --paper: #fff8e9;
  --paper-strong: #fffdf7;
  --line: rgba(23, 33, 27, 0.14);
  --green: #1f7a4d;
  --green-deep: #0f4b35;
  --saffron: #f3b23d;
  --coral: #e9674a;
  --ruby: #b7383d;
  --blue: #315f76;
  --shadow: 0 24px 80px rgba(26, 43, 32, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: 'PingFang SC', 'Microsoft YaHei', 'Noto Sans Thai', sans-serif;
  background:
    radial-gradient(circle at 12% 10%, rgba(243, 178, 61, 0.24), transparent 28rem),
    radial-gradient(circle at 90% 15%, rgba(31, 122, 77, 0.18), transparent 26rem),
    linear-gradient(135deg, #f8efd8 0%, #f5f0df 44%, #e9f0df 100%);
  overflow-x: hidden;
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: '';
  background-image:
    linear-gradient(rgba(23, 33, 27, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 33, 27, 0.035) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: linear-gradient(to bottom, #000 0%, transparent 90%);
}

.aurora {
  position: fixed;
  z-index: -1;
  width: 34rem;
  height: 34rem;
  border-radius: 999px;
  filter: blur(20px);
  opacity: 0.55;
  animation: drift 14s ease-in-out infinite alternate;
}

.aurora-a {
  left: -12rem;
  top: 16rem;
  background: rgba(233, 103, 74, 0.24);
}

.aurora-b {
  right: -14rem;
  bottom: 4rem;
  background: rgba(49, 95, 118, 0.2);
  animation-delay: -5s;
}

.shell {
  width: min(1440px, calc(100% - 40px));
  margin: 0 auto;
  padding: 32px 0 56px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 32px;
  background: rgba(255, 253, 247, 0.76);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
}

.hero {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 28px;
  align-items: stretch;
  padding: 42px;
  overflow: hidden;
  position: relative;
}

.hero::after {
  position: absolute;
  right: 18rem;
  bottom: -6rem;
  width: 20rem;
  height: 20rem;
  border: 1px solid rgba(31, 122, 77, 0.2);
  border-radius: 40% 60% 50% 50%;
  content: '';
  transform: rotate(-12deg);
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--green-deep);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 920px;
  margin-bottom: 18px;
  font-family: 'Noto Serif SC', serif;
  font-size: clamp(2.4rem, 6vw, 5.2rem);
  line-height: 0.98;
  letter-spacing: -0.06em;
}

h2 {
  margin-bottom: 0;
  font-family: 'Noto Serif SC', serif;
  font-size: clamp(1.45rem, 2.6vw, 2rem);
  letter-spacing: -0.03em;
}

.hero-copy {
  max-width: 850px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.9;
}

.hero-card {
  display: grid;
  align-content: end;
  min-height: 240px;
  padding: 28px;
  border-radius: 28px;
  color: #fff8e9;
  background:
    linear-gradient(160deg, rgba(15, 75, 53, 0.95), rgba(31, 122, 77, 0.8)),
    repeating-linear-gradient(45deg, transparent 0 10px, rgba(255, 255, 255, 0.08) 10px 12px);
}

.metric {
  font-size: 6rem;
  font-weight: 700;
  line-height: 0.9;
}

.hero-card small {
  margin-top: 8px;
  color: rgba(255, 248, 233, 0.78);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 0.92fr) minmax(420px, 1.08fr);
  gap: 24px;
  margin-top: 24px;
}

.input-panel,
.result-panel,
.kb-panel {
  padding: 28px;
}

.section-head {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

label {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
  color: var(--green-deep);
  font-weight: 700;
}

textarea,
select {
  width: 100%;
  border: 1px solid rgba(23, 33, 27, 0.18);
  border-radius: 20px;
  outline: none;
  color: var(--ink);
  background: rgba(255, 248, 233, 0.76);
  font: inherit;
  font-weight: 500;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

textarea {
  resize: vertical;
  padding: 18px;
  line-height: 1.75;
}

select {
  min-height: 52px;
  padding: 0 16px;
}

textarea:focus,
select:focus {
  border-color: rgba(31, 122, 77, 0.72);
  background: rgba(255, 253, 247, 0.96);
  box-shadow: 0 0 0 5px rgba(31, 122, 77, 0.12);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

button {
  cursor: pointer;
  border: 0;
  font: inherit;
  font-weight: 800;
}

.primary,
.ghost,
.tab {
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.primary:hover,
.ghost:hover,
.tab:hover {
  transform: translateY(-1px);
}

.primary {
  width: 100%;
  margin-top: 6px;
  padding: 18px 22px;
  border-radius: 999px;
  color: #fff8e9;
  background: linear-gradient(135deg, var(--green-deep), var(--green));
  box-shadow: 0 16px 36px rgba(15, 75, 53, 0.26);
}

.ghost {
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--green-deep);
  background: rgba(255, 248, 233, 0.72);
}

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 82px;
  padding: 10px 14px;
  border-radius: 999px;
  color: #fff;
  font-weight: 800;
}

.badge.muted {
  color: var(--muted);
  background: rgba(23, 33, 27, 0.08);
}

.badge.fail {
  background: var(--ruby);
}

.badge.pass {
  background: var(--blue);
}

.badge.excellent {
  background: var(--green);
}

.score-card {
  display: grid;
  grid-template-columns: 136px 1fr;
  gap: 22px;
  align-items: center;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(255, 248, 233, 0.68);
}

.score-ring {
  display: grid;
  place-items: center;
  width: 128px;
  height: 128px;
  border-radius: 999px;
  background:
    radial-gradient(circle, var(--paper-strong) 0 56%, transparent 57%),
    conic-gradient(var(--green) calc(var(--score) * 1%), rgba(23, 33, 27, 0.1) 0);
}

.score-ring span {
  font-size: 2.6rem;
  font-weight: 800;
}

.score-label {
  margin-bottom: 8px;
  font-size: 1.38rem;
  font-weight: 800;
}

.score-note {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.8;
}

.tabs {
  display: flex;
  gap: 10px;
  margin: 22px 0;
  padding: 6px;
  border-radius: 999px;
  background: rgba(23, 33, 27, 0.07);
}

.tab {
  flex: 1;
  padding: 11px 14px;
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
}

.tab.active {
  color: var(--green-deep);
  background: var(--paper-strong);
  box-shadow: 0 8px 22px rgba(23, 33, 27, 0.1);
}

.tab-page {
  display: none;
}

.tab-page.active {
  display: block;
  animation: rise 220ms ease both;
}

.finding,
.evidence-card,
.rewrite-box,
.mini-note,
.kb-card,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 253, 247, 0.72);
}

.finding {
  margin-bottom: 12px;
  padding: 18px;
}

.finding-head {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.finding-head span {
  padding: 5px 9px;
  border-radius: 999px;
  color: #fff;
  font-size: 0.76rem;
  font-weight: 800;
}

.finding.critical .finding-head span,
.finding.high .finding-head span {
  background: var(--ruby);
}

.finding.medium .finding-head span {
  background: var(--coral);
}

.finding.low .finding-head span {
  background: var(--saffron);
  color: var(--ink);
}

.finding.positive .finding-head span,
.finding.positive strong {
  color: var(--green-deep);
}

.finding p,
.evidence-card p,
.kb-card p {
  margin-bottom: 10px;
  color: var(--muted);
  line-height: 1.75;
}

.hit-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--muted);
}

code {
  padding: 3px 7px;
  border-radius: 8px;
  color: var(--ruby);
  background: rgba(183, 56, 61, 0.1);
  font-family: 'IBM Plex Sans Thai', monospace;
}

.suggestion {
  padding: 12px 14px;
  border-radius: 16px;
  color: var(--green-deep);
  background: rgba(31, 122, 77, 0.1);
  line-height: 1.7;
  font-weight: 700;
}

.rewrite-box {
  padding: 22px;
  background:
    linear-gradient(135deg, rgba(31, 122, 77, 0.12), rgba(243, 178, 61, 0.14)),
    rgba(255, 253, 247, 0.78);
}

.rewrite-box h3 {
  margin-bottom: 14px;
  font-family: 'Noto Serif SC', serif;
}

.rewrite-head {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.rewrite-head h3 {
  margin-bottom: 0;
}

.ai-status {
  padding: 7px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.ai-status.idle {
  color: var(--muted);
  background: rgba(23, 33, 27, 0.08);
}

.ai-status.loading {
  color: var(--blue);
  background: rgba(49, 95, 118, 0.12);
}

.ai-status.ready {
  color: var(--green-deep);
  background: rgba(31, 122, 77, 0.13);
}

.ai-status.error {
  color: var(--ruby);
  background: rgba(183, 56, 61, 0.1);
}

.rewrite-box p {
  margin-bottom: 0;
  font-size: 1.35rem;
  line-height: 1.8;
  font-weight: 700;
}

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

.mini-note {
  padding: 13px 15px;
  color: var(--muted);
  line-height: 1.65;
}

.evidence-card {
  margin-bottom: 12px;
  padding: 18px;
}

.evidence-card span {
  display: block;
  margin-bottom: 4px;
  color: var(--green-deep);
  font-weight: 800;
}

.evidence-card strong {
  display: block;
  margin-bottom: 10px;
}

.evidence-card ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.8;
}

.quiet {
  opacity: 0.68;
}

.empty-state {
  padding: 26px;
  color: var(--muted);
  text-align: center;
}

.kb-panel {
  margin-top: 24px;
}

.kb-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
}

.kb-card {
  min-height: 180px;
  padding: 18px;
  position: relative;
  overflow: hidden;
}

.kb-card::after {
  position: absolute;
  right: -24px;
  bottom: -24px;
  width: 96px;
  height: 96px;
  border-radius: 999px;
  background: rgba(243, 178, 61, 0.2);
  content: '';
}

.kb-card span {
  color: var(--saffron);
  font-weight: 800;
}

.kb-card h3 {
  margin: 12px 0;
  font-size: 1.08rem;
}

@keyframes drift {
  from {
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
  to {
    transform: translate3d(3rem, -2rem, 0) rotate(16deg);
  }
}

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

@media (max-width: 1080px) {
  .hero,
  .workspace {
    grid-template-columns: 1fr;
  }

  .field-grid,
  .kb-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 680px) {
  .shell {
    width: min(100% - 24px, 1440px);
    padding-top: 12px;
  }

  .hero,
  .input-panel,
  .result-panel,
  .kb-panel {
    padding: 20px;
    border-radius: 24px;
  }

  .section-head,
  .score-card {
    grid-template-columns: 1fr;
  }

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

  .field-grid,
  .kb-grid {
    grid-template-columns: 1fr;
  }

  .score-card {
    display: grid;
    justify-items: center;
    text-align: center;
  }

  .tabs {
    border-radius: 22px;
  }

  .tab {
    padding: 10px 8px;
  }
}
