/* ========== MathTalking Theme ========== */
/* Adapted from terreflow/lyncius/assets/mvp-theme.css */

/* ── Variables ── */
:root {
  --text-main: #111;
  --text-sec: #444;
  --text-ter: #999;
  --border: #e5e7eb;
  --radius: 16px;
  --font-sans: 'Inter', 'Noto Sans SC', 'Noto Sans JP', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --color-primary: #1d4ed8;
  --color-primary-hover: #1e40af;
  --color-success: #059669;
  --color-error: #dc2626;
  --nav-height: 56px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-main);
  background: #f8fafc;
  padding-top: var(--nav-height);
  -webkit-font-smoothing: antialiased;
}

/* ── Global Nav ── */
.global-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: #fff;
  border-bottom: 1px solid var(--border);
  z-index: 100;
  display: flex;
  align-items: center;
}

.nav-inner {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.nav-slogan {
  font-size: 13px;
  color: var(--text-ter);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.lang-select {
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text-sec);
  cursor: pointer;
  outline: none;
}

.lang-select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.15);
}

/* ── Buttons ── */
.btn {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 16px;
  border-radius: 100px;
  border: none;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  min-width: 64px;
  text-align: center;
}

.btn-upgrade {
  background: var(--color-primary);
  color: #fff;
}
.btn-upgrade:hover {
  background: var(--color-primary-hover);
}

/* Function input row */
.func-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.func-add-btn {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--color-primary);
  color: #fff;
  font-size: 18px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.func-add-btn:hover { background: var(--color-primary-hover); }

.func-empty {
  font-size: 12px;
  color: var(--text-ter);
  text-align: center;
  padding: 16px 8px;
}

.func-item {
  padding-bottom: 4px;
  border-bottom: 1px solid #f3f4f6;
}
.func-item:last-of-type { border-bottom: none; }

.func-label {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Layout ── */
.wrap {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 24px;
}

.grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  grid-template-rows: auto auto;
  gap: 16px;
}

.left-panels {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  /* Height driven by grid row = graph card height. No viewport calc. */
}

.right-col {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-self: start;
}

/* Info / description card above graph */
.info-card {
  min-height: 150px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-sec);
}

.seo-content {
  grid-column: 1 / -1;
  grid-row: 2;
}

/* ── Cards ── */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.card-label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #aaa;
  margin-bottom: 12px;
}

/* ── Function Card ── */
.func-card {
  flex: 3 1 0;
  min-height: 400px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.func-list {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

/* Function row */
.func-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
}

.func-color-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.1s;
}
.func-color-dot:hover { transform: scale(1.2); }

.func-input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: #fafafa;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.func-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.1);
  background: #fff;
}
.func-input.has-error {
  border-color: var(--color-error);
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.1);
}

.func-preview {
  font-size: 12px;
  padding: 2px 0 0 22px;
  color: var(--text-sec);
  min-height: 20px;
}

.func-error {
  font-size: 11px;
  color: var(--color-error);
  padding: 2px 0 0 22px;
}

.func-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-ter);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.func-btn:hover {
  background: #f3f4f6;
  color: var(--text-sec);
}
.func-btn.hidden-state {
  opacity: 0.4;
}

/* ── Chat Card ── */
.chat-card {
  flex: 2 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-thread {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
  padding-right: 4px;
}

.chat-msg {
  font-size: 13px;
  line-height: 1.6;
  padding: 8px 12px;
  border-radius: 10px;
  max-width: 88%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.chat-msg.user {
  background: #f3f4f6;
  color: var(--text-main);
  align-self: flex-end;
  border-radius: 10px 10px 2px 10px;
}

.chat-msg.assistant {
  background: #f0f2ff;
  color: #333;
  align-self: flex-start;
  border: 1px solid #e0e4f8;
  border-radius: 10px 10px 10px 2px;
}

/* Chat streaming indicator */
.chat-msg.streaming:empty::after {
  content: '···';
  animation: blink 1s steps(3) infinite;
  color: var(--text-ter);
  font-size: 16px;
  letter-spacing: 2px;
}
@keyframes blink {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 1; }
}

/* KaTeX in chat */
.chat-msg .katex { font-size: 1em; }
.chat-msg .katex-display { margin: 8px 0; overflow-x: auto; }

.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-input {
  flex: 1;
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 100px;
  background: #f9fafb;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chat-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.1);
  background: #fff;
}

.chat-send-btn {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 100px;
  border: none;
  background: #1f2937;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.chat-send-btn:hover { background: #111827; }

/* ── Graph Card ── */
.graph-card {
  padding: 0;
  overflow: hidden;
}

.graph-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  min-height: 56px;
  flex-shrink: 0;
}

.graph-header-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-ter);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

