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

:root {
  --bg: #12121f;
  --accent: #e8a87c;
  --correct: #7bc67e;
  --input-border: rgba(255,255,255,0.18);
  --axis: rgba(255,255,255,0.15);
  --text-primary: #ffffff;
  --text-secondary: rgba(255,255,255,0.45);
  --ad-bg: rgba(255,255,255,0.03);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: system-ui, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 100px;
}

#app {
  width: 100%;
  max-width: 480px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ── Tabs ── */
#tabs {
  display: flex;
  border-bottom: 1px solid var(--input-border);
}

.tab {
  flex: 1;
  padding: 14px 0;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-family: system-ui, sans-serif;
  cursor: pointer;
  transition: color 0.2s, border-bottom 0.2s;
  border-bottom: 2px solid transparent;
}

.tab.active {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
}

/* ── Title block ── */
#title-block {
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--input-border);
}

#title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

#math-notation {
  font-family: Georgia, serif;
  font-style: italic;
  font-size: 32px;
  color: var(--text-primary);
}

#tier-badge {
  font-size: 12px;
  color: var(--text-secondary);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--input-border);
  border-radius: 20px;
  padding: 3px 10px;
}

/* ── Graph ── */
#graph-container {
  padding: 8px 20px 0;
  position: relative;
}

#graph-svg {
  width: 100%;
  display: block;
  overflow: visible;
}

/* ── Inputs overlaid on SVG ── */
.node-input-group {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translateX(-50%);
  pointer-events: auto;
}

.word-label {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
  margin-bottom: 2px;
}

.word-input {
  width: 72px;
  min-height: 44px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--input-border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 13px;
  text-align: center;
  font-family: system-ui, sans-serif;
  outline: none;
  transition: border-color 0.2s;
  padding: 0 4px;
}

.word-input:focus {
  border-color: rgba(255,255,255,0.4);
}

.word-input.correct {
  border-color: var(--correct);
  color: var(--correct);
}

.word-input.wrong {
  border-color: #e87c7c;
  animation: shake 0.3s ease;
}

.hint-btn {
  margin-top: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(255,255,255,0.07);
  border: 1px solid var(--input-border);
  color: var(--text-secondary);
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: system-ui, sans-serif;
  transition: background 0.15s;
  min-height: 22px;
}

.hint-btn:hover {
  background: rgba(255,255,255,0.13);
}

.deriv-label {
  font-size: 11px;
  font-style: italic;
  color: var(--text-secondary);
  margin-top: 3px;
}

@keyframes shake {
  0%   { transform: translateX(-50%) translateX(0); }
  20%  { transform: translateX(-50%) translateX(-5px); }
  40%  { transform: translateX(-50%) translateX(5px); }
  60%  { transform: translateX(-50%) translateX(-4px); }
  80%  { transform: translateX(-50%) translateX(4px); }
  100% { transform: translateX(-50%) translateX(0); }
}

/* ── Description ── */
#desc-section {
  padding: 16px 20px;
  border-top: 1px solid var(--input-border);
  margin-top: 8px;
}

#desc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

#desc-header span {
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

#desc-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px;
  display: flex;
  align-items: center;
}

#desc-toggle:hover { color: var(--text-primary); }

#desc-body {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-secondary);
}

#desc-body strong {
  color: var(--text-primary);
  font-weight: 600;
}

.desc-phrase {
  opacity: 0;
  transition: opacity 0.4s ease;
}

.desc-phrase.visible {
  opacity: 1;
}

/* ── No puzzle ── */
#no-puzzle {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 16px;
}

/* ── Ad banner ── */
#ad-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 90px;
  background: var(--ad-bg);
  border-top: 1px solid rgba(255,255,255,0.07);
  display: flex;
  align-items: center;
  justify-content: center;
}

#ad-banner span {
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

#reset-btn {
  position: absolute;
  right: 12px;
  bottom: 12px;
  background: none;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 16px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

#reset-btn:hover {
  color: var(--text-primary);
  border-color: rgba(255,255,255,0.35);
}

@media (max-width: 480px) {
  #math-notation { font-size: 22px; }
  #title-block   { padding: 10px 16px 8px; }
  .tab           { padding: 10px 0; }
}

/* ── Toast ── */
#toast {
  position: fixed;
  top: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  background: var(--accent);
  color: #12121f;
  font-size: 15px;
  font-weight: 700;
  padding: 10px 22px;
  border-radius: 24px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 200;
  white-space: nowrap;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Modal ── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#modal {
  background: #1c1c2e;
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 28px 24px;
  width: min(90vw, 360px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#modal h2 {
  font-size: 22px;
  color: var(--accent);
  text-align: center;
}

#modal-date {
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}

#share-text {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--input-border);
  border-radius: 6px;
  padding: 12px;
  font-family: system-ui, monospace;
  font-size: 13px;
  white-space: pre;
  color: var(--text-primary);
  line-height: 1.8;
}

#copy-btn, #close-modal {
  padding: 11px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-family: system-ui, sans-serif;
}

#copy-btn {
  background: var(--accent);
  color: #12121f;
  font-weight: 600;
}

#close-modal {
  background: rgba(255,255,255,0.07);
  color: var(--text-primary);
}

#copy-btn:hover { opacity: 0.9; }
#close-modal:hover { background: rgba(255,255,255,0.12); }
