:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #69737d;
  --panel: #ffffff;
  --soft: #f7f3eb;
  --line: #e7dcc8;
  --accent: #2563eb;
  --accent-2: #b89045;
  --accent-3: #24344d;
  --dark: #111927;
  --dark-2: #20314a;
  --gold: #c7a45a;
  --warn: #a86f13;
  --radius: 8px;
  --shadow: 0 22px 52px rgba(23, 33, 43, 0.12);
  --panel-shadow: 0 1px 0 rgba(255, 255, 255, 0.78) inset, 0 18px 42px rgba(29, 35, 45, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 14% 0%, rgba(47, 111, 126, 0.12), transparent 30%),
    radial-gradient(circle at 88% 8%, rgba(184, 144, 69, 0.14), transparent 28%),
    linear-gradient(90deg, rgba(36, 52, 77, 0.035) 1px, transparent 1px),
    linear-gradient(0deg, rgba(36, 52, 77, 0.035) 1px, transparent 1px),
    #faf7ef;
  background-size: auto, auto, 34px 34px, 34px 34px, auto;
}

body.is-loading {
  overflow: hidden;
}

.intro-loader {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 46%, rgba(40, 100, 255, 0.28), transparent 22%),
    radial-gradient(circle at 70% 68%, rgba(14, 165, 233, 0.18), transparent 24%),
    radial-gradient(circle at 24% 24%, rgba(199, 164, 90, 0.11), transparent 22%),
    linear-gradient(180deg, #02040b 0%, #070b16 48%, #03050b 100%);
  color: #fff;
  transition: opacity 520ms ease, visibility 520ms ease;
}

.loading-stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.loading-stage::before {
  content: "";
  position: absolute;
  width: min(560px, 78vw);
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.1), transparent 18%),
    radial-gradient(circle, rgba(37, 99, 235, 0.24), transparent 54%);
  filter: blur(18px);
  opacity: 0;
  animation: loaderGlow 3s ease both;
}

.loading-ring {
  position: absolute;
  border-radius: 50%;
  opacity: 0;
  animation: ringLoad 3s ease both, ringSpin 9s linear infinite;
}

.ring-large {
  width: min(430px, 68vw);
  aspect-ratio: 1;
  border: 1px solid rgba(255, 224, 154, 0.34);
  border-top-color: rgba(125, 211, 252, 0.95);
  box-shadow: 0 0 38px rgba(37, 99, 235, 0.16), inset 0 0 38px rgba(255, 224, 154, 0.08);
}

.ring-small {
  width: min(300px, 52vw);
  aspect-ratio: 1;
  border: 1px dashed rgba(125, 211, 252, 0.38);
  border-right-color: rgba(255, 224, 154, 0.92);
  animation-direction: normal, reverse;
}

.loading-symbol {
  position: absolute;
  display: grid;
  place-items: center;
  min-width: 50px;
  height: 50px;
  border-radius: 16px;
  color: rgba(244, 248, 255, 0.92);
  font-weight: 950;
  background: rgba(255, 255, 255, 0.075);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(10px);
  opacity: 0;
  animation: symbolLoading 3s ease both;
}

.symbol-one { left: 26%; top: 28%; animation-delay: 0.1s; }
.symbol-two { right: 27%; top: 29%; animation-delay: 0.28s; }
.symbol-three { left: 31%; bottom: 27%; animation-delay: 0.46s; }
.symbol-four { right: 31%; bottom: 27%; animation-delay: 0.64s; }

.intro-loader::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 18% 28%, #fff 0 1px, transparent 1.6px),
    radial-gradient(circle at 62% 18%, #fff 0 1px, transparent 1.7px),
    radial-gradient(circle at 82% 38%, #fff 0 1px, transparent 1.6px),
    radial-gradient(circle at 32% 72%, #fff 0 1px, transparent 1.7px),
    radial-gradient(circle at 74% 76%, #fff 0 1px, transparent 1.6px);
  background-size: 210px 170px, 260px 210px, 190px 230px, 250px 190px, 230px 250px;
  opacity: 0.42;
  animation: starDrift 11s linear infinite;
}

.intro-loader::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 0 44%, rgba(0, 0, 0, 0.34) 78%);
  pointer-events: none;
}

.intro-loader.is-done {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.intro-logo {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 8px;
  text-align: center;
  transform: translateY(25vh);
  animation: introLogo 950ms cubic-bezier(.2, .8, .2, 1) both;
}

.intro-logo::before {
  content: "";
  position: absolute;
  inset: -38px -58px;
  z-index: -1;
  border-radius: 999px;
  background:
    linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent),
    radial-gradient(circle, rgba(14, 165, 233, 0.18), transparent 64%);
  filter: blur(2px);
  opacity: 0;
  animation: logoAura 3s ease both;
}

.intro-logo p,
.intro-logo h1,
.intro-equation {
  margin: 0;
}

.intro-logo p {
  color: var(--gold);
  font-size: clamp(1rem, 2.1vw, 1.45rem);
  font-weight: 900;
  letter-spacing: 0.38em;
  text-transform: uppercase;
}

.intro-logo h1 {
  font-size: clamp(3rem, 8vw, 7.8rem);
  line-height: 0.95;
  letter-spacing: 0;
  text-shadow: 0 26px 54px rgba(37, 99, 235, 0.46), 0 0 24px rgba(14, 165, 233, 0.18);
}

.intro-equation {
  color: rgba(226, 239, 255, 0.78);
  font-size: clamp(0.88rem, 1.7vw, 1.1rem);
  font-weight: 800;
}

.intro-progress {
  position: absolute;
  left: 50%;
  bottom: 10%;
  width: min(560px, 62vw);
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.11);
  transform: translateX(-50%);
  box-shadow: 0 0 28px rgba(37, 99, 235, 0.18);
}

.intro-progress span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #0ea5e9, var(--gold));
  transform-origin: left;
  animation: introProgress 3s ease forwards;
}

@keyframes introLogo {
  from {
    opacity: 0;
    transform: translateY(calc(25vh + 18px)) scale(0.94);
  }
  to {
    opacity: 1;
    transform: translateY(25vh) scale(1);
  }
}

@keyframes introProgress {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@keyframes starDrift {
  to { transform: translate3d(-70px, 30px, 0); }
}

@keyframes logoAura {
  0%, 26% { opacity: 0; transform: scaleX(0.6); }
  58% { opacity: 1; transform: scaleX(1); }
  100% { opacity: 0.7; transform: scaleX(1.08); }
}

@keyframes loaderGlow {
  0% { opacity: 0; transform: scale(0.72); }
  45% { opacity: 1; transform: scale(1); }
  100% { opacity: 0.72; transform: scale(1.08); }
}

@keyframes ringLoad {
  0% { opacity: 0; transform: scale(0.78); filter: blur(8px); }
  42% { opacity: 1; transform: scale(1); filter: blur(0); }
  100% { opacity: 0.72; transform: scale(1.02); filter: blur(0); }
}

@keyframes ringSpin {
  to { rotate: 360deg; }
}

@keyframes symbolLoading {
  0% { opacity: 0; transform: translateY(18px) scale(0.78); filter: blur(8px); }
  42% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
  100% { opacity: 0.76; transform: translateY(-14px) scale(0.96); filter: blur(0); }
}

@media (max-width: 760px) {
  .loading-symbol {
    min-width: 42px;
    height: 42px;
    font-size: 0.92rem;
  }

  .symbol-one { left: 10%; top: 31%; }
  .symbol-two { right: 10%; top: 32%; }
  .symbol-three { left: 16%; bottom: 27%; }
  .symbol-four { right: 16%; bottom: 27%; }

  .intro-logo h1 {
    font-size: clamp(2.6rem, 13vw, 4.5rem);
  }
}

#particleCanvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  gap: 20px;
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 76px minmax(0, 1fr);
}

.solver-pane,
.library-pane,
.tab-content {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(255, 252, 247, 0.9));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(10px);
}

.sidebar {
  position: sticky;
  top: 24px;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: calc(100vh - 48px);
  padding: 18px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.055), transparent 34%),
    linear-gradient(145deg, #030303, #0d0d0f 56%, #171717);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.34);
  color: #eef5f7;
  transition: width 180ms ease, min-height 180ms ease, padding 180ms ease;
}

.sidebar-toggle {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 1rem;
  font-weight: 900;
}

.sidebar::before {
  content: "∑  π  √  x²  f(x)";
  position: absolute;
  right: -26px;
  top: 96px;
  color: rgba(255, 255, 255, 0.06);
  font-size: 3.8rem;
  font-weight: 900;
  line-height: 1.2;
  writing-mode: vertical-rl;
  pointer-events: none;
}

.workspace {
  display: grid;
  gap: 24px;
  min-width: 0;
}

.solver-pane {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
}

.library-pane {
  overflow: hidden;
  padding: 18px;
}

.tab-content {
  min-height: 0;
  padding: 18px;
}

.is-hidden {
  display: none;
}

.brand-block h1 {
  position: relative;
  font-size: 2.15rem;
  color: #fff;
  text-align: center;
}

.brand-block {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 8px 0 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.11);
  text-align: center;
}

