:root {
  --bg: #fcfefd;
  --surface: #ecf6f2;
  --border: #dde0de;
  --text: #5a605d;
  --muted: #8b9691;
  --primary: #0fa1b1;
  --secondary: #749b4a;
  --accent: #9488c5;
  --primary-dark: oklch(45% 0.105 210);
  --secondary-dark: oklch(43% 0.09 130);
  --accent-dark: oklch(48% 0.105 295);
  --ink: oklch(35% 0.025 170);
  --shadow: 0 22px 70px rgba(45, 91, 80, 0.10);
}

* { box-sizing: border-box; }
html { background: var(--bg); color: var(--text); overflow-x: hidden; }
body { margin: 0; min-width: 320px; min-height: 100vh; font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif; line-height: 1.55; overflow-x: hidden; }
button, a { font: inherit; }
button { min-height: 44px; }
[hidden] { display: none !important; }

.wash { position: fixed; z-index: -1; border-radius: 44% 56% 62% 38%; filter: blur(2px); opacity: .62; pointer-events: none; }
.wash-one { width: 520px; height: 360px; top: -160px; right: -130px; background: radial-gradient(ellipse at 40% 45%, color-mix(in oklch, var(--primary) 16%, transparent), transparent 68%); transform: rotate(-12deg); }
.wash-two { width: 520px; height: 500px; left: -260px; top: 42vh; background: radial-gradient(ellipse, color-mix(in oklch, var(--accent) 12%, transparent), transparent 68%); }

