:root {
  --paper: #f7f2e8;
  --paper-2: #f3ead9;
  --panel: #fffdf8;
  --panel-soft: rgba(255, 253, 248, .82);
  --ink: #172033;
  --muted: #667085;
  --line: #ddd3c2;
  --accent: #1f6f5f;
  --accent-blue: #2f7fd3;
  --soft-blue: #eef6ff;
  --soft-green: #e7f1ec;
  --soft-gold: #f3ead9;
  --danger: #b42318;
  --success: #1f7a4d;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font: 15px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, "Noto Sans SC", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
  gap: 18px;
  max-width: 1520px;
  margin: 0 auto;
  padding: 18px clamp(14px, 3vw, 38px) 54px;
}

.tools-panel {
  position: sticky;
  top: 12px;
  align-self: start;
  max-height: calc(100vh - 24px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 2px 12px rgba(23, 32, 51, .04);
  padding: 14px;
}

.top-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.top-links a {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent);
  background: rgba(255, 255, 255, .56);
  text-decoration: none;
  font-size: 12px;
  font-weight: 800;
  padding: 0 10px;
}

.top-links a:hover {
  border-color: var(--accent);
}

.product-head {
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(30px, 4vw, 44px);
  line-height: 1.02;
  font-weight: 600;
}

.product-head p:last-child,
.positioning-card p,
.focus-head p,
.phrase-detail p,
.formula-item p,
.word-part-card p {
  color: var(--muted);
}

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 14px;
}

.mode-tabs button,
.practice-controls button,
.primary-command,
.secondary-command,
.icon-command {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  padding: 0 12px;
}

.mode-tabs button.active,
.practice-controls button.active,
.primary-command {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.search-panel {
  position: relative;
  margin-top: 14px;
}

.search-panel label,
.practice-card label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

#expression-search,
#practice-input {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  padding: 0 15px;
  transition: border-color .18s ease, box-shadow .18s ease;
}

#expression-search:focus,
#practice-input:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 4px rgba(47, 127, 211, .14);
}

#practice-input.has-error {
  border-color: var(--danger);
  box-shadow: 0 0 0 4px rgba(180, 35, 24, .12);
}

.suggestions {
  position: absolute;
  inset: auto 0 auto 0;
  top: calc(100% + 8px);
  z-index: 12;
  display: grid;
  gap: 6px;
  max-height: 390px;
  overflow: auto;
  border: 1px solid rgba(49, 95, 143, .22);
  border-radius: 8px;
  background: rgba(255, 253, 248, .98);
  box-shadow: 0 18px 36px rgba(23, 32, 51, .16);
  padding: 8px;
  animation: fadeDown .18s ease-out both;
}

.suggestions[hidden] {
  display: none;
}

@keyframes fadeDown {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.suggestion {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #fff;
  text-align: left;
  padding: 9px 11px;
}

.suggestion-group {
  display: grid;
  gap: 6px;
}

.suggestion-group + .suggestion-group {
  margin-top: 4px;
  border-top: 1px solid rgba(221, 211, 194, .72);
  padding-top: 8px;
}

.suggestion-group h3 {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.suggestion:hover,
.suggestion.active,
.suggestion:focus-visible {
  outline: none;
  border-color: rgba(47, 127, 211, .48);
  background: var(--soft-blue);
}

.suggestion span {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.suggestion strong {
  overflow-wrap: anywhere;
  font-size: 16px;
}

.suggestion em,
.suggestion small {
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
}

.suggestion small {
  flex: 0 0 auto;
  max-width: 42%;
  text-align: right;
}

mark {
  border-radius: 4px;
  background: #d9ecff;
  color: #174c80;
  padding: 0 2px;
}

.empty-suggestion {
  margin: 0;
  color: var(--muted);
  padding: 12px;
}

.suggestion-hint {
  margin: 8px 0 0;
  border: 1px solid rgba(49, 95, 143, .18);
  border-radius: 8px;
  background: #f4f8fb;
  color: #46586a;
  font-size: 12px;
  line-height: 1.35;
  padding: 9px 10px;
}

.tool-section {
  margin-top: 15px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-head h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
  line-height: 1.1;
  font-weight: 600;
}

.section-head span {
  color: var(--muted);
  font-size: 12px;
}

.verb-list,
.word-part-list {
  display: grid;
  gap: 8px;
}

.verb-item,
.word-part-item {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
  padding: 10px 12px;
  transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}

.verb-item:hover,
.word-part-item:hover,
.verb-item.active,
.word-part-item.active {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(47, 127, 211, .10);
}

.verb-item.active,
.word-part-item.active {
  background: var(--soft-blue);
}

.verb-item strong,
.word-part-item strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  line-height: 1;
}

.verb-item span,
.word-part-item span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.builder-area {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.positioning-card,
.focus-card,
.expression-map-card,
.detail-card,
.formula-card,
.roots-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 2px 12px rgba(23, 32, 51, .04);
  padding: clamp(15px, 2.2vw, 22px);
}

.positioning-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: linear-gradient(180deg, var(--panel) 0%, #fbf6eb 100%);
}

.positioning-card h2,
.focus-head h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(28px, 4.2vw, 46px);
  line-height: 1.04;
  font-weight: 600;
}

.positioning-card p {
  max-width: 520px;
  margin: 0;
}

.focus-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.icon-command[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--soft-green);
  color: var(--accent);
}