.brand-subtitle {
  margin: 0;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.tab-nav {
  display: grid;
  gap: 8px;
}

.tab-button {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.055);
  color: #dce8ec;
  padding: 10px 12px;
  text-align: left;
  font-weight: 850;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.tab-button.is-active {
  border-color: rgba(96, 165, 250, 0.45);
  background: linear-gradient(90deg, #2563eb, #0ea5e9);
  color: #fff;
  box-shadow: 0 8px 22px rgba(37, 99, 235, 0.26);
}

.tab-button:hover {
  border-color: rgba(199, 164, 90, 0.38);
  background: rgba(255, 255, 255, 0.1);
  transform: translateX(2px);
}

.side-note {
  margin-top: auto;
  border: 1px solid rgba(199, 164, 90, 0.2);
  border-radius: 6px;
  background: rgba(199, 164, 90, 0.09);
  color: #f3e7c0;
  padding: 12px;
  font-size: 0.86rem;
  font-weight: 750;
  line-height: 1.4;
}

.app-shell.sidebar-collapsed .sidebar {
  padding: 14px 10px;
}

.app-shell.sidebar-collapsed .brand-block h1,
.app-shell.sidebar-collapsed .brand-subtitle {
  display: none;
}

.app-shell.sidebar-collapsed .brand-block {
  min-height: 44px;
  padding: 0 0 12px;
}

.app-shell.sidebar-collapsed .tab-nav {
  gap: 7px;
}

.app-shell.sidebar-collapsed .tab-button {
  min-height: 42px;
  padding: 8px 6px;
  overflow: hidden;
  text-align: center;
  font-size: 0;
}

.app-shell.sidebar-collapsed .tab-button::after {
  content: attr(data-icon);
  font-size: 1rem;
  font-weight: 900;
}

.topbar,
.library-header,
.toolbar,
.tool-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar,
.library-header {
  justify-content: space-between;
}

.eyebrow,
.section-label {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(2rem, 4vw, 4.2rem);
  line-height: 0.95;
}

h2 {
  font-size: 1.22rem;
}

.status-pill {
  min-width: 92px;
  border: 1px solid rgba(37, 99, 235, 0.24);
  border-radius: 999px;
  background: #eff6ff;
  color: var(--accent);
  padding: 9px 12px;
  text-align: center;
  font-weight: 800;
}

.input-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

.chat-composer {
  align-items: end;
}

.question-box {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 10px;
}

.question-box label,
.tool-row label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 750;
}

.prompt-frame {
  display: flex;
  width: 100%;
  min-height: 142px;
  flex-direction: column;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(47, 111, 126, 0.032) 1px, transparent 1px),
    linear-gradient(0deg, rgba(47, 111, 126, 0.032) 1px, transparent 1px),
    #fff;
  background-size: 28px 28px;
  padding: 14px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.prompt-frame:focus-within,
.prompt-frame.is-dragging {
  border-color: rgba(37, 99, 235, 0.5);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

textarea {
  flex: 1;
  width: 100%;
  min-height: 118px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(47, 111, 126, 0.032) 1px, transparent 1px),
    linear-gradient(0deg, rgba(47, 111, 126, 0.032) 1px, transparent 1px),
    #fff;
  background-size: 28px 28px;
  color: var(--ink);
  padding: 18px;
  outline: none;
  line-height: 1.6;
}

#questionInput {
  min-height: 82px;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
  resize: none;
}

textarea:focus,
input:focus {
  border-color: rgba(37, 99, 235, 0.5);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

#questionInput:focus {
  box-shadow: none;
}

.toolbar {
  flex-wrap: wrap;
}

.toolbar button,
.file-action {
  min-height: 42px;
  border: 1px solid rgba(16, 24, 32, 0.1);
  border-radius: 6px;
  background: linear-gradient(135deg, #111827, #2563eb);
  color: #fff;
  padding: 10px 16px;
  font-weight: 850;
  box-shadow: 0 10px 22px rgba(11, 23, 32, 0.12);
}

.toolbar button:nth-child(2),
.file-action {
  background: #fff;
  color: var(--ink);
}

.attach-plus {
  display: inline-grid;
  place-items: center;
  width: 42px;
  min-width: 42px;
  height: 42px;
  padding: 0;
  font-size: 1.45rem;
  line-height: 1;
}

.prompt-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.composer-hint {
  align-self: center;
  margin: 0;
}

#imageInput {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.drop-copy {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.image-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 118px));
  gap: 8px;
}

.image-item {
  position: relative;
  overflow: hidden;
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.image-item img {
  display: block;
  width: 100%;
  height: 92px;
  object-fit: cover;
}

.image-remove {
  position: absolute;
  top: 5px;
  right: 5px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.14);
}

.image-status {
  padding: 6px 7px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.25;
}

.composer-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.toolbar button:hover,
.file-action:hover {
  border-color: rgba(199, 164, 90, 0.42);
  transform: translateY(-1px);
}

.chat-window {
  min-height: 300px;
  max-height: 380px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(47, 111, 126, 0.025) 1px, transparent 1px),
    linear-gradient(0deg, rgba(47, 111, 126, 0.025) 1px, transparent 1px),
    rgba(255, 255, 255, 0.72);
  background-size: 28px 28px;
  padding: 16px;
}

.chat-stream {
  display: flex;
  min-height: 100%;
  flex-direction: column;
  justify-content: flex-end;
  gap: 12px;
}

.message {
  width: fit-content;
  max-width: min(760px, 88%);
  border: 1px solid var(--line);
  background: #fff;
  padding: 13px 14px;
  line-height: 1.5;
  box-shadow: 0 8px 20px rgba(20, 20, 20, 0.04);
}

.user-message {
  align-self: flex-end;
  border: 1px solid rgba(37, 99, 235, 0.18);
  border-radius: 14px 14px 4px 14px;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  color: #fff;
  font-weight: 750;
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.16);
}

.assistant-message {
  align-self: flex-start;
  border-radius: 14px 14px 14px 4px;
  border-color: rgba(47, 111, 126, 0.22);
  background:
    linear-gradient(135deg, rgba(47, 111, 126, 0.075), rgba(199, 164, 90, 0.11)),
    #fffdfb;
}

#answerText {
  font-size: 1.28rem;
  font-weight: 850;
  line-height: 1.35;
  word-break: break-word;
}

#stepsList {
  margin: 10px 0 0;
  padding-left: 22px;
  color: var(--muted);
  line-height: 1.55;
}

#formulaSearch,
#numberTool,
#toolSearch,
.tool-input,
.tool-select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

.library-header {
  align-items: start;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.library-header input {
  max-width: 220px;
}

.tool-row {
  flex-wrap: wrap;
  align-items: end;
  margin-bottom: 14px;
  padding: 12px;
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(47, 111, 126, 0.055), transparent),
    var(--soft);
  border: 1px solid var(--line);
}

.tool-row label {
  flex: 0 0 190px;
}

.mini-result {
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 750;
  line-height: 1.45;
}

.formula-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  padding-right: 4px;
}

.formula-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 14px;
  box-shadow: 0 10px 26px rgba(13, 32, 43, 0.045);
}

.formula-card h3 {
  margin: 0 0 7px;
  font-size: 0.98rem;
}

.formula-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.tag {
  display: inline-flex;
  margin-top: 9px;
  border-radius: 999px;
  background: rgba(199, 164, 90, 0.14);
  color: var(--accent);
  padding: 4px 8px;
  font-size: 0.72rem;
  font-weight: 850;
}

.tool-result {
  min-height: 180px;
}

.data-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.data-cell,
.question-card,
.trick-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 12px;
  box-shadow: 0 8px 20px rgba(13, 32, 43, 0.04);
}

.data-cell strong {
  display: block;
  margin-bottom: 4px;
  font-size: 1.05rem;
}

.big-number {
  color: var(--accent);
  font-size: 1.35rem;
  font-weight: 900;
}

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

.tool-actions button,
.quiz-submit {
  min-height: 40px;
  border: 1px solid rgba(37, 99, 235, 0.22);
  border-radius: 6px;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  color: #fff;
  padding: 9px 13px;
  font-weight: 850;
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.16);
}

.tool-actions button.secondary {
  background: #fff;
  color: var(--ink);
  box-shadow: none;
}

.trick-result {
  margin-top: 10px;
  border: 1px solid rgba(47, 111, 126, 0.22);
  border-radius: var(--radius);
  background: #f8f4e8;
  padding: 12px;
  font-weight: 800;
}

.quiz-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.timer {
  border: 1px solid rgba(255, 107, 74, 0.35);
  border-radius: 999px;
  background: #fff3ef;
  color: var(--accent-2);
  padding: 8px 10px;
  font-weight: 900;
}

.question-card {
  margin-bottom: 10px;
}

.question-card h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.option-list {
  display: grid;
  gap: 7px;
}

.option-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
  padding: 8px;
  font-weight: 700;
  transition: border-color 140ms ease, background 140ms ease;
}

.option-list label:hover {
  border-color: rgba(199, 164, 90, 0.32);
  background: #fffafa;
}

.option-list label.is-correct {
  border-color: rgba(16, 145, 92, 0.55);
  background: #e7f8f1;
  color: #075e51;
}

.option-list label.is-wrong {
  border-color: rgba(216, 79, 53, 0.55);
  background: #fff0ed;
  color: #9d321e;
}

.option-list.is-locked label {
  pointer-events: none;
}

.quiz-summary {
  border: 1px solid rgba(47, 111, 126, 0.22);
  border-radius: var(--radius);
  background: #f8f4e8;
  padding: 12px;
  margin-bottom: 12px;
  font-weight: 850;
}

.floating-calc-button {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 50%;
  background:
    radial-gradient(circle at 68% 76%, rgba(0, 0, 0, 0.72), transparent 38%),
    linear-gradient(135deg, #2b2f36, #050608 58%, #111827);
  color: #fff;
  font-size: 1.85rem;
  font-weight: 950;
  box-shadow:
    inset -10px -12px 22px rgba(0, 0, 0, 0.62),
    inset 8px 8px 18px rgba(255, 255, 255, 0.16),
    0 18px 40px rgba(0, 0, 0, 0.34);
  touch-action: none;
  user-select: none;
}

.floating-calc-button:hover {
  transform: translateY(-2px);
}

.floating-calculator {
  position: fixed;
  right: 24px;
  bottom: 100px;
  z-index: 21;
  width: min(320px, calc(100vw - 28px));
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 32%),
    #080a0f;
  box-shadow: 0 28px 68px rgba(0, 0, 0, 0.38);
  color: #f6fbff;
  padding: 12px;
  transform-origin: 92% 100%;
  opacity: 0;
  pointer-events: none;
  transform: translate(42px, 64px) scale(0.18) skew(-10deg, 6deg);
  clip-path: ellipse(14% 10% at 92% 100%);
}

.floating-calculator.is-open {
  animation: genieOpen 360ms cubic-bezier(0.18, 0.86, 0.24, 1.05) forwards;
  pointer-events: auto;
}

.floating-calculator.is-closing {
  animation: genieClose 260ms ease-in forwards;
  pointer-events: none;
}

@keyframes genieOpen {
  0% {
    opacity: 0;
    transform: translate(42px, 64px) scale(0.18) skew(-10deg, 6deg);
    clip-path: ellipse(14% 10% at 92% 100%);
  }
  58% {
    opacity: 1;
    transform: translate(-8px, -10px) scale(1.03) skew(3deg, -2deg);
    clip-path: ellipse(110% 82% at 50% 54%);
  }
  100% {
    opacity: 1;
    transform: translate(0, 0) scale(1) skew(0deg, 0deg);
    clip-path: ellipse(140% 110% at 50% 50%);
  }
}

@keyframes genieClose {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1);
    clip-path: ellipse(140% 110% at 50% 50%);
  }
  100% {
    opacity: 0;
    transform: translate(42px, 64px) scale(0.16) skew(-12deg, 8deg);
    clip-path: ellipse(10% 8% at 92% 100%);
  }
}

.calc-drag-handle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 7px 7px 9px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  cursor: grab;
  touch-action: none;
}

.calc-drag-handle:active {
  cursor: grabbing;
}