.masthead, main, .site-footer { width: min(1080px, calc(100% - 40px)); margin-inline: auto; }
.masthead { height: 92px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.brand { color: var(--ink); display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 650; letter-spacing: -.01em; }
.brand svg { width: 34px; height: 34px; fill: none; stroke: var(--secondary-dark); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.brand .curl { stroke: var(--primary-dark); }
.account-chip { color: var(--primary-dark); font-size: .82rem; letter-spacing: .03em; border: 1px solid color-mix(in oklch, var(--primary) 32%, var(--border)); background: color-mix(in oklch, var(--surface) 70%, transparent); border-radius: 999px; padding: 7px 13px; }

main { padding: 74px 0 80px; }
.intro { max-width: 760px; margin-bottom: 46px; }
.eyebrow, .state-kicker { margin: 0 0 10px; color: var(--primary-dark); font-size: .72rem; font-weight: 750; letter-spacing: .16em; }
h1, h2, p { overflow-wrap: anywhere; }
h1 { margin: 0; color: var(--ink); font-size: clamp(2.7rem, 7vw, 5.4rem); line-height: .98; font-weight: 540; letter-spacing: -.055em; max-width: 840px; }
h1 em { color: var(--accent-dark); font-family: Georgia, serif; font-weight: 400; }
.intro > p:last-child { max-width: 620px; margin: 26px 0 0; font-size: 1.08rem; }

.state-panel { min-height: 190px; display: flex; align-items: center; gap: 28px; padding: clamp(24px, 5vw, 46px); background: color-mix(in oklch, var(--surface) 84%, white); border: 1px solid var(--border); border-radius: 30px 34px 28px 36px; box-shadow: var(--shadow); }
.state-panel h2 { margin: 0 0 8px; color: var(--ink); font-size: clamp(1.35rem, 3vw, 2rem); font-weight: 560; }
.state-panel p:last-child { margin: 0; }
.loader { width: 78px; height: 78px; flex: 0 0 auto; position: relative; }
.loader span { position: absolute; inset: 15px; border-radius: 64% 36% 58% 42%; background: color-mix(in oklch, var(--primary) 28%, transparent); animation: bloom 3.2s ease-in-out infinite alternate; }
.loader span:nth-child(2) { inset: 5px 20px 24px 3px; background: color-mix(in oklch, var(--secondary) 25%, transparent); animation-delay: -.9s; }
.loader span:nth-child(3) { inset: 28px 2px 3px 30px; background: color-mix(in oklch, var(--accent) 27%, transparent); animation-delay: -1.7s; }
@keyframes bloom { to { transform: rotate(18deg) scale(1.14); border-radius: 40% 60% 35% 65%; } }
.error-panel { border-color: color-mix(in oklch, var(--accent) 45%, var(--border)); }
.error-mark { width: 58px; height: 58px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50% 46% 54% 48%; color: white; background: var(--accent-dark); font-weight: 800; font-size: 1.35rem; }
.button { cursor: pointer; margin-top: 17px; padding: 10px 20px; border: 0; border-radius: 999px; color: white; background: var(--primary-dark); font-weight: 650; box-shadow: 0 7px 22px rgba(15, 111, 123, .16); }
.button:hover { background: oklch(40% 0.105 210); transform: translateY(-1px); }
:focus-visible { outline: 3px solid var(--primary-dark); outline-offset: 4px; }

.density-control { margin: 0 8px 18px; }
.density-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 18px; }
.density-heading label { color: var(--ink); font-weight: 650; }
.density-heading output { color: var(--primary-dark); font-size: .9rem; font-weight: 700; font-variant-numeric: tabular-nums; }
#word-limit { width: 100%; height: 44px; margin: 2px 0 -6px; cursor: pointer; accent-color: var(--primary-dark); }
#word-limit:disabled { cursor: default; opacity: .58; }
.density-scale { display: flex; justify-content: space-between; color: var(--muted); font-size: .72rem; }
.density-note { margin: 7px 0 0; color: var(--muted); font-size: .8rem; }

.result-card { padding: clamp(25px, 5vw, 52px); background: rgba(252, 254, 253, .92); border: 1px solid var(--border); border-radius: 40px 31px 44px 35px; box-shadow: var(--shadow); overflow: hidden; position: relative; }
.result-card::before { content: ""; position: absolute; width: 300px; height: 180px; right: -80px; top: -80px; background: radial-gradient(ellipse, color-mix(in oklch, var(--primary) 13%, transparent), transparent 70%); pointer-events: none; }
.result-header { display: flex; align-items: start; justify-content: space-between; gap: 22px; position: relative; }
.result-header h2, .ranking h2 { margin: 0; color: var(--ink); font-size: clamp(1.6rem, 3.2vw, 2.5rem); line-height: 1.1; font-weight: 570; letter-spacing: -.03em; }
.result-account { margin: 2px 0 0; color: var(--primary-dark); font-weight: 650; white-space: nowrap; }
.cloud-wrap { margin: 26px 0 22px; width: 100%; }
#word-cloud { width: 100%; height: auto; display: block; overflow: visible; }
#cloud-words text { paint-order: stroke; stroke: rgba(252,254,253,.72); stroke-width: 2px; stroke-linejoin: round; animation: settle .55s ease both; }
@keyframes settle { from { opacity: 0; transform: translateY(7px); } }
.result-meta { padding-top: 23px; border-top: 1px solid var(--border); display: grid; grid-template-columns: .7fr 1fr 1.3fr 1.4fr; gap: 18px; }
.result-meta div { min-width: 0; }
.result-meta span { display: block; color: var(--muted); font-size: .64rem; font-weight: 750; letter-spacing: .12em; }
.result-meta strong { display: block; margin-top: 4px; color: var(--ink); font-size: .92rem; font-weight: 650; }
.result-actions { display: flex; align-items: center; gap: 18px; padding: 18px 8px 0; }
.result-actions .button { margin: 0; }
.result-actions p { margin: 0; color: var(--muted); font-size: .88rem; }

.ranking { margin-top: 70px; display: grid; grid-template-columns: minmax(230px, .75fr) 1.5fr; gap: clamp(30px, 7vw, 80px); align-items: start; }
.method { max-width: 37ch; color: var(--muted); font-size: .9rem; }
#word-ranking { list-style: none; counter-reset: rank; display: grid; grid-template-columns: 1fr 1fr; gap: 0 34px; margin: 0; padding: 0; }
#word-ranking li { counter-increment: rank; display: grid; grid-template-columns: 27px 1fr auto; align-items: baseline; min-width: 0; padding: 9px 0; border-bottom: 1px solid var(--border); }
#word-ranking li::before { content: counter(rank, decimal-leading-zero); color: var(--muted); font-size: .66rem; }
.rank-word { color: var(--ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.rank-count { color: var(--primary-dark); font-variant-numeric: tabular-nums; font-size: .84rem; }
.site-footer { min-height: 90px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: .78rem; }

@media (max-width: 700px) {
  .masthead, main, .site-footer { width: min(100% - 28px, 1080px); }
  .masthead { height: 74px; }
  .account-chip { display: none; }
  main { padding-top: 48px; }
  .intro { margin-bottom: 34px; }
  .state-panel { align-items: flex-start; gap: 15px; }
  .loader { width: 52px; height: 52px; }
  .result-header { display: block; }
  .result-account { margin-top: 9px; }
  #word-cloud { aspect-ratio: 3 / 4; }
  .result-meta { grid-template-columns: 1fr 1fr; }
  .ranking { grid-template-columns: 1fr; margin-top: 52px; }
  #word-ranking { grid-template-columns: 1fr; }
  .result-actions { align-items: flex-start; flex-direction: column; gap: 7px; }
  .density-control { margin-inline: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