.phrase-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-top: 14px;
}

.phrase-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 76px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  padding: 11px 12px;
  transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}

.phrase-chip:hover,
.phrase-chip.active {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(47, 127, 211, .10);
}

.phrase-chip.active {
  background: var(--soft-blue);
  animation: selectedPulse .32s ease-out;
}

@keyframes selectedPulse {
  45% {
    transform: scale(.985);
  }
}

.phrase-chip span {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.phrase-chip strong {
  overflow-wrap: anywhere;
  font-size: 17px;
  line-height: 1.18;
}

.phrase-chip em {
  color: var(--muted);
  font-style: normal;
  font-size: 13px;
}

.phrase-chip small {
  flex: none;
  border-radius: 999px;
  background: var(--soft-gold);
  color: var(--ink);
  font-size: 11px;
  font-weight: 900;
  padding: 5px 7px;
}

.map-stage {
  position: relative;
  min-height: 220px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(rgba(49, 95, 143, .05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(49, 95, 143, .05) 1px, transparent 1px),
    #fffdf8;
  background-size: 28px 28px;
  padding: 14px;
}

.map-lines {
  position: absolute;
  inset: 14px;
  width: calc(100% - 28px);
  height: calc(100% - 28px);
  pointer-events: none;
  z-index: 1;
}

.map-line {
  fill: none;
  stroke: var(--accent-blue);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 420;
  stroke-dashoffset: 420;
  animation: lineGrow .46s ease-out forwards;
  filter: drop-shadow(0 3px 5px rgba(47, 127, 211, .14));
}

@keyframes lineGrow {
  to {
    stroke-dashoffset: 0;
  }
}

.map-chain {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: .72fr 1fr 1.2fr 1.2fr;
  gap: 34px;
  align-items: stretch;
}

.map-node {
  display: grid;
  align-content: start;
  gap: 7px;
  min-height: 142px;
  border: 1px solid rgba(49, 95, 143, .24);
  border-radius: 8px;
  background: rgba(255, 253, 248, .96);
  padding: 12px;
  animation: cardIn .24s ease-out both;
}

.root-node {
  background: linear-gradient(135deg, #2f7fd3 0%, #1f6fbe 100%);
  color: #fff;
}

.map-node span {
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.root-node span,
.root-node em {
  color: rgba(255, 255, 255, .78);
}

.map-node strong {
  overflow-wrap: anywhere;
  font-size: 18px;
  line-height: 1.2;
}

.map-node em {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-style: normal;
  font-size: 13px;
  line-height: 1.3;
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateX(-12px) scale(.96);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, .95fr);
  gap: 14px;
}

.selected-phrase {
  display: grid;
  gap: 2px;
  margin-bottom: 10px;
}

.selected-phrase strong {
  font-size: 28px;
  line-height: 1.1;
}

.selected-phrase span {
  color: var(--muted);
  font-size: 16px;
}

.patterns,
.conversation {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.pattern-row,
.conversation div {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  column-gap: 10px;
  row-gap: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .55);
  padding: 10px;
}

.pattern-row {
  width: 100%;
  color: var(--ink);
  text-align: left;
}

.pattern-row:hover,
.pattern-row:focus-visible {
  outline: none;
  border-color: var(--accent-blue);
  background: var(--soft-blue);
}

.pattern-row span,
.conversation span {
  color: var(--accent-blue);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.pattern-row strong,
.conversation strong {
  overflow-wrap: anywhere;
}

.pattern-row em,
.conversation em {
  grid-column: 2;
  color: var(--muted);
  font-style: normal;
}

.practice-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.practice-card {
  display: grid;
  gap: 10px;
}

.practice-current {
  display: grid;
  gap: 5px;
  border: 1px solid rgba(49, 95, 143, .22);
  border-radius: 8px;
  background: var(--soft-blue);
  padding: 15px;
}

.practice-current span {
  color: var(--accent-blue);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.practice-current strong {
  overflow-wrap: anywhere;
  font-size: clamp(26px, 4vw, 38px);
  line-height: 1.12;
}

.practice-current em {
  color: #46586a;
  font-style: normal;
}

.practice-progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(49, 95, 143, .12);
}

.practice-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent));
  transition: width .2s ease;
}

.practice-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.practice-stats span {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .6);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  padding: 8px;
}