.calc-drag-handle p {
  margin: 0 0 2px;
  color: #69b7ff;
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.calc-drag-handle strong {
  display: block;
  font-size: 1rem;
}

.calc-close {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 900;
}

.calc-display {
  min-height: 62px;
  overflow: hidden;
  border: 1px solid rgba(96, 165, 250, 0.24);
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.16), rgba(14, 165, 233, 0.08));
  padding: 14px;
  text-align: right;
  color: #fff;
  font-size: 1.8rem;
  font-weight: 850;
  line-height: 1.1;
  word-break: break-all;
}

.calc-keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.calc-keys button {
  min-height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.075);
  color: #f6fbff;
  font-size: 1.05rem;
  font-weight: 850;
}

.calc-keys button:hover {
  background: rgba(255, 255, 255, 0.14);
}

.calc-equals {
  background: linear-gradient(135deg, #2563eb, #0ea5e9) !important;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.24);
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 240px minmax(0, 1fr);
    padding: 18px;
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 76px minmax(0, 1fr);
  }

  .sidebar {
    position: sticky;
    top: 18px;
    min-height: calc(100vh - 36px);
  }

  .workspace,
  .solver-pane,
  .library-pane,
  .tab-content {
    min-height: 0;
  }

  .tab-nav {
    grid-template-columns: 1fr;
  }

  .tab-button {
    text-align: left;
  }

  .brand-block {
    padding-bottom: 12px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .solver-pane,
  .library-pane,
  .tab-content {
    padding: 14px;
  }

  .sidebar {
    position: static;
    min-height: auto;
    padding: 14px;
  }

  .workspace,
  .solver-pane,
  .library-pane,
  .tab-content {
    min-height: auto;
  }

  .sidebar-toggle {
    top: 10px;
    right: 10px;
  }

  .app-shell.sidebar-collapsed .sidebar {
    min-height: 64px;
    padding: 12px;
  }

  .app-shell.sidebar-collapsed .tab-nav {
    display: none;
  }

  .brand-block h1 {
    font-size: 1.85rem;
  }

  .input-grid,
  .topbar,
  .library-header,
  .tool-row {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }

  .question-box {
    min-height: 0;
  }

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

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

  .library-header input {
    max-width: none;
  }

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

  .tab-button {
    text-align: center;
  }

  .question-box {
    min-height: 0;
  }

  textarea {
    min-height: 110px;
  }

  .chat-window {
    min-height: 260px;
    max-height: 340px;
  }

  .floating-calc-button {
    right: 16px;
    bottom: 16px;
  }

  .floating-calculator {
    right: 14px;
    bottom: 90px;
  }
}

@media (max-width: 460px) {
  .app-shell {
    padding: 8px;
  }

  .tab-nav,
  .formula-grid,
  .data-grid {
    grid-template-columns: 1fr;
  }

  .formula-card,
  .data-cell,
  .question-card,
  .trick-card {
    padding: 11px;
  }

  .toolbar button,
  .file-action,
  .tool-actions button {
    width: 100%;
    text-align: center;
  }
}

/* Modern Halwa AI interface refresh */
:root {
  --ink: #101923;
  --muted: #657386;
  --panel: rgba(255, 255, 255, 0.78);
  --soft: #eef5ff;
  --line: rgba(30, 64, 175, 0.13);
  --accent: #2563eb;
  --accent-2: #0ea5e9;
  --accent-3: #d6a84c;
  --dark: #05070b;
  --dark-2: #101827;
  --gold: #d6b568;
  --radius: 8px;
  --shadow: 0 24px 70px rgba(15, 23, 42, 0.16);
  --panel-shadow: 0 1px 0 rgba(255, 255, 255, 0.86) inset, 0 22px 60px rgba(15, 23, 42, 0.1);
}

body {
  background:
    radial-gradient(circle at 18% 10%, rgba(37, 99, 235, 0.16), transparent 28%),
    radial-gradient(circle at 84% 14%, rgba(14, 165, 233, 0.14), transparent 30%),
    radial-gradient(circle at 80% 76%, rgba(214, 181, 104, 0.12), transparent 26%),
    linear-gradient(90deg, rgba(15, 23, 42, 0.04) 1px, transparent 1px),
    linear-gradient(0deg, rgba(15, 23, 42, 0.035) 1px, transparent 1px),
    #f4f8fb;
  background-size: auto, auto, auto, 38px 38px, 38px 38px, auto;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(115deg, transparent 0 34%, rgba(255, 255, 255, 0.52) 46%, transparent 58%),
    radial-gradient(circle at 48% 8%, rgba(255, 255, 255, 0.66), transparent 28%);
  opacity: 0.46;
}

.app-shell {
  grid-template-columns: 288px minmax(0, 1fr);
  gap: 22px;
  width: min(1680px, 100%);
  padding: 22px;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 82px minmax(0, 1fr);
}

.sidebar {
  top: 22px;
  min-height: calc(100vh - 44px);
  padding: 20px 18px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(37, 99, 235, 0.15), transparent 22%),
    radial-gradient(circle at 24% 0%, rgba(14, 165, 233, 0.24), transparent 24%),
    linear-gradient(145deg, #05070b, #090c12 52%, #121621);
  box-shadow: 0 28px 80px rgba(2, 6, 23, 0.38);
}

.sidebar::before {
  right: -34px;
  top: 112px;
  color: rgba(255, 255, 255, 0.045);
  font-size: 4.8rem;
}

.sidebar-toggle {
  width: 40px;
  height: 40px;
  border-color: rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.04));
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.22);
}

.brand-block {
  gap: 8px;
  padding: 18px 0 24px;
}

.brand-block h1 {
  font-size: clamp(2.1rem, 3.4vw, 3.1rem);
  text-shadow: 0 0 26px rgba(37, 99, 235, 0.34);
}

.brand-subtitle {
  color: #d9bd72;
  letter-spacing: 0.18em;
}

.tab-nav {
  gap: 10px;
}

.tab-button {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 12px 14px;
  border-color: rgba(255, 255, 255, 0.11);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.085), rgba(255, 255, 255, 0.035));
  color: #e8eef7;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset;
}

.tab-button::before {
  content: attr(data-icon);
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #cfe7ff;
  font-size: 0.95rem;
}

.tab-button.is-active {
  border-color: rgba(125, 211, 252, 0.46);
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  color: #fff;
  box-shadow: 0 16px 34px rgba(37, 99, 235, 0.34);
}

.tab-button.is-active::before {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.tab-button:hover {
  transform: translateX(3px);
}

.app-shell.sidebar-collapsed .tab-button {
  justify-content: center;
}

.app-shell.sidebar-collapsed .tab-button::before {
  display: none;
}

.workspace {
  gap: 18px;
}

.solver-pane,
.tab-content {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(37, 99, 235, 0.12);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(248, 252, 255, 0.76)),
    radial-gradient(circle at 98% 0%, rgba(37, 99, 235, 0.08), transparent 28%);
  box-shadow: var(--panel-shadow);
}

.solver-pane::before,
.tab-content::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(37, 99, 235, 0.035) 1px, transparent 1px),
    linear-gradient(0deg, rgba(37, 99, 235, 0.03) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: linear-gradient(180deg, #000, transparent 86%);
}

.solver-pane > *,
.tab-content > * {
  position: relative;
  z-index: 1;
}

.topbar,
.library-header {
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(37, 99, 235, 0.1);
}

.eyebrow,
.section-label {
  color: #2563eb;
  letter-spacing: 0.16em;
}

h2 {
  font-size: clamp(1.18rem, 1.8vw, 1.55rem);
}

.status-pill {
  border-color: rgba(37, 99, 235, 0.2);
  background: linear-gradient(135deg, rgba(239, 246, 255, 0.96), rgba(255, 255, 255, 0.78));
  box-shadow: 0 12px 30px rgba(37, 99, 235, 0.1);
}

.chat-window {
  min-height: min(42vh, 430px);
  border: 1px solid rgba(37, 99, 235, 0.12);
  border-radius: 8px;
  background:
    radial-gradient(circle at 18% 12%, rgba(14, 165, 233, 0.08), transparent 22%),
    linear-gradient(90deg, rgba(15, 23, 42, 0.025) 1px, transparent 1px),
    linear-gradient(0deg, rgba(15, 23, 42, 0.023) 1px, transparent 1px),
    rgba(255, 255, 255, 0.68);
  background-size: auto, 32px 32px, 32px 32px, auto;
}

.message {
  border-radius: 8px;
  border: 1px solid rgba(37, 99, 235, 0.1);
  box-shadow: 0 16px 36px rgba(15, 23, 42, 0.08);
}

.assistant-message {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(239, 246, 255, 0.86));
}

.user-message {
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
}

.prompt-frame {
  min-height: 164px;
  border-color: rgba(37, 99, 235, 0.16);
  border-radius: 8px;
  background:
    radial-gradient(circle at 90% 12%, rgba(37, 99, 235, 0.06), transparent 24%),
    linear-gradient(90deg, rgba(37, 99, 235, 0.035) 1px, transparent 1px),
    linear-gradient(0deg, rgba(37, 99, 235, 0.03) 1px, transparent 1px),
    rgba(255, 255, 255, 0.82);
  background-size: auto, 30px 30px, 30px 30px, auto;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.07);
}

.prompt-frame:focus-within,
.prompt-frame.is-dragging {
  border-color: rgba(14, 165, 233, 0.52);
  box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.1), 0 22px 58px rgba(37, 99, 235, 0.12);
}

#questionInput {
  color: #111827;
}

.toolbar button,
.tool-actions button,
.quiz-submit {
  border-radius: 8px;
  background: linear-gradient(135deg, #1d4ed8, #0ea5e9);
  box-shadow: 0 14px 32px rgba(37, 99, 235, 0.26);
}

.toolbar button:nth-child(2),
.tool-actions button.secondary,
.file-action {
  background: rgba(255, 255, 255, 0.82);
  color: #1d2937;
  border: 1px solid rgba(37, 99, 235, 0.12);
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.08);
}

.attach-plus {
  border-radius: 8px;
  color: #2563eb;
}

#toolSearch,
.tool-input,
.tool-select {
  border-color: rgba(37, 99, 235, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.06);
}

.formula-card,
.data-cell,
.question-card,
.trick-card,
.mini-result,
.trick-result,
.quiz-summary {
  border-color: rgba(37, 99, 235, 0.11);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(248, 252, 255, 0.74));
  box-shadow: 0 16px 38px rgba(15, 23, 42, 0.07);
}

.big-number {
  color: #2563eb;
}