/* Function pills in graph header */
.graph-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
.graph-pills::-webkit-scrollbar { display: none; }

.graph-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 6px;
  border: 1px solid var(--border);
  border-radius: 100px;
  background: #fff;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-main);
  white-space: nowrap;
  transition: opacity 0.15s, background 0.15s;
  flex-shrink: 0;
}
.graph-pill:hover { background: #f9fafb; }
.graph-pill.pill-hidden { opacity: 0.35; }

.pill-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.graph-container {
  position: relative;
  aspect-ratio: 4 / 3;
  width: 100%;
  background: #fff;
}

#graphCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* Floating toolbar */
.graph-toolbar {
  position: absolute;
  bottom: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 5;
}

.toolbar-btn {
  width: 32px;
  height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.52);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  color: var(--text-main);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}
.toolbar-btn:hover {
  background: rgba(255, 255, 255, 0.92);
}

/* ── SEO Content ── */
.seo-content {
  padding: 16px 4px;
}
.seo-content h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 8px;
}
.seo-content p {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-sec);
  margin-bottom: 16px;
}

/* ── Ad Slots ── */
.ad-slot {
  min-height: 90px;
  background: #fafafa;
  border: 1px dashed #ddd;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ad-label {
  font-size: 11px;
  color: #ccc;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ── Color Picker Popover ── */
.color-picker {
  position: absolute;
  display: grid;
  grid-template-columns: repeat(4, 24px);
  gap: 4px;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  z-index: 20;
}
.color-picker-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.1s;
}
.color-picker-swatch:hover { transform: scale(1.15); }
.color-picker-swatch.active { border-color: var(--text-main); }

/* ========== Responsive ========== */

/* Tablet: single column */
@media (max-width: 1100px) {
  .grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }
  .left-panels {
    display: contents;
  }
  .right-col {
    display: contents;
  }

  /* Reorder: info first, then graph, then func list, then chat, then SEO */
  .info-card    { order: 0; }
  .graph-card   { order: 1; }
  .func-card    { order: 2; }
  .chat-card    { order: 3; min-height: 300px; max-height: 400px; }
  .seo-content  { order: 4; }

  .chat-thread { min-height: 200px; }
}

/* Small tablet */
@media (max-width: 768px) {
  .nav-slogan { display: none; }
  .wrap { padding: 16px; }
  .card { padding: 16px; }
  .nav-inner { padding: 0 16px; }
  .chat-card { max-height: 360px; }
  .chat-thread { min-height: 180px; max-height: 220px; }
}

/* Mobile */
@media (max-width: 480px) {
  :root { --nav-height: 48px; }
  .wrap { padding: 12px; }
  .card { padding: 14px; }
  .grid { gap: 12px; }
  .graph-container { aspect-ratio: 4 / 5; }
  .nav-logo { font-size: 16px; }

  .btn-upgrade { display: none; }
  .nav-slogan { display: none; }

  .toolbar-btn { width: 28px; height: 28px; font-size: 14px; }

  .func-input { font-size: 12px; padding: 5px 8px; }
  .chat-input { font-size: 12px; padding: 7px 12px; }
  .chat-msg { font-size: 12px; padding: 6px 10px; }

  .seo-content h2 { font-size: 16px; }
  .seo-content p { font-size: 13px; }
}

/* ── Scrollbar ── */
.func-list::-webkit-scrollbar,
.chat-thread::-webkit-scrollbar {
  width: 4px;
}
.func-list::-webkit-scrollbar-thumb,
.chat-thread::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 2px;
}