.practice-stats strong {
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
}

.practice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.practice-feedback {
  min-height: 24px;
  color: var(--muted);
}

.practice-feedback p {
  margin: 0;
}

.practice-feedback.correct {
  color: var(--success);
  font-weight: 800;
}

.practice-feedback.wrong {
  color: var(--danger);
  font-weight: 800;
}

.correction-box {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 5px 8px;
  margin-top: 8px;
  border: 1px solid rgba(180, 35, 24, .18);
  border-radius: 8px;
  background: #fff7f5;
  color: var(--ink);
  font-weight: 400;
  padding: 10px;
}

.correction-box span {
  color: var(--danger);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.correction-box strong {
  overflow-wrap: anywhere;
  font-weight: 800;
}

.error-mark {
  border-radius: 4px;
  background: #ffd9d5;
  color: #8a1f14;
  padding: 0 2px;
}

.formula-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.formula-item {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .52);
  padding: 12px;
}

.formula-item h3,
.word-part-card h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
  line-height: 1.1;
}

.formula-item p {
  margin: 0;
}

.formula-item div,
.word-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.formula-item span,
.word-list span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--soft-gold);
  font-size: 12px;
  padding: 0 9px;
}

.formula-item small {
  color: var(--accent);
  font-weight: 800;
}

.word-part-detail {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.word-part-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .52);
  padding: 12px;
}

.word-part-card.active {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(47, 127, 211, .10);
}

.word-part-card div:first-child span {
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.word-part-card p {
  margin: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 20;
  opacity: 0;
  transform: translate(-50%, 14px);
  pointer-events: none;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  padding: 9px 14px;
  transition: opacity .18s ease, transform .18s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *:before,
  *:after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media (max-width: 1100px) {
  .app-shell,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .tools-panel {
    position: static;
    max-height: none;
  }

  .verb-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .positioning-card,
  .focus-head {
    align-items: stretch;
    flex-direction: column;
  }

  .phrase-grid,
  .formula-list,
  .word-part-detail {
    grid-template-columns: 1fr;
  }

  .map-chain {
    grid-template-columns: 1fr;
    gap: 28px;
  }

  .map-node {
    min-height: 108px;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding: 12px 10px 42px;
  }

  .mode-tabs,
  .verb-list,
  .practice-stats {
    grid-template-columns: 1fr;
  }

  .suggestions {
    position: relative;
    top: 8px;
  }

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

  .suggestion small {
    max-width: none;
    text-align: left;
  }

  .pattern-row,
  .conversation div {
    grid-template-columns: 1fr;
  }

  .pattern-row em,
  .conversation em {
    grid-column: auto;
  }
}