.floating-calc-button {
  background:
    radial-gradient(circle at 34% 22%, rgba(255, 255, 255, 0.24), transparent 20%),
    linear-gradient(145deg, #02040b, #111827 58%, #05070b);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 24px 54px rgba(2, 6, 23, 0.36), 0 0 0 8px rgba(37, 99, 235, 0.06);
}

.floating-calculator {
  border-color: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(17, 24, 39, 0.94), rgba(3, 7, 18, 0.96));
  box-shadow: 0 32px 80px rgba(2, 6, 23, 0.42);
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 82px minmax(0, 1fr);
    padding: 16px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: flex;
    flex-direction: column;
    padding: 12px;
  }

  .sidebar {
    position: relative;
    top: 0;
    min-height: auto;
  }

  .chat-window {
    min-height: 300px;
  }

  .topbar,
  .library-header {
    align-items: flex-start;
  }
}

/* Halwa AI V2 - Math Intelligence Console */
body.template-v2 {
  --v2-bg: #e9eef3;
  --v2-surface: #f8fafc;
  --v2-white: #ffffff;
  --v2-ink: #0c1524;
  --v2-muted: #667386;
  --v2-line: #d7dfe8;
  --v2-black: #080b10;
  --v2-black-2: #111722;
  --v2-blue: #1668e8;
  --v2-cyan: #00a9dc;
  --v2-gold: #d8b25c;
  --v2-green: #16a37a;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(90deg, rgba(12, 21, 36, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(12, 21, 36, 0.03) 1px, transparent 1px),
    var(--v2-bg);
  background-size: 48px 48px;
  color: var(--v2-ink);
}

body.template-v2::before {
  display: none;
}

body.template-v2 #particleCanvas {
  z-index: 0;
  opacity: 0.28;
  filter: saturate(0.8);
}

.template-v2 .app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  grid-template-rows: 72px minmax(0, 1fr);
  gap: 14px;
  width: min(1800px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 14px;
  transition: grid-template-columns 220ms ease;
}

.template-v2 .app-shell.sidebar-collapsed {
  grid-template-columns: 74px minmax(0, 1fr);
}

.template-v2 .app-header {
  grid-column: 1 / -1;
  grid-row: 1;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-width: 0;
  padding: 0 20px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 8px;
  background:
    linear-gradient(105deg, rgba(22, 104, 232, 0.18), transparent 34%),
    #090d14;
  color: #fff;
  box-shadow: 0 12px 34px rgba(8, 11, 16, 0.18);
}

.template-v2 .header-brand,
.template-v2 .brand-copy,
.template-v2 .header-engine {
  display: flex;
  align-items: center;
}

.template-v2 .header-brand {
  gap: 11px;
  min-width: 0;
}

.template-v2 .brand-mark,
.template-v2 .rail-monogram {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: linear-gradient(145deg, #2078f5, #0c4db7);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 950;
  box-shadow: 0 10px 26px rgba(22, 104, 232, 0.28);
}

.template-v2 .brand-copy {
  align-items: flex-start;
  flex-direction: column;
  line-height: 1.1;
}

.template-v2 .brand-copy strong {
  font-size: 1.04rem;
}

.template-v2 .brand-copy small {
  margin-top: 4px;
  color: #9ba8ba;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.template-v2 .header-mode {
  display: flex;
  align-items: baseline;
  gap: 7px;
  color: #7f8da1;
  font-size: 0.74rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.template-v2 .header-mode strong {
  color: #fff;
  font-size: 0.85rem;
}

.template-v2 .header-engine {
  justify-self: end;
  gap: 8px;
  color: #b7c1ce;
  font-size: 0.76rem;
  font-weight: 800;
}

.template-v2 .engine-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c894;
  box-shadow: 0 0 0 5px rgba(34, 200, 148, 0.12), 0 0 15px rgba(34, 200, 148, 0.7);
  animation: v2Pulse 1.8s ease-in-out infinite;
}

@keyframes v2Pulse {
  50% { opacity: 0.55; transform: scale(0.86); }
}

.template-v2 .sidebar {
  position: sticky;
  top: 100px;
  grid-column: 1;
  grid-row: 2;
  align-self: start;
  display: flex;
  min-width: 0;
  min-height: calc(100vh - 100px);
  max-height: calc(100vh - 100px);
  gap: 14px;
  padding: 14px;
  overflow: hidden auto;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(22, 104, 232, 0.14), transparent 25%),
    var(--v2-black);
  color: #edf3fa;
  box-shadow: 0 20px 50px rgba(8, 11, 16, 0.2);
}

.template-v2 .sidebar::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: linear-gradient(90deg, var(--v2-blue), var(--v2-cyan), var(--v2-gold));
}

.template-v2 .sidebar-toggle {
  position: absolute;
  top: 17px;
  right: 14px;
  display: grid;
  place-content: center;
  gap: 5px;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 8px;
  background: #151b25;
  box-shadow: none;
}

.template-v2 .sidebar-toggle span {
  display: block;
  width: 14px;
  height: 2px;
  border-radius: 2px;
  background: #dce7f3;
  transition: transform 180ms ease;
}

.template-v2 .sidebar-toggle span:last-child {
  width: 9px;
}

.template-v2 .app-shell:not(.sidebar-collapsed) .sidebar-toggle span:first-child {
  transform: translateX(-2px);
}

.template-v2 .brand-block {
  display: flex;
  align-items: center;
  justify-items: initial;
  gap: 10px;
  min-height: 42px;
  padding: 0 46px 14px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  text-align: left;
}

.template-v2 .rail-monogram {
  width: 34px;
  height: 34px;
  flex-basis: 34px;
  font-size: 0.92rem;
}

.template-v2 .brand-block h1 {
  color: #fff;
  font-size: 0.92rem;
  line-height: 1.15;
  text-align: left;
  text-shadow: none;
  white-space: nowrap;
}

.template-v2 .brand-subtitle {
  margin-top: 3px;
  color: #77869a;
  font-size: 0.62rem;
  letter-spacing: 0.12em;
}

.template-v2 .tab-nav {
  display: grid;
  gap: 6px;
}

.template-v2 .tab-button {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 46px;
  padding: 7px 10px;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: #9eabba;
  box-shadow: none;
  text-align: left;
  font-size: 0.82rem;
  font-weight: 780;
  transition: color 150ms ease, background 150ms ease, border-color 150ms ease;
}

.template-v2 .tab-button::before {
  content: attr(data-icon);
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 7px;
  background: #141a23;
  color: #c7d2df;
  font-size: 0.86rem;
}

.template-v2 .tab-button::after {
  content: "";
  position: absolute;
  right: 9px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: transparent;
}

.template-v2 .tab-button:hover {
  transform: none;
  border-color: rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.04);
  color: #fff;
}

.template-v2 .tab-button.is-active {
  border-color: rgba(67, 139, 246, 0.28);
  background: linear-gradient(90deg, rgba(22, 104, 232, 0.2), rgba(22, 104, 232, 0.04));
  color: #fff;
  box-shadow: inset 3px 0 0 var(--v2-blue);
}

.template-v2 .tab-button.is-active::before {
  border-color: #2675ec;
  background: var(--v2-blue);
  color: #fff;
  box-shadow: 0 8px 20px rgba(22, 104, 232, 0.3);
}

.template-v2 .tab-button.is-active::after {
  background: var(--v2-gold);
  box-shadow: 0 0 8px rgba(216, 178, 92, 0.7);
}

.template-v2 .rail-footer {
  display: flex;
  justify-content: center;
  gap: 13px;
  margin-top: auto;
  padding: 13px 4px 2px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: #4d5968;
  font-family: Georgia, serif;
  font-size: 0.85rem;
}

.template-v2 .app-shell.sidebar-collapsed .sidebar {
  padding: 14px 10px;
}

.template-v2 .app-shell.sidebar-collapsed .brand-block {
  min-height: 42px;
  padding: 0 0 14px;
}

.template-v2 .app-shell.sidebar-collapsed .brand-block > div,
.template-v2 .app-shell.sidebar-collapsed .rail-monogram,
.template-v2 .app-shell.sidebar-collapsed .rail-footer {
  display: none;
}

.template-v2 .app-shell.sidebar-collapsed .sidebar-toggle {
  position: static;
  margin: 0 auto;
}

.template-v2 .app-shell.sidebar-collapsed .tab-button {
  justify-content: center;
  min-height: 48px;
  padding: 8px;
  font-size: 0;
}

.template-v2 .app-shell.sidebar-collapsed .tab-button::before {
  display: grid;
}

.template-v2 .app-shell.sidebar-collapsed .tab-button::after {
  content: "";
  right: 5px;
  top: 7px;
}

.template-v2 .workspace {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  min-width: 0;
  gap: 0;
}

.template-v2 .solver-pane,
.template-v2 .tab-content {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: calc(100vh - 100px);
  max-height: calc(100vh - 100px);
  flex-direction: column;
  gap: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(12, 21, 36, 0.1);
  border-radius: 8px;
  background: rgba(248, 250, 252, 0.94);
  box-shadow: 0 20px 55px rgba(12, 21, 36, 0.11);
  backdrop-filter: blur(16px);
}

.template-v2 .solver-pane::before,
.template-v2 .tab-content::before {
  display: none;
}

.template-v2 .solver-pane.is-hidden,
.template-v2 .tab-content.is-hidden {
  display: none;
}

.template-v2 .topbar,
.template-v2 .library-header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  min-height: 86px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--v2-line);
  background: rgba(255, 255, 255, 0.86);
}

.template-v2 .topbar::after,
.template-v2 .library-header::after {
  content: "f(x)  ·  π  ·  ∑";
  position: absolute;
  left: 50%;
  color: #d5dce5;
  font-family: Georgia, serif;
  font-size: 0.78rem;
  letter-spacing: 0.24em;
  transform: translateX(-50%);
}

.template-v2 .eyebrow,
.template-v2 .section-label {
  margin: 0 0 5px;
  color: var(--v2-blue);
  font-size: 0.67rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.template-v2 h2 {
  color: var(--v2-ink);
  font-size: clamp(1.18rem, 2vw, 1.55rem);
  line-height: 1.18;
}

.template-v2 .status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: auto;
  border: 1px solid rgba(22, 163, 122, 0.22);
  border-radius: 999px;
  background: #edfbf6;
  color: #0d805e;
  padding: 8px 12px;
  box-shadow: none;
  font-size: 0.75rem;
}

.template-v2 .status-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--v2-green);
}

.template-v2 .solver-console {
  display: grid;
  grid-template-rows: minmax(250px, 1fr) auto;
  min-height: 0;
  flex: 1;
  background: #eef2f6;
}

