/* === DESIGN TOKENS === */
:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #f1f3f7;
  --text: #0f1117;
  --text-soft: #4a5365;
  --text-mute: #8a93a3;
  --border: #e3e7ee;
  --primary: #5b8def;
  --primary-2: #7c5dee;
  --grad: linear-gradient(135deg, #5b8def 0%, #7c5dee 100%);
  --shadow: 0 4px 24px rgba(15, 17, 23, 0.06);
  --radius: 12px;
  --radius-lg: 16px;
}
[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #181b25;
  --surface-2: #232733;
  --text: #f1f3f7;
  --text-soft: #b8c0cc;
  --text-mute: #6e7689;
  --border: #2a2e3b;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 16px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-2); }

/* === EMBED MODE === */
body.embed .hd, body.embed .ft, body.embed .article, body.embed .related, body.embed .breadcrumb { display: none !important; }
body.embed .calc-page { padding: 16px 0; }
body.embed .container { padding: 0 12px; }
body.embed .calc-form { position: static; padding: 18px; }
body.embed .calc-result { padding: 18px; }
body.embed .calc-layout { gap: 16px; }
body.embed .calc-head { margin-bottom: 16px; }

/* === HEADER === */
.hd { position: sticky; top: 0; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 100; backdrop-filter: blur(12px); }
.hd-row { display: flex; align-items: center; gap: 24px; padding: 14px 20px; }
.hd-logo { display: flex; align-items: center; gap: 8px; font-weight: 800; color: var(--text); font-size: 18px; }
.hd-logo-icon { width: 32px; height: 32px; display: grid; place-items: center; background: var(--grad); color: #fff; border-radius: 8px; font-weight: 900; }
.hd-nav { display: flex; gap: 22px; margin-left: auto; }
.hd-nav a { color: var(--text-soft); font-weight: 500; }
.hd-nav a:hover { color: var(--primary); }
.hd-theme { background: none; border: 1px solid var(--border); cursor: pointer; padding: 8px 12px; border-radius: 8px; font-size: 16px; color: var(--text); }
.hd-geo { position: relative; }
.hd-geo-btn { background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; padding: 8px 12px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--text); }
.hd-geo-menu { position: absolute; top: 100%; right: 0; margin-top: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; min-width: 180px; z-index: 200; }
.hd-geo-menu button { display: block; width: 100%; text-align: left; padding: 8px 12px; background: none; border: 0; border-radius: 6px; cursor: pointer; font-size: 14px; color: var(--text); }
.hd-geo-menu button:hover { background: var(--surface-2); }
@media (max-width: 720px) { .hd-nav { display: none; } }

/* === HERO === */
.hero { padding: 60px 0 48px; }
.hero-h1 { font-size: clamp(32px, 5vw, 48px); font-weight: 800; line-height: 1.1; letter-spacing: -0.02em; max-width: 800px; }
.grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero-sub { font-size: 18px; color: var(--text-soft); margin-top: 16px; max-width: 720px; }
.hero-feats { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }
.hero-feat { padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 100px; font-size: 14px; font-weight: 500; }

/* === CATEGORIES === */
.cat { padding: 32px 0; }
.cat-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 20px; }
.cat-head h2 { font-size: 26px; font-weight: 700; }
.cat-count { color: var(--text-mute); font-size: 14px; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card { display: flex; flex-direction: column; padding: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); transition: transform .15s, box-shadow .2s, border-color .2s; color: var(--text); position: relative; overflow: hidden; }
.card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--card-color, var(--primary)); opacity: 0; transition: opacity .2s; }
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--card-color, var(--primary)); }
.card:hover::before { opacity: 1; }
.card-icon { font-size: 32px; margin-bottom: 12px; }
.card-title { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.card-desc { font-size: 14px; color: var(--text-soft); flex: 1; }
.card-cta { margin-top: 14px; font-size: 14px; font-weight: 600; color: var(--card-color, var(--primary)); }

/* === WHY === */
.why { padding: 60px 0 80px; }
.why h2 { font-size: 28px; font-weight: 700; margin-bottom: 28px; text-align: center; }
.why-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; }
.why-item { padding: 24px; background: var(--surface); border-radius: var(--radius-lg); border: 1px solid var(--border); }
.why-item { display: flex; flex-direction: column; }
.why-item b { display: block; margin-bottom: 8px; font-size: 16px; }
.why-item p { color: var(--text-soft); font-size: 14px; flex: 1; margin-bottom: 14px; }
.why-btn { display: inline-block; padding: 10px 16px; background: var(--grad); color: #fff; border-radius: 10px; font-size: 13px; font-weight: 600; text-decoration: none; text-align: center; transition: transform .15s, box-shadow .2s; align-self: flex-start; }
.why-btn:hover { color: #fff; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(91,141,239,0.35); }

/* === FOOTER === */
.ft { background: var(--surface); border-top: 1px solid var(--border); margin-top: 80px; padding: 48px 0 24px; }
.ft-row { display: grid; grid-template-columns: 2fr repeat(4, 1fr); gap: 24px; }
.ft-logo { font-weight: 800; font-size: 18px; margin-bottom: 8px; }
.ft-tagline { color: var(--text-mute); font-size: 14px; }
.ft-col h4 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-mute); margin-bottom: 12px; }
.ft-col a, .ft-col span { display: block; color: var(--text-soft); font-size: 14px; margin-bottom: 6px; }
.ft-col a:hover { color: var(--primary); }
.ft-soon { opacity: 0.5; }
.ft-about { font-size: 13px; color: var(--text-soft); }
.ft-bottom { display: flex; justify-content: space-between; padding-top: 24px; margin-top: 32px; border-top: 1px solid var(--border); color: var(--text-mute); font-size: 13px; }
@media (max-width: 720px) {
  .ft-row { grid-template-columns: 1fr 1fr; }
  .container { padding: 0 14px; }
  .hd-row { gap: 10px; padding: 10px 14px; }
  .hd-logo-text { display: none; }
  .hero { padding: 32px 0 24px; }
  .hero-h1 { font-size: 28px; }
  .hero-sub { font-size: 15px; }
  .calc-form { padding: 18px; position: static; }
  .calc-form .row { grid-template-columns: 1fr; gap: 0; }
  .calc-result { padding: 18px; }
  .calc-head { gap: 12px; }
  .calc-icon { width: 48px; height: 48px; font-size: 22px; }
  .result-bigval { font-size: 28px; }
  .result-stats { gap: 8px; }
  .result-stat { padding: 10px 12px; }
  .cat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { padding: 16px; }
  .card-icon { font-size: 24px; }
  .card-title { font-size: 15px; }
  .card-desc { font-size: 12px; }
}
@media (max-width: 420px) {
  .cat-grid { grid-template-columns: 1fr; }
  .hero-feats { gap: 6px; }
  .hero-feat { padding: 6px 10px; font-size: 12px; }
}