.template-v2 .chat-window {
  position: relative;
  min-height: 0;
  max-height: none;
  overflow: auto;
  overflow-x: hidden;
  border: 0;
  border-radius: 0;
  background:
    linear-gradient(90deg, rgba(12, 21, 36, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(12, 21, 36, 0.032) 1px, transparent 1px),
    #f2f5f8;
  background-size: 34px 34px;
  padding: 28px;
}

.template-v2 .chat-window::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, var(--v2-blue), var(--v2-cyan) 55%, var(--v2-gold));
}

.template-v2 .console-orbit {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(360px, 55vw);
  aspect-ratio: 1;
  border: 1px solid rgba(22, 104, 232, 0.07);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: v2Orbit 34s linear infinite;
}

.template-v2 .console-orbit::before,
.template-v2 .console-orbit::after {
  content: "";
  position: absolute;
  border: 1px solid rgba(216, 178, 92, 0.09);
  border-radius: 50%;
}

.template-v2 .console-orbit::before { inset: 16%; }
.template-v2 .console-orbit::after { inset: 34%; border-color: rgba(0, 169, 220, 0.1); }

.template-v2 .console-orbit span {
  position: absolute;
  color: rgba(22, 104, 232, 0.12);
  font-family: Georgia, serif;
  font-size: 1.1rem;
}

.template-v2 .console-orbit span:nth-child(1) { top: -9px; left: 48%; }
.template-v2 .console-orbit span:nth-child(2) { right: -6px; top: 51%; }
.template-v2 .console-orbit span:nth-child(3) { bottom: -10px; left: 47%; }

@keyframes v2Orbit {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

.template-v2 .chat-stream {
  position: relative;
  z-index: 1;
  display: flex;
  min-height: 100%;
  justify-content: flex-end;
  gap: 14px;
}

.template-v2 .message {
  width: fit-content;
  max-width: min(820px, 88%);
  border: 1px solid var(--v2-line);
  border-radius: 8px;
  padding: 15px 17px;
  box-shadow: 0 12px 28px rgba(12, 21, 36, 0.07);
  line-height: 1.55;
}

.template-v2 .assistant-message {
  position: relative;
  align-self: flex-start;
  border-left: 3px solid var(--v2-blue);
  background: rgba(255, 255, 255, 0.94);
}

.template-v2 .user-message {
  align-self: flex-end;
  border-color: #1668e8;
  background: #1668e8;
  color: #fff;
}

.template-v2 #answerText {
  color: var(--v2-ink);
  font-size: 1.12rem;
  font-weight: 760;
}

.template-v2 #stepsList {
  color: var(--v2-muted);
}

.template-v2 .chat-composer {
  position: relative;
  z-index: 2;
  display: block;
  padding: 16px 20px 18px;
  border-top: 1px solid var(--v2-line);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 -12px 34px rgba(12, 21, 36, 0.05);
}

.template-v2 .question-box {
  display: flex;
  gap: 8px;
}

.template-v2 .question-box > label {
  color: #536174;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.template-v2 .prompt-frame {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  min-height: 112px;
  gap: 8px 12px;
  padding: 13px;
  border: 1px solid #c9d3df;
  border-radius: 8px;
  background: #f8fafc;
  background-image:
    linear-gradient(90deg, rgba(12, 21, 36, 0.026) 1px, transparent 1px),
    linear-gradient(rgba(12, 21, 36, 0.023) 1px, transparent 1px);
  background-size: 28px 28px;
  box-shadow: inset 0 1px 0 #fff;
}

.template-v2 .prompt-frame:focus-within,
.template-v2 .prompt-frame.is-dragging {
  border-color: var(--v2-blue);
  box-shadow: 0 0 0 3px rgba(22, 104, 232, 0.1);
}

.template-v2 #questionInput {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 58px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--v2-ink);
  font-size: 0.98rem;
  line-height: 1.5;
  resize: none;
}

.template-v2 #questionInput::placeholder {
  color: #8a96a6;
}

.template-v2 .image-list {
  grid-column: 1 / -1;
}

.template-v2 .prompt-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
}

.template-v2 .attach-plus {
  display: grid;
  place-items: center;
  width: 32px;
  min-width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: #fff;
  color: var(--v2-blue);
  box-shadow: none;
  font-size: 1.15rem;
}

.template-v2 .composer-hint,
.template-v2 .composer-status {
  color: #7a8798;
  font-size: 0.74rem;
}

.template-v2 .composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.template-v2 .composer-status {
  margin: 0;
}

.template-v2 .toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
}

.template-v2 .toolbar button {
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: #fff;
  color: #334155;
  box-shadow: none;
  font-size: 0.78rem;
  font-weight: 850;
}

.template-v2 .toolbar #solveBtn {
  display: inline-flex;
  align-items: center;
  gap: 18px;
  min-width: 108px;
  justify-content: space-between;
  border-color: var(--v2-blue);
  background: var(--v2-blue);
  color: #fff;
  box-shadow: 0 10px 22px rgba(22, 104, 232, 0.22);
}

.template-v2 .toolbar #solveBtn b {
  font-size: 1rem;
}

.template-v2 .toolbar button:hover,
.template-v2 .file-action:hover {
  transform: translateY(-1px);
}

.template-v2 .tab-content {
  overflow: hidden;
}

.template-v2 .library-header {
  position: relative;
  margin: 0;
}

.template-v2 .library-header input,
.template-v2 #toolSearch,
.template-v2 .tool-input,
.template-v2 .tool-select {
  width: min(260px, 100%);
  min-height: 40px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: #fff;
  color: var(--v2-ink);
  padding: 9px 11px;
  box-shadow: none;
}

.template-v2 .tool-row {
  display: flex;
  flex: 0 0 auto;
  align-items: end;
  gap: 12px;
  margin: 0;
  padding: 16px 22px;
  border: 0;
  border-bottom: 1px solid var(--v2-line);
  border-radius: 0;
  background: #eef3f8;
}

.template-v2 .tool-row label {
  color: #526174;
  font-size: 0.76rem;
  font-weight: 800;
}

.template-v2 .tool-result {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 20px 22px;
  background:
    linear-gradient(90deg, rgba(12, 21, 36, 0.025) 1px, transparent 1px),
    linear-gradient(rgba(12, 21, 36, 0.023) 1px, transparent 1px),
    #f7f9fb;
  background-size: 34px 34px;
}

.template-v2 .formula-grid,
.template-v2 .data-grid {
  gap: 10px;
}

.template-v2 .formula-card,
.template-v2 .data-cell,
.template-v2 .question-card,
.template-v2 .trick-card,
.template-v2 .mini-result,
.template-v2 .trick-result,
.template-v2 .quiz-summary {
  border: 1px solid var(--v2-line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 9px 24px rgba(12, 21, 36, 0.055);
}

.template-v2 .formula-card,
.template-v2 .data-cell,
.template-v2 .question-card,
.template-v2 .trick-card {
  padding: 14px;
}

.template-v2 .formula-card {
  border-top: 3px solid #dbe5f0;
}

.template-v2 .formula-card:hover,
.template-v2 .data-cell:hover,
.template-v2 .trick-card:hover {
  border-color: rgba(22, 104, 232, 0.28);
  transform: translateY(-1px);
}

.template-v2 .big-number {
  color: var(--v2-blue);
}

.template-v2 .tag {
  background: #eef5ff;
  color: #1559bd;
}

.template-v2 .tool-actions button,
.template-v2 .quiz-submit {
  min-height: 40px;
  border: 1px solid var(--v2-blue);
  border-radius: 7px;
  background: var(--v2-blue);
  color: #fff;
  box-shadow: 0 8px 18px rgba(22, 104, 232, 0.18);
}

.template-v2 .tool-actions button.secondary {
  border-color: #cbd5e1;
  background: #fff;
  color: #263548;
  box-shadow: none;
}

.template-v2 .floating-calc-button {
  width: 58px;
  height: 58px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background: #080b10;
  color: #fff;
  box-shadow: 0 18px 36px rgba(8, 11, 16, 0.3), 0 0 0 5px rgba(22, 104, 232, 0.1);
  font-size: 1.55rem;
}

.template-v2 .floating-calculator {
  border-radius: 8px;
  background: #080b10;
}

@media (max-width: 1100px) {
  .template-v2 .app-shell,
  .template-v2 .app-shell.sidebar-collapsed {
    grid-template-columns: 74px minmax(0, 1fr);
  }

  .template-v2 .sidebar {
    padding: 14px 10px;
  }

  .template-v2 .brand-block {
    min-height: 42px;
    padding: 0 0 14px;
  }

  .template-v2 .brand-block > div,
  .template-v2 .rail-monogram,
  .template-v2 .rail-footer {
    display: none;
  }

  .template-v2 .sidebar-toggle {
    position: static;
    margin: 0 auto;
  }

  .template-v2 .tab-button {
    justify-content: center;
    padding: 8px;
    font-size: 0;
  }

  .template-v2 .header-mode,
  .template-v2 .topbar::after,
  .template-v2 .library-header::after {
    display: none;
  }

  .template-v2 .app-header {
    grid-template-columns: 1fr auto;
  }
}

@media (max-width: 760px) {
  body.template-v2 {
    background-size: 36px 36px;
  }

  .template-v2 .app-shell,
  .template-v2 .app-shell.sidebar-collapsed {
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr);
    grid-template-rows: 62px minmax(0, 1fr);
    gap: 8px;
    padding: 8px;
  }

  .template-v2 .app-header {
    min-height: 62px;
    padding: 0 12px;
  }

  .template-v2 .brand-mark {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
  }

  .template-v2 .brand-copy small,
  .template-v2 .header-engine span:last-child {
    display: none;
  }

  .template-v2 .sidebar {
    position: sticky;
    top: 78px;
    width: 54px;
    min-height: calc(100vh - 78px);
    max-height: calc(100vh - 78px);
    padding: 10px 6px;
    z-index: 8;
    transition: width 200ms ease, box-shadow 200ms ease;
  }

  .template-v2 .app-shell:not(.sidebar-collapsed) .sidebar {
    width: min(264px, calc(100vw - 24px));
    box-shadow: 20px 20px 70px rgba(8, 11, 16, 0.42);
  }

  .template-v2 .app-shell.sidebar-collapsed .sidebar {
    width: 54px;
    min-height: calc(100vh - 78px);
    max-height: calc(100vh - 78px);
    padding: 10px 6px;
  }

  .template-v2 .app-shell.sidebar-collapsed .tab-nav {
    display: grid;
    gap: 6px;
  }

  .template-v2 .brand-block {
    min-height: 38px;
    padding: 0 42px 12px 0;
  }

  .template-v2 .app-shell.sidebar-collapsed .brand-block {
    padding: 0 0 12px;
  }

  .template-v2 .app-shell:not(.sidebar-collapsed) .brand-block > div,
  .template-v2 .app-shell:not(.sidebar-collapsed) .rail-monogram {
    display: block;
  }

  .template-v2 .app-shell:not(.sidebar-collapsed) .rail-monogram {
    display: grid;
  }

  .template-v2 .app-shell:not(.sidebar-collapsed) .sidebar-toggle {
    position: absolute;
    top: 13px;
    right: 10px;
    margin: 0;
  }

  .template-v2 .app-shell:not(.sidebar-collapsed) .tab-button {
    justify-content: flex-start;
    padding: 7px 9px;
    font-size: 0.8rem;
  }

  .template-v2 .workspace {
    grid-column: 2;
    grid-row: 2;
  }

  .template-v2 .solver-pane,
  .template-v2 .tab-content {
    min-height: calc(100vh - 78px);
    max-height: calc(100vh - 78px);
  }

  .template-v2 .topbar,
  .template-v2 .library-header {
    min-height: 76px;
    padding: 13px 14px;
  }

  .template-v2 .topbar h2,
  .template-v2 .library-header h2 {
    font-size: 1.02rem;
  }

  .template-v2 .status-pill {
    padding: 7px 9px;
    font-size: 0.68rem;
  }

  .template-v2 .chat-window {
    min-height: 0;
    padding: 18px 12px;
  }

  .template-v2 .message {
    max-width: 96%;
    padding: 12px;
  }

  .template-v2 .chat-composer {
    padding: 12px;
  }

  .template-v2 .prompt-frame {
    min-height: 104px;
  }

  .template-v2 .composer-footer {
    align-items: flex-end;
  }

  .template-v2 .composer-status {
    max-width: 42%;
  }

  .template-v2 .library-header {
    align-items: stretch;
    flex-direction: column;
  }

  .template-v2 .library-header input,
  .template-v2 #toolSearch {
    width: 100%;
    max-width: none;
  }

  .template-v2 .tool-row {
    flex-direction: column;
    align-items: stretch;
    padding: 14px;
  }

  .template-v2 .tool-row label,
  .template-v2 .tool-input,
  .template-v2 .tool-select {
    width: 100%;
    max-width: none;
  }

  .template-v2 .tool-result {
    padding: 14px;
  }

  .template-v2 .formula-grid,
  .template-v2 .data-grid {
    grid-template-columns: 1fr;
  }

  .template-v2 .floating-calc-button {
    right: 14px;
    bottom: 14px;
    width: 52px;
    height: 52px;
  }
}