/* Accessibility — focus rings */
*:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
button, input, select { font-family: inherit; }
input:invalid { border-color: #ef4444; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* === CALC PAGE === */
.calc-page { padding: 32px 0 60px; }
.breadcrumb { font-size: 13px; color: var(--text-mute); margin-bottom: 20px; }
.breadcrumb a { color: var(--text-mute); }
.breadcrumb span { margin: 0 6px; }
.calc-head { display: flex; gap: 20px; align-items: flex-start; margin-bottom: 28px; }
.calc-icon { font-size: 28px; width: 64px; height: 64px; display: grid; place-items: center; border-radius: 14px; flex-shrink: 0; }
.calc-h1 { font-size: clamp(24px, 3vw, 32px); font-weight: 800; line-height: 1.2; letter-spacing: -0.01em; }
.calc-desc { color: var(--text-soft); margin-top: 6px; }

.calc-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 24px; align-items: flex-start; }
@media (max-width: 900px) { .calc-layout { grid-template-columns: 1fr; } }

.calc-form { background: var(--surface); padding: 28px; border-radius: var(--radius-lg); border: 1px solid var(--border); position: sticky; top: 84px; }
.voice-btn { display: flex; align-items: center; gap: 8px; width: 100%; padding: 12px 16px; background: linear-gradient(135deg, rgba(91,141,239,0.12), rgba(124,93,238,0.12)); border: 1px solid rgba(91,141,239,0.25); border-radius: 10px; color: var(--text); font-size: 14px; font-weight: 500; cursor: pointer; margin-bottom: 16px; transition: all .15s; }
.voice-btn:hover { background: linear-gradient(135deg, rgba(91,141,239,0.2), rgba(124,93,238,0.2)); }
.voice-btn.recording { background: rgba(239,68,68,0.15); border-color: rgba(239,68,68,0.5); color: #ef4444; animation: pulse-bg 1s infinite; }
.voice-btn.recording::before { content: '⏺ '; animation: blink 1s infinite; }
@keyframes pulse-bg { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.5); } 50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); } }
@keyframes blink { 50% { opacity: 0.3; } }
.voice-toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); padding: 12px 22px; background: var(--surface); border: 1px solid var(--border); border-radius: 100px; box-shadow: var(--shadow); z-index: 1000; font-size: 14px; }
.calc-form h3 { font-size: 16px; font-weight: 700; margin: 18px 0 10px; }
.calc-form h3:first-child { margin-top: 0; }
.calc-form label { display: block; margin-bottom: 12px; font-size: 14px; font-weight: 500; color: var(--text-soft); }
.calc-form label small { color: var(--text-mute); font-weight: 400; }
.calc-form input, .calc-form select { width: 100%; padding: 11px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; font-size: 15px; font-family: inherit; color: var(--text); margin-top: 4px; transition: border-color .15s; }
.calc-form input:focus, .calc-form select:focus { outline: none; border-color: var(--primary); }
.calc-form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.calc-form .check { display: flex; align-items: center; gap: 8px; }
.calc-form .check input { width: auto; margin: 0; }
.btn-primary { background: var(--grad); color: #fff; border: none; padding: 14px 28px; border-radius: 12px; font-size: 16px; font-weight: 600; cursor: pointer; width: 100%; margin-top: 12px; transition: transform .1s, box-shadow .2s; }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(91, 141, 239, 0.4); }

.calc-result { padding: 28px; background: var(--surface); border-radius: var(--radius-lg); border: 1px solid var(--border); min-height: 320px; position: relative; }
.result-actions { display: flex; gap: 8px; margin-bottom: 16px; }
.result-action-btn { padding: 8px 14px; font-size: 13px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); cursor: pointer; transition: background .15s; }
.result-action-btn:hover { background: var(--border); }
@media print {
  body * { visibility: hidden; }
  .calc-result, .calc-result * { visibility: visible; }
  .calc-result { position: absolute; left: 0; top: 0; padding: 24px; border: none; box-shadow: none; }
  .result-actions, .ai-box-loading { display: none !important; }
}
.result-empty { color: var(--text-mute); text-align: center; padding: 60px 20px; }
.result-empty-icon { display: block; font-size: 32px; margin-bottom: 12px; }