@media (max-width: 430px) {
  .template-v2 .brand-copy strong {
    font-size: 0.9rem;
  }

  .template-v2 .topbar {
    align-items: flex-start;
  }

  .template-v2 .toolbar button {
    width: auto;
  }

  .template-v2 .toolbar #solveBtn {
    min-width: 92px;
  }

  .template-v2 .composer-hint {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  .template-v2 .console-orbit,
  .template-v2 .engine-dot {
    animation: none;
  }
}

/* Halwa AI V3 - full template replacement */
body.template-v3 {
  --v3-bg: #0b0e10;
  --v3-panel: #15191c;
  --v3-panel-2: #1d2327;
  --v3-paper: #f2f3ee;
  --v3-white: #ffffff;
  --v3-ink: #101416;
  --v3-muted: #6f7a7e;
  --v3-line: #d8ddd9;
  --v3-lime: #ccf43d;
  --v3-mint: #28d7bd;
  --v3-amber: #ffb45a;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(120deg, rgba(204, 244, 61, 0.025) 0 25%, transparent 25% 75%, rgba(40, 215, 189, 0.025) 75%),
    #0b0e10;
  color: var(--v3-ink);
}

body.template-v3::before {
  display: none;
}

.template-v3 #particleCanvas {
  z-index: 0;
  opacity: 0.12;
  filter: grayscale(1);
}

.template-v3 .app-shell,
.template-v3 .app-shell.sidebar-collapsed {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 70px auto minmax(0, 1fr);
  gap: 10px;
  width: min(1840px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 12px;
}

.template-v3 .app-header {
  grid-column: 1;
  grid-row: 1;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-width: 0;
  padding: 0 20px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: var(--v3-paper);
  color: var(--v3-ink);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
}

.template-v3 .header-brand,
.template-v3 .brand-copy,
.template-v3 .header-engine {
  display: flex;
  align-items: center;
}

.template-v3 .header-brand {
  gap: 11px;
}

.template-v3 .brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 7px;
  background: var(--v3-ink);
  color: var(--v3-lime);
  font-size: 1.05rem;
  font-weight: 950;
  box-shadow: 6px 6px 0 var(--v3-lime);
}

.template-v3 .brand-copy {
  align-items: flex-start;
  flex-direction: column;
  line-height: 1.1;
}

.template-v3 .brand-copy strong {
  font-size: 1.04rem;
}

.template-v3 .brand-copy small {
  margin-top: 4px;
  color: #697275;
  font-size: 0.65rem;
  font-weight: 850;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.template-v3 .header-mode {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #7b8588;
  font-size: 0.67rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.template-v3 .header-mode strong {
  color: var(--v3-ink);
  font-size: 0.76rem;
}

.template-v3 .header-engine {
  justify-self: end;
  gap: 9px;
  color: #4e5b5e;
  font-size: 0.74rem;
  font-weight: 850;
}

.template-v3 .engine-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #17a884;
  box-shadow: 0 0 0 5px rgba(23, 168, 132, 0.12);
  animation: v3Signal 1.8s ease-in-out infinite;
}

@keyframes v3Signal {
  50% { transform: scale(0.78); opacity: 0.55; }
}

.template-v3 .sidebar,
.template-v3 .app-shell.sidebar-collapsed .sidebar {
  position: relative;
  top: auto;
  grid-column: 1;
  grid-row: 2;
  align-self: stretch;
  display: flex;
  flex-direction: row;
  align-items: center;
  min-width: 0;
  width: auto;
  min-height: 64px;
  max-height: none;
  gap: 8px;
  padding: 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: #15191c;
  color: #fff;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.24);
}

.template-v3 .sidebar::before {
  content: "TOOLS";
  position: static;
  display: grid;
  place-items: center;
  width: 52px;
  height: 44px;
  flex: 0 0 52px;
  color: #879195;
  font-size: 0.58rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  writing-mode: initial;
}

.template-v3 .brand-block,
.template-v3 .rail-footer,
.template-v3 .sidebar-toggle {
  display: none;
}

.template-v3 .tab-nav,
.template-v3 .app-shell.sidebar-collapsed .tab-nav {
  display: flex;
  flex: 1;
  min-width: 0;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.template-v3 .tab-nav::-webkit-scrollbar {
  display: none;
}

.template-v3 .tab-button,
.template-v3 .app-shell.sidebar-collapsed .tab-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-width: max-content;
  min-height: 44px;
  gap: 8px;
  padding: 7px 12px 7px 8px;
  overflow: visible;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: #9da7aa;
  box-shadow: none;
  text-align: left;
  font-size: 0.76rem;
  font-weight: 820;
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}

.template-v3 .tab-button::before,
.template-v3 .app-shell.sidebar-collapsed .tab-button::before {
  content: attr(data-icon);
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  background: #21272b;
  color: #d7dddf;
  font-size: 0.78rem;
}

.template-v3 .tab-button::after,
.template-v3 .app-shell.sidebar-collapsed .tab-button::after {
  content: "";
  display: none;
}

.template-v3 .tab-button:hover {
  transform: none;
  border-color: rgba(255, 255, 255, 0.08);
  background: #1d2327;
  color: #fff;
}

.template-v3 .tab-button.is-active {
  border-color: var(--v3-lime);
  background: var(--v3-lime);
  color: #111607;
  box-shadow: none;
}

.template-v3 .tab-button.is-active::before {
  border-color: #111607;
  background: #111607;
  color: var(--v3-lime);
  box-shadow: none;
}

.template-v3 .workspace {
  grid-column: 1;
  grid-row: 3;
  display: grid;
  min-width: 0;
  gap: 0;
}

.template-v3 .solver-pane,
.template-v3 .tab-content {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: calc(100vh - 176px);
  max-height: calc(100vh - 176px);
  gap: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: transparent;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  backdrop-filter: none;
}

.template-v3 .solver-pane::before,
.template-v3 .tab-content::before {
  display: none;
}

.template-v3 .solver-pane.is-hidden,
.template-v3 .tab-content.is-hidden {
  display: none;
}

.template-v3 .topbar,
.template-v3 .library-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 78px;
  margin: 0;
  padding: 14px 20px;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  background: #15191c;
  color: #fff;
}

.template-v3 .topbar::after,
.template-v3 .library-header::after {
  content: "π  /  ∑  /  f(x)  /  √";
  position: absolute;
  left: 50%;
  color: #394247;
  font-family: Georgia, serif;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  transform: translateX(-50%);
}

.template-v3 .eyebrow,
.template-v3 .section-label {
  margin: 0 0 5px;
  color: var(--v3-lime);
  font-size: 0.64rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.template-v3 .topbar h2,
.template-v3 .library-header h2 {
  color: #fff;
  font-size: clamp(1.15rem, 1.8vw, 1.48rem);
}

.template-v3 .status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: auto;
  border: 1px solid rgba(204, 244, 61, 0.3);
  border-radius: 6px;
  background: rgba(204, 244, 61, 0.08);
  color: var(--v3-lime);
  padding: 8px 11px;
  box-shadow: none;
  font-size: 0.72rem;
}

.template-v3 .status-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--v3-lime);
}

.template-v3 .solver-console {
  display: grid;
  grid-template-columns: minmax(0, 1.42fr) minmax(340px, 0.58fr);
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
  gap: 10px;
  padding: 10px;
  background: #0f1214;
}

.template-v3 .chat-window {
  position: relative;
  grid-column: 1;
  min-width: 0;
  min-height: 0;
  max-height: none;
  overflow: auto;
  overflow-x: hidden;
  padding: 24px;
  border: 0;
  border-radius: 7px;
  background:
    linear-gradient(90deg, rgba(16, 20, 22, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(16, 20, 22, 0.035) 1px, transparent 1px),
    var(--v3-paper);
  background-size: 32px 32px;
}

.template-v3 .chat-window::before {
  content: "OUTPUT";
  position: absolute;
  top: 13px;
  right: 15px;
  color: #b0b8b7;
  font-size: 0.56rem;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.template-v3 .console-orbit {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(360px, 52vw);
  aspect-ratio: 1;
  border: 1px solid rgba(16, 20, 22, 0.06);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: v3Orbit 42s linear infinite;
}

.template-v3 .console-orbit::before,
.template-v3 .console-orbit::after {
  content: "";
  position: absolute;
  border: 1px solid rgba(16, 20, 22, 0.055);
  border-radius: 50%;
}

.template-v3 .console-orbit::before { inset: 18%; }
.template-v3 .console-orbit::after { inset: 36%; }

.template-v3 .console-orbit span {
  position: absolute;
  color: rgba(16, 20, 22, 0.12);
  font-family: Georgia, serif;
}

.template-v3 .console-orbit span:nth-child(1) { top: -8px; left: 48%; }
.template-v3 .console-orbit span:nth-child(2) { right: -5px; top: 50%; }
.template-v3 .console-orbit span:nth-child(3) { bottom: -8px; left: 48%; }

@keyframes v3Orbit {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

.template-v3 .chat-stream {
  position: relative;
  z-index: 1;
  min-height: 100%;
  justify-content: flex-end;
  gap: 12px;
}

.template-v3 .message {
  max-width: min(780px, 90%);
  border: 1px solid #d5dad6;
  border-radius: 7px;
  padding: 14px 16px;
  box-shadow: 7px 7px 0 rgba(16, 20, 22, 0.07);
}

.template-v3 .assistant-message {
  align-self: flex-start;
  border-left: 4px solid var(--v3-mint);
  background: #fff;
}

.template-v3 .user-message {
  align-self: flex-end;
  border-color: #14191b;
  background: #14191b;
  color: #fff;
  box-shadow: 7px 7px 0 rgba(204, 244, 61, 0.34);
}

.template-v3 #answerText {
  color: var(--v3-ink);
  font-size: 1.1rem;
  font-weight: 780;
}

.template-v3 #stepsList {
  color: var(--v3-muted);
}

.template-v3 .chat-composer {
  grid-column: 2;
  align-self: stretch;
  display: block;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.template-v3 .question-box {
  display: flex;
  height: 100%;
  min-height: 0;
  flex-direction: column;
  gap: 9px;
  padding: 18px;
  border-radius: 7px;
  background: #191e21;
  color: #fff;
}

.template-v3 .question-box > label {
  color: var(--v3-lime);
  font-size: 0.65rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.template-v3 .prompt-frame {
  position: relative;
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid #384247;
  border-radius: 7px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    #202629;
  background-size: 28px 28px;
  box-shadow: none;
}

.template-v3 .prompt-frame:focus-within,
.template-v3 .prompt-frame.is-dragging {
  border-color: var(--v3-mint);
  box-shadow: 0 0 0 3px rgba(40, 215, 189, 0.12);
}

.template-v3 #questionInput {
  min-height: 150px;
  flex: 1;
  padding: 0;
  border: 0;
  background: transparent;
  color: #f5f7f5;
  font-size: 0.98rem;
  line-height: 1.55;
  resize: none;
}

.template-v3 #questionInput::placeholder {
  color: #7c888c;
}

.template-v3 .image-list {
  grid-template-columns: repeat(auto-fit, minmax(80px, 100px));
}

.template-v3 .image-item {
  border-color: #3b4549;
  background: #101416;
}

.template-v3 .prompt-actions {
  margin-top: auto;
}

.template-v3 .attach-plus {
  display: grid;
  place-items: center;
  width: 34px;
  min-width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border: 1px solid #465156;
  border-radius: 6px;
  background: #2b3337;
  color: var(--v3-lime);
  box-shadow: none;
  font-size: 1.15rem;
}

.template-v3 .composer-hint,
.template-v3 .composer-status {
  color: #849094;
  font-size: 0.72rem;
}

.template-v3 .composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.template-v3 .composer-status {
  margin: 0;
}

.template-v3 .toolbar {
  display: flex;
  gap: 7px;
  flex-wrap: nowrap;
}

.template-v3 .toolbar button {
  min-height: 39px;
  padding: 8px 13px;
  border: 1px solid #3d484c;
  border-radius: 6px;
  background: #252c30;
  color: #cad1d3;
  box-shadow: none;
  font-size: 0.76rem;
  font-weight: 850;
}

.template-v3 .toolbar #solveBtn {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  min-width: 110px;
  gap: 18px;
  border-color: var(--v3-lime);
  background: var(--v3-lime);
  color: #111607;
  box-shadow: none;
}

.template-v3 .toolbar button:hover,
.template-v3 .file-action:hover {
  transform: translateY(-1px);
}

.template-v3 .tab-content {
  grid-template-rows: auto auto minmax(0, 1fr);
  background: var(--v3-paper);
}

.template-v3 .library-header input,
.template-v3 #toolSearch {
  width: min(270px, 100%);
  min-height: 40px;
  border: 1px solid #3c464a;
  border-radius: 6px;
  background: #22282c;
  color: #fff;
  padding: 9px 12px;
  box-shadow: none;
}

.template-v3 .tool-row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  margin: 0;
  padding: 14px 18px;
  border: 0;
  border-bottom: 1px solid var(--v3-line);
  border-radius: 0;
  background: #e4e7e1;
}

.template-v3 .tool-row label {
  color: #596467;
  font-size: 0.75rem;
  font-weight: 850;
}

.template-v3 .tool-input,
.template-v3 .tool-select {
  border: 1px solid #c7cec8;
  border-radius: 6px;
  background: #fff;
  box-shadow: none;
}

.template-v3 .tool-result {
  min-height: 0;
  overflow: auto;
  padding: 18px;
  background:
    linear-gradient(90deg, rgba(16, 20, 22, 0.03) 1px, transparent 1px),
    linear-gradient(rgba(16, 20, 22, 0.03) 1px, transparent 1px),
    var(--v3-paper);
  background-size: 32px 32px;
}

.template-v3 .formula-card,
.template-v3 .data-cell,
.template-v3 .question-card,
.template-v3 .trick-card,
.template-v3 .mini-result,
.template-v3 .trick-result,
.template-v3 .quiz-summary {
  border: 1px solid #d5dad6;
  border-radius: 7px;
  background: #fff;
  box-shadow: 5px 5px 0 rgba(16, 20, 22, 0.055);
}

.template-v3 .formula-card,
.template-v3 .data-cell,
.template-v3 .question-card,
.template-v3 .trick-card {
  padding: 14px;
}

.template-v3 .formula-card:hover,
.template-v3 .data-cell:hover,
.template-v3 .trick-card:hover {
  border-color: #aab5ad;
  transform: translateY(-1px);
}

.template-v3 .big-number {
  color: #0c8d78;
}

.template-v3 .tag {
  background: #edf8ca;
  color: #344400;
}

.template-v3 .tool-actions button,
.template-v3 .quiz-submit {
  border: 1px solid #111607;
  border-radius: 6px;
  background: #111607;
  color: var(--v3-lime);
  box-shadow: none;
}

.template-v3 .tool-actions button.secondary {
  border-color: #c6ccc7;
  background: #fff;
  color: #2c3638;
}

.template-v3 .floating-calc-button {
  width: 58px;
  height: 58px;
  border: 2px solid var(--v3-lime);
  border-radius: 50%;
  background: #111516;
  color: var(--v3-lime);
  box-shadow: 0 16px 35px rgba(0, 0, 0, 0.34);
}

.template-v3 .floating-calculator {
  border: 1px solid #333b3f;
  border-radius: 8px;
  background: #111516;
}

@media (max-width: 1080px) {
  .template-v3 .app-header {
    grid-template-columns: 1fr auto;
  }

  .template-v3 .header-mode,
  .template-v3 .topbar::after,
  .template-v3 .library-header::after {
    display: none;
  }

  .template-v3 .solver-console {
    grid-template-columns: minmax(0, 1.2fr) minmax(310px, 0.8fr);
  }

  .template-v3 .tab-button,
  .template-v3 .app-shell.sidebar-collapsed .tab-button {
    padding-right: 9px;
    font-size: 0.72rem;
  }
}

@media (max-width: 820px) {
  .template-v3 .app-shell,
  .template-v3 .app-shell.sidebar-collapsed {
    grid-template-rows: 64px auto minmax(0, 1fr);
    padding: 8px;
    gap: 8px;
  }

  .template-v3 .app-header {
    min-height: 64px;
    padding: 0 12px;
  }

  .template-v3 .sidebar,
  .template-v3 .app-shell.sidebar-collapsed .sidebar {
    min-height: 56px;
    padding: 6px;
  }

  .template-v3 .sidebar::before {
    display: none;
  }

  .template-v3 .tab-button,
  .template-v3 .app-shell.sidebar-collapsed .tab-button {
    min-height: 42px;
    padding: 6px;
    font-size: 0;
  }

  .template-v3 .tab-button::before,
  .template-v3 .app-shell.sidebar-collapsed .tab-button::before {
    width: 30px;
    height: 30px;
  }

  .template-v3 .solver-pane,
  .template-v3 .tab-content {
    min-height: calc(100vh - 152px);
    max-height: none;
  }

  .template-v3 .solver-console {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(300px, 1fr) auto;
  }

  .template-v3 .chat-window,
  .template-v3 .chat-composer {
    grid-column: 1;
  }

  .template-v3 .chat-composer {
    grid-row: 2;
  }

  .template-v3 .question-box {
    height: auto;
    padding: 13px;
  }

  .template-v3 .prompt-frame {
    min-height: 118px;
  }

  .template-v3 #questionInput {
    min-height: 68px;
  }

  .template-v3 .library-header {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .template-v3 .library-header input,
  .template-v3 #toolSearch {
    width: 100%;
    max-width: none;
  }
}

@media (max-width: 520px) {
  .template-v3 .brand-mark {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
    box-shadow: 4px 4px 0 var(--v3-lime);
  }

  .template-v3 .brand-copy small,
  .template-v3 .header-engine span:last-child {
    display: none;
  }

  .template-v3 .topbar,
  .template-v3 .library-header {
    min-height: 72px;
    padding: 12px;
  }

  .template-v3 .topbar h2,
  .template-v3 .library-header h2 {
    font-size: 1rem;
  }

  .template-v3 .status-pill {
    padding: 7px 8px;
    font-size: 0.65rem;
  }

  .template-v3 .chat-window {
    padding: 16px 12px;
  }

  .template-v3 .message {
    max-width: 96%;
    padding: 12px;
  }

  .template-v3 .composer-footer {
    align-items: flex-end;
  }

  .template-v3 .composer-status {
    max-width: 38%;
  }

  .template-v3 .toolbar button {
    width: auto;
    padding: 8px 10px;
  }

  .template-v3 .toolbar #solveBtn {
    min-width: 92px;
  }

  .template-v3 .tool-row {
    flex-direction: column;
    align-items: stretch;
    padding: 12px;
  }

  .template-v3 .tool-row label,
  .template-v3 .tool-input,
  .template-v3 .tool-select {
    width: 100%;
    max-width: none;
  }

  .template-v3 .tool-result {
    padding: 12px;
  }

  .template-v3 .formula-grid,
  .template-v3 .data-grid {
    grid-template-columns: 1fr;
  }

  .template-v3 .floating-calc-button {
    right: 14px;
    bottom: 14px;
    width: 52px;
    height: 52px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .template-v3 .console-orbit,
  .template-v3 .engine-dot {
    animation: none;
  }
}