/* result content */
.result-main { display: grid; gap: 14px; }
.result-bigval { font-size: 36px; font-weight: 800; letter-spacing: -0.02em; line-height: 1; }
.result-bigval-label { color: var(--text-mute); font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.result-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin: 18px 0; }
.result-stat { padding: 14px 16px; background: var(--surface-2); border-radius: 10px; }
.result-stat-label { font-size: 12px; color: var(--text-mute); text-transform: uppercase; letter-spacing: 0.05em; }
.result-stat-value { font-size: 18px; font-weight: 700; margin-top: 4px; }
.result-section { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--border); }
.result-section h4 { font-size: 15px; font-weight: 700; margin-bottom: 10px; }

/* AI box */
.ai-box { margin-top: 20px; padding: 18px 20px; background: linear-gradient(135deg, rgba(91, 141, 239, 0.08), rgba(124, 93, 238, 0.08)); border: 1px solid rgba(91, 141, 239, 0.25); border-radius: 14px; }
.ai-box-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-weight: 700; font-size: 14px; }
.ai-box-head .ai-pulse { width: 8px; height: 8px; background: var(--primary); border-radius: 50%; animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.5; transform: scale(1.5); } }
.ai-box-text { font-size: 14px; color: var(--text); white-space: pre-wrap; line-height: 1.6; }
.ai-box-loading { color: var(--text-mute); font-style: italic; }
.ai-box-error { color: #ef4444; font-size: 13px; }

/* schedule table */
.sched { margin-top: 16px; max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; }
.sched table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sched th, .sched td { padding: 8px 12px; text-align: right; border-bottom: 1px solid var(--border); }
.sched th { background: var(--surface-2); position: sticky; top: 0; font-weight: 600; color: var(--text-soft); }
.sched tr:last-child td { border: 0; }

/* time machine */
.tm { margin-top: 16px; }
.tm-row { display: grid; grid-template-columns: 60px 1fr 80px 80px; gap: 10px; padding: 8px 12px; align-items: center; border-radius: 8px; margin-bottom: 4px; }
.tm-year { font-weight: 700; font-size: 14px; }
.tm-bar { height: 6px; background: var(--surface-2); border-radius: 100px; overflow: hidden; }
.tm-fill { height: 100%; transition: width .4s; border-radius: 100px; }
.tm-burden { font-weight: 600; font-size: 13px; }
.tm-low { color: #22c55e; } .tm-low .tm-fill { background: #22c55e; }
.tm-medium { color: #eab308; } .tm-medium .tm-fill { background: #eab308; }
.tm-high { color: #f97316; } .tm-high .tm-fill { background: #f97316; }
.tm-critical { color: #ef4444; } .tm-critical .tm-fill { background: #ef4444; }

/* related */
.related { margin-top: 48px; }
.related h3 { font-size: 18px; margin-bottom: 16px; }
.related-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.related-card { display: flex; align-items: center; gap: 10px; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; color: var(--text); transition: border-color .2s; }
.related-card:hover { border-color: var(--card-color, var(--primary)); }
.related-icon { font-size: 24px; }
.related-title { font-size: 14px; font-weight: 600; }

/* article */
.article { padding: 40px 0 60px; }
.article h2 { font-size: 22px; margin: 24px 0 12px; }
.article h3 { font-size: 18px; margin: 20px 0 8px; }
.article p { color: var(--text-soft); margin-bottom: 12px; }
.article ul { padding-left: 20px; color: var(--text-soft); }
.article li { margin-bottom: 6px; }
.article code { background: var(--surface-2); padding: 2px 6px; border-radius: 4px; font-family: 'JetBrains Mono', monospace; font-size: 13px; }
.taxtable { width: 100%; border-collapse: collapse; margin: 16px 0; background: var(--surface); border-radius: 10px; overflow: hidden; }
.taxtable th, .taxtable td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.taxtable th { background: var(--surface-2); font-weight: 600; }

.article-intro { font-size: 17px; line-height: 1.65; color: var(--text-soft); margin-bottom: 28px; padding: 18px 22px; background: var(--surface); border-left: 4px solid var(--primary); border-radius: 8px; }
.article-related-quick { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 18px; background: var(--surface-2); border-radius: 10px; margin-bottom: 24px; font-size: 14px; }
.article-related-quick span { color: var(--text-mute); font-weight: 600; }
.article-related-quick a { padding: 4px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 100px; font-size: 13px; color: var(--text); text-decoration: none; }
.article-related-quick a:hover { border-color: var(--primary); color: var(--primary); }
.article table { width: 100%; border-collapse: collapse; margin: 14px 0; }
.article table th, .article table td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; font-size: 14px; }
.article table th { background: var(--surface-2); font-weight: 600; }
.faq { display: grid; gap: 10px; margin-top: 18px; }
.faq-item { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 22px; transition: border-color .15s; }
.faq-item:hover { border-color: var(--primary); }
.faq-item summary { font-weight: 600; cursor: pointer; list-style: none; position: relative; padding-right: 28px; }
.faq-item summary::after { content: '+'; position: absolute; right: 0; top: 0; font-size: 22px; color: var(--text-mute); transition: transform .2s; }
.faq-item[open] summary::after { content: '−'; }
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item p { margin-top: 10px; color: var(--text-soft); font-size: 14px; line-height: 1.6; }

/* ===== AI Chat ===== */
.ai-chat-fab { position: fixed; bottom: 20px; right: 20px; width: 56px; height: 56px; border-radius: 50%; background: var(--grad); color: #fff; border: 0; cursor: pointer; font-size: 24px; box-shadow: 0 6px 20px rgba(91,141,239,0.4); z-index: 999; display: grid; place-items: center; transition: transform .15s; }
.ai-chat-fab:hover { transform: scale(1.05); }
.ai-chat-badge { position: absolute; top: -6px; right: -6px; background: #ef4444; color: #fff; font-size: 10px; font-weight: 800; padding: 2px 6px; border-radius: 100px; }
.ai-chat-panel { position: fixed; bottom: 88px; right: 20px; width: 360px; max-width: calc(100vw - 40px); height: 480px; max-height: calc(100vh - 120px); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 8px 40px rgba(0,0,0,0.2); display: flex; flex-direction: column; z-index: 998; }
.ai-chat-panel[hidden] { display: none !important; }
.ai-chat-close { z-index: 1000; position: relative; line-height: 1; padding: 6px 14px; border-radius: 8px; min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; -webkit-tap-highlight-color: rgba(239,68,68,0.2); }
.ai-chat-close:hover, .ai-chat-close:active { background: var(--surface-2); color: var(--text); }
@media (max-width: 600px) {
  .ai-chat-panel { bottom: 0; right: 0; left: 0; top: 0; width: 100%; max-width: 100%; height: 100%; max-height: 100%; border-radius: 0; border: 0; }
  .ai-chat-fab { bottom: 16px; right: 16px; width: 52px; height: 52px; }
  .ai-chat-head { padding: 16px 18px; padding-top: max(16px, env(safe-area-inset-top)); }
  .ai-chat-close { font-size: 28px; min-width: 48px; min-height: 48px; }
  .ai-chat-form { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}
body.ai-chat-open { overflow: hidden; }
.ai-chat-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 700; }
.ai-chat-close { background: none; border: 0; font-size: 24px; cursor: pointer; color: var(--text-mute); padding: 0 6px; }
.ai-chat-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.ai-chat-msg { padding: 10px 14px; border-radius: 14px; max-width: 85%; font-size: 14px; line-height: 1.5; word-wrap: break-word; }
.ai-chat-msg-bot { background: var(--surface-2); color: var(--text); align-self: flex-start; border-bottom-left-radius: 4px; }
.ai-chat-msg-user { background: var(--grad); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.ai-chat-msg a { color: inherit; text-decoration: underline; }
.ai-chat-form { display: flex; gap: 6px; padding: 12px; border-top: 1px solid var(--border); }
.ai-chat-form input { flex: 1; padding: 10px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 100px; color: var(--text); font-size: 14px; }
.ai-chat-form button { width: 40px; height: 40px; border-radius: 50%; background: var(--grad); color: #fff; border: 0; cursor: pointer; font-size: 18px; font-weight: 700; }