/* Compact left menu rail */
.template-v3.menu-rail .app-shell,
.template-v3.menu-rail .app-shell.sidebar-collapsed {
  grid-template-columns: 108px minmax(0, 1fr);
  grid-template-rows: 70px minmax(0, 1fr);
  gap: 10px;
}

.template-v3.menu-rail .app-header {
  grid-column: 1 / -1;
  grid-row: 1;
}

.template-v3.menu-rail .sidebar,
.template-v3.menu-rail .app-shell.sidebar-collapsed .sidebar {
  position: sticky;
  top: 92px;
  grid-column: 1;
  grid-row: 2;
  align-self: start;
  display: flex;
  width: 108px;
  min-width: 108px;
  min-height: calc(100vh - 104px);
  max-height: calc(100vh - 104px);
  flex-direction: column;
  align-items: stretch;
  gap: 7px;
  padding: 8px;
  overflow: hidden;
}

.template-v3.menu-rail .sidebar::before {
  content: "TOOLS";
  display: grid;
  place-items: center;
  width: 100%;
  height: 28px;
  flex: 0 0 28px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: #778185;
  font-size: 0.55rem;
  font-weight: 900;
  letter-spacing: 0.14em;
}

.template-v3.menu-rail .tab-nav,
.template-v3.menu-rail .app-shell.sidebar-collapsed .tab-nav {
  display: grid;
  grid-template-columns: 1fr;
  flex: 1;
  gap: 6px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #394247 transparent;
}

.template-v3.menu-rail .tab-button,
.template-v3.menu-rail .app-shell.sidebar-collapsed .tab-button {
  display: flex;
  width: 100%;
  min-width: 0;
  min-height: 68px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 4px;
  overflow: hidden;
  border-radius: 6px;
  text-align: center;
  font-size: 0.62rem;
  font-weight: 820;
  line-height: 1.15;
  white-space: normal;
}

.template-v3.menu-rail .tab-button::before,
.template-v3.menu-rail .app-shell.sidebar-collapsed .tab-button::before {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
}

.template-v3.menu-rail .workspace {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
}

.template-v3.menu-rail .solver-pane,
.template-v3.menu-rail .tab-content {
  min-height: calc(100vh - 104px);
  max-height: calc(100vh - 104px);
}

@media (max-width: 900px) {
  .template-v3.menu-rail .app-shell,
  .template-v3.menu-rail .app-shell.sidebar-collapsed {
    grid-template-columns: 78px minmax(0, 1fr);
  }

  .template-v3.menu-rail .sidebar,
  .template-v3.menu-rail .app-shell.sidebar-collapsed .sidebar {
    width: 78px;
    min-width: 78px;
    padding: 7px;
  }

  .template-v3.menu-rail .tab-button,
  .template-v3.menu-rail .app-shell.sidebar-collapsed .tab-button {
    min-height: 64px;
    padding: 6px 3px;
    font-size: 0.56rem;
  }
}

@media (max-width: 600px) {
  .template-v3.menu-rail .app-shell,
  .template-v3.menu-rail .app-shell.sidebar-collapsed {
    grid-template-columns: 66px minmax(0, 1fr);
    grid-template-rows: 60px minmax(0, 1fr);
    gap: 6px;
    padding: 6px;
  }

  .template-v3.menu-rail .app-header {
    min-height: 60px;
    padding: 0 10px;
  }

  .template-v3.menu-rail .sidebar,
  .template-v3.menu-rail .app-shell.sidebar-collapsed .sidebar {
    top: 72px;
    width: 66px;
    min-width: 66px;
    min-height: calc(100vh - 78px);
    max-height: calc(100vh - 78px);
    padding: 6px 5px;
  }

  .template-v3.menu-rail .sidebar::before {
    height: 24px;
    flex-basis: 24px;
    font-size: 0.48rem;
  }

  .template-v3.menu-rail .tab-nav,
  .template-v3.menu-rail .app-shell.sidebar-collapsed .tab-nav {
    display: grid;
    gap: 5px;
  }

  .template-v3.menu-rail .tab-button,
  .template-v3.menu-rail .app-shell.sidebar-collapsed .tab-button {
    min-height: 62px;
    gap: 4px;
    padding: 5px 2px;
    font-size: 0.5rem;
    line-height: 1.12;
  }

  .template-v3.menu-rail .tab-button::before,
  .template-v3.menu-rail .app-shell.sidebar-collapsed .tab-button::before {
    width: 27px;
    height: 27px;
    flex-basis: 27px;
    font-size: 0.7rem;
  }

  .template-v3.menu-rail .solver-pane,
  .template-v3.menu-rail .tab-content {
    min-height: calc(100vh - 78px);
    max-height: calc(100vh - 78px);
  }

  .template-v3.menu-rail .solver-console {
    grid-template-rows: minmax(260px, 1fr) auto;
    padding: 7px;
    gap: 7px;
  }

  .template-v3.menu-rail .chat-window {
    min-height: 260px;
    padding: 14px 9px;
  }

  .template-v3.menu-rail .question-box {
    padding: 11px;
  }

  .template-v3.menu-rail .prompt-frame {
    min-height: 110px;
    padding: 11px;
  }

  .template-v3.menu-rail #questionInput {
    min-height: 62px;
    font-size: 0.88rem;
  }

  .template-v3.menu-rail .composer-hint {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

@media (max-width: 390px) {
  .template-v3.menu-rail .app-shell,
  .template-v3.menu-rail .app-shell.sidebar-collapsed {
    grid-template-columns: 60px minmax(0, 1fr);
  }

  .template-v3.menu-rail .sidebar,
  .template-v3.menu-rail .app-shell.sidebar-collapsed .sidebar {
    width: 60px;
    min-width: 60px;
    padding-inline: 4px;
  }

  .template-v3.menu-rail .tab-button,
  .template-v3.menu-rail .app-shell.sidebar-collapsed .tab-button {
    font-size: 0.46rem;
  }

  .template-v3.menu-rail .topbar,
  .template-v3.menu-rail .library-header {
    padding-inline: 10px;
  }

  .template-v3.menu-rail .topbar h2,
  .template-v3.menu-rail .library-header h2 {
    font-size: 0.92rem;
  }
}

/* Compact chrome and orbiting calculator toggle */
.template-v3.menu-rail .app-shell,
.template-v3.menu-rail .app-shell.sidebar-collapsed {
  grid-template-rows: 56px minmax(0, 1fr);
}

.template-v3.menu-rail .app-header {
  min-height: 56px;
  padding-inline: 16px;
}

.template-v3.menu-rail .brand-mark {
  width: 32px;
  height: 32px;
  flex-basis: 32px;
  font-size: 0.92rem;
  box-shadow: 4px 4px 0 var(--v3-lime);
}

.template-v3.menu-rail .brand-copy strong {
  font-size: 0.96rem;
}

.template-v3.menu-rail .brand-copy small {
  margin-top: 2px;
  font-size: 0.58rem;
}

.template-v3.menu-rail .sidebar,
.template-v3.menu-rail .app-shell.sidebar-collapsed .sidebar {
  top: 78px;
  min-height: calc(100vh - 90px);
  max-height: calc(100vh - 90px);
}

.template-v3.menu-rail .solver-pane,
.template-v3.menu-rail .tab-content {
  min-height: calc(100vh - 90px);
  max-height: calc(100vh - 90px);
}

.template-v3.menu-rail .topbar,
.template-v3.menu-rail .library-header {
  min-height: 62px;
  padding-block: 10px;
}

.template-v3 .floating-calc-button {
  --calc-orbit-edge: 16px;
  --calc-orbit-size: 58px;
  left: var(--calc-orbit-edge);
  top: var(--calc-orbit-edge);
  right: auto;
  bottom: auto;
  animation: calcViewportOrbit 48s linear infinite;
  will-change: left, top;
}

.template-v3 .floating-calc-button:hover,
.template-v3 .floating-calc-button:focus-visible,
.template-v3 .floating-calc-button:active,
.template-v3:has(.floating-calculator.is-open) .floating-calc-button,
.template-v3:has(.floating-calculator.is-closing) .floating-calc-button {
  animation-play-state: paused;
  transform: none;
}

@keyframes calcViewportOrbit {
  0%, 100% {
    left: var(--calc-orbit-edge);
    top: var(--calc-orbit-edge);
  }
  25% {
    left: calc(100vw - var(--calc-orbit-size) - var(--calc-orbit-edge));
    top: var(--calc-orbit-edge);
  }
  50% {
    left: calc(100vw - var(--calc-orbit-size) - var(--calc-orbit-edge));
    top: calc(100dvh - var(--calc-orbit-size) - var(--calc-orbit-edge));
  }
  75% {
    left: var(--calc-orbit-edge);
    top: calc(100dvh - var(--calc-orbit-size) - var(--calc-orbit-edge));
  }
}

@media (max-width: 600px) {
  .template-v3.menu-rail .app-shell,
  .template-v3.menu-rail .app-shell.sidebar-collapsed {
    grid-template-rows: 52px minmax(0, 1fr);
  }

  .template-v3.menu-rail .app-header {
    min-height: 52px;
    padding-inline: 9px;
  }

  .template-v3.menu-rail .sidebar,
  .template-v3.menu-rail .app-shell.sidebar-collapsed .sidebar {
    top: 64px;
    min-height: calc(100vh - 70px);
    max-height: calc(100vh - 70px);
  }

  .template-v3.menu-rail .solver-pane,
  .template-v3.menu-rail .tab-content {
    min-height: calc(100vh - 70px);
    max-height: calc(100vh - 70px);
  }

  .template-v3.menu-rail .topbar,
  .template-v3.menu-rail .library-header {
    min-height: 58px;
    padding-block: 9px;
  }

  .template-v3 .floating-calc-button {
    --calc-orbit-edge: 10px;
    --calc-orbit-size: 52px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .template-v3 .floating-calc-button {
    left: auto;
    top: auto;
    right: var(--calc-orbit-edge);
    bottom: var(--calc-orbit-edge);
    animation: none;
  }
}
