*, *::before, *::after { box-sizing: border-box; }
    :root {
      --ink: #101012;
      --black: #050506;
      --paper: #faf8f2;
      --soft: #f1eee5;
      --line: #ded7c8;
      --gold: #cfa85a;
      --gold-dark: #9d7433;
      --purple: #513087;
      --purple-soft: #efe8f8;
      --red: #b23b3b;
      --green: #3c7a55;
      --muted: #716b62;
      --white: #ffffff;
      --shadow: 0 18px 40px rgba(10, 10, 12, .14);
      --radius: 8px;
    }

    html, body {
      height: 100%;
      margin: 0;
      background: #171514;
      color: var(--ink);
      font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
      letter-spacing: 0;
      overflow: hidden;
    }

    body {
      display: flex;
      justify-content: center;
      padding: 18px;
    }

    button, input, textarea, select {
      font: inherit;
    }

    button {
      cursor: pointer;
    }

    .phone {
      width: min(100%, 430px);
      height: calc(100vh - 36px);
      min-height: 0;
      background: var(--paper);
      border: 1px solid rgba(255,255,255,.16);
      border-radius: 28px;
      overflow: hidden;
      box-shadow: 0 28px 80px rgba(0,0,0,.45);
      display: grid;
      grid-template-rows: auto 1fr auto;
      position: relative;
    }

    .topbar {
      background: var(--black);
      color: var(--white);
      padding: 26px 20px 22px;
      display: grid;
      gap: 22px;
      border-bottom: 3px solid var(--gold);
    }

    .brand-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 16px;
    }

    .brand-mark {
      width: 154px;
      height: auto;
      display: block;
      filter: invert(1) brightness(2.25) contrast(1.1);
      opacity: .96;
    }

    .header-actions {
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .icon-button {
      min-height: 34px;
      border: 1px solid rgba(255,255,255,.22);
      background: rgba(255,255,255,.06);
      color: var(--white);
      border-radius: 999px;
      padding: 0 10px;
      font-size: 12px;
      font-weight: 700;
    }

    .icon-button {
      min-width: 46px;
      min-height: 46px;
      border-radius: 50%;
      font-size: 22px;
    }

    .language-control {
      position: relative;
    }

    .language-trigger {
      min-height: 40px;
      border: 1px solid rgba(207,168,90,.78);
      background: rgba(255,255,255,.04);
      color: var(--white);
      border-radius: 999px;
      padding: 0 12px;
      display: inline-flex;
      align-items: center;
      gap: 8px;
      font-size: 14px;
      font-weight: 800;
      line-height: 1;
    }

    .language-trigger::after {
      content: "⌄";
      color: #e5c477;
      font-size: 18px;
      line-height: .8;
      transform: translateY(-1px);
    }

    .language-menu {
      position: absolute;
      top: calc(100% + 8px);
      right: 0;
      min-width: 108px;
      padding: 6px;
      background: #111;
      border: 1px solid rgba(207,168,90,.55);
      border-radius: var(--radius);
      box-shadow: 0 18px 40px rgba(0,0,0,.35);
      display: none;
      z-index: 30;
    }

    .language-control.open .language-menu {
      display: grid;
      gap: 4px;
    }

    .language-option {
      border: 0;
      background: transparent;
      color: var(--white);
      min-height: 36px;
      border-radius: 6px;
      padding: 0 8px;
      display: flex;
      align-items: center;
      gap: 8px;
      font-size: 13px;
      font-weight: 800;
    }

    .language-option.active,
    .language-option:hover {
      background: rgba(207,168,90,.2);
    }

    .flag {
      font-size: 18px;
      line-height: 1;
    }

    .hero-mini {
      display: flex;
      align-items: center;
      gap: 12px;
    }

    .avatar {
      width: 66px;
      height: 66px;
      border-radius: 50%;
      object-fit: cover;
      border: 2px solid var(--gold);
      background: var(--soft);
    }

    .hero-copy h1 {
      font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
      margin: 0;
      font-size: 34px;
      line-height: 1;
      font-weight: 500;
      color: var(--white);
    }

    .hero-copy p {
      margin: 8px 0 0;
      color: #e8dec9;
      font-size: 16px;
      font-weight: 400;
    }

    .workspace {
      min-height: 0;
      overflow-y: auto;
      padding: 16px 16px 24px;
      scrollbar-gutter: stable;
      overscroll-behavior: contain;
    }

    .screen {
      display: none;
      animation: enter .18s ease-out;
    }

    .screen.active {
      display: block;
    }

    .thinking-overlay {
      position: absolute;
      inset: 0;
      background: rgba(5, 5, 6, .76);
      display: none;
      align-items: center;
      justify-content: center;
      padding: 22px;
      z-index: 20;
      backdrop-filter: blur(8px);
    }

    .thinking-overlay.active {
      display: flex;
    }

    .thinking-card {
      width: min(100%, 330px);
      background: var(--white);
      border: 1px solid var(--line);
      border-radius: var(--radius);
      padding: 22px;
      text-align: center;
      box-shadow: var(--shadow);
    }

    .thinking-avatar {
      width: 70px;
      height: 70px;
      border-radius: 50%;
      object-fit: cover;
      border: 3px solid var(--gold);
      margin-bottom: 14px;
    }

    .thinking-card h2 {
      margin: 0 0 6px;
      font-size: 19px;
      line-height: 1.2;
    }

    .thinking-card p {
      margin: 0;
      color: var(--muted);
      font-size: 13px;
      line-height: 1.45;
    }

    .thinking-dots {
      display: flex;
      justify-content: center;
      gap: 7px;
      margin-top: 16px;
    }

    .thinking-dots span {
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background: var(--purple);
      animation: thinkingPulse 1.15s infinite ease-in-out;
    }

    .thinking-dots span:nth-child(2) { animation-delay: .15s; }
    .thinking-dots span:nth-child(3) { animation-delay: .3s; }

    @keyframes thinkingPulse {
      0%, 80%, 100% { opacity: .35; transform: translateY(0); }
      40% { opacity: 1; transform: translateY(-5px); }
    }

    @keyframes enter {
      from { opacity: 0; transform: translateY(8px); }
      to { opacity: 1; transform: translateY(0); }
    }

    .panel {
      background: var(--white);
      border: 1px solid var(--line);
      border-radius: var(--radius);
      box-shadow: var(--shadow);
      padding: 16px;
      margin-bottom: 14px;
    }

    .black-panel {
      background: var(--black);
      color: var(--white);
      border-color: #25211a;
    }

    .screen-title {
      margin: 0 0 6px;
      font-size: 22px;
      line-height: 1.1;
      font-weight: 800;
    }

    .eyebrow {
      margin: 0 0 7px;
      color: var(--gold-dark);
      font-size: 11px;
      font-weight: 800;
      letter-spacing: 1.2px;
      text-transform: uppercase;
    }

    .muted {
      color: var(--muted);
      font-size: 13px;
      line-height: 1.45;
    }

    .hero-card {
      min-height: 310px;
      background:
        linear-gradient(90deg, rgba(0,0,0,.66) 0%, rgba(0,0,0,.35) 34%, rgba(0,0,0,0) 58%),
        linear-gradient(180deg, rgba(0,0,0,0) 45%, rgba(0,0,0,.38)),
        url("/static/assets/lucia-banner.jpeg") center center / cover;
      display: flex;
      flex-direction: column;
      justify-content: flex-end;
      padding: 28px 20px 42px;
      color: var(--white);
      border-radius: 0;
      margin: -16px -16px 14px;
    }

    .hero-card p:not(.eyebrow) {
      margin: 14px 0 0;
      max-width: 245px;
      color: #f0e5ce;
      font-size: 13px;
      font-weight: 800;
      line-height: 1.5;
      letter-spacing: 1px;
      text-transform: uppercase;
    }

    .primary,
    .secondary,
    .ghost {
      width: 100%;
      min-height: 48px;
      border-radius: var(--radius);
      font-weight: 800;
      border: 1px solid transparent;
      padding: 0 14px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
    }

    .primary {
      background: linear-gradient(180deg, #e5c477, var(--gold));
      color: #17120a;
      box-shadow: 0 10px 24px rgba(207,168,90,.28);
    }

    .primary:disabled,
    .secondary:disabled,
    .ghost:disabled {
      cursor: not-allowed;
      opacity: .45;
      box-shadow: none;
    }

    .secondary {
      background: var(--purple);
      color: var(--white);
    }

    .ghost {
      background: var(--white);
      border-color: var(--line);
      color: var(--ink);
    }

    .button-grid {
      display: grid;
      gap: 10px;
    }

    .home-actions {
      gap: 12px;
    }

    .home-action {
      min-height: 76px;
      justify-content: space-between;
      padding: 0 20px;
      font-size: 18px;
      text-align: left;
      box-shadow: none;
    }

    .home-action .action-left {
      display: inline-flex;
      align-items: center;
      gap: 16px;
      min-width: 0;
    }

    .action-icon {
      width: 48px;
      height: 48px;
      display: grid;
      place-items: center;
      color: #0d0d0d;
      flex: 0 0 auto;
    }

    .action-icon svg {
      width: 34px;
      height: 34px;
      stroke: currentColor;
      stroke-width: 1.9;
      fill: none;
      stroke-linecap: round;
      stroke-linejoin: round;
    }

    .action-label {
      white-space: normal;
      overflow-wrap: anywhere;
    }

    .action-chevron {
      font-size: 36px;
      line-height: 1;
      font-weight: 500;
      flex: 0 0 auto;
    }

    .home-action.ghost {
      background: rgba(255,255,255,.78);
      border-color: #e1d9ca;
      color: var(--ink);
    }

    .step-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 16px;
      gap: 12px;
    }

    .step-count {
      color: var(--muted);
      font-size: 12px;
      font-weight: 800;
    }

    .progress {
      height: 5px;
      flex: 1;
      background: #ded8cc;
      border-radius: 999px;
      overflow: hidden;
    }

    .progress span {
      display: block;
      height: 100%;
      width: var(--p, 20%);
      background: var(--purple);
    }

    .question {
      margin-bottom: 18px;
    }

    .question h3 {
      margin: 0 0 11px;
      font-size: 17px;
      line-height: 1.25;
    }

    .option-grid {
      display: grid;
      gap: 9px;
    }

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

    .option {
      min-height: 46px;
      border: 1px solid var(--line);
      background: var(--white);
      color: var(--ink);
      border-radius: var(--radius);
      padding: 10px 12px;
      font-weight: 750;
      text-align: center;
    }

    .option.active {
      border-color: var(--gold-dark);
      background: #fbf3df;
      box-shadow: inset 0 0 0 1px var(--gold);
    }

    .hair-levels {
      display: grid;
      grid-template-columns: repeat(10, 1fr);
      gap: 4px;
      margin-top: 6px;
    }

    .level {
      min-height: 50px;
      border: 2px solid transparent;
      border-radius: 6px;
      padding: 0;
      overflow: hidden;
      background: var(--tone);
      color: var(--white);
      display: flex;
      align-items: end;
      justify-content: center;
      font-size: 11px;
      font-weight: 900;
      text-shadow: 0 1px 2px rgba(0,0,0,.6);
    }

    .level.active {
      border-color: var(--purple);
      transform: translateY(-2px);
    }

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

    .target-card {
      position: relative;
      min-height: 112px;
      border: 1px solid var(--line);
      border-radius: var(--radius);
      overflow: hidden;
      background: var(--target-bg);
      color: var(--white);
      display: flex;
      align-items: flex-end;
      justify-content: center;
      padding: 10px;
      font-weight: 900;
      text-shadow: 0 1px 6px rgba(0,0,0,.65);
    }

    .target-card.active {
      outline: 3px solid var(--gold);
    }

    .diagnostic-tone-grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      max-height: 390px;
      overflow-y: auto;
      padding-right: 2px;
    }

    .diagnostic-tone-grid .tone-card {
      min-height: 150px;
      display: grid;
      grid-template-rows: 78px auto auto;
      align-items: start;
    }

    .diagnostic-preview {
      width: 100%;
      height: 78px;
      border-radius: 6px;
      border: 1px solid rgba(16,16,18,.18);
      background: #14100d;
      object-fit: cover;
      display: block;
      margin: 0 0 8px;
      box-shadow: inset 0 0 18px rgba(255,255,255,.08), inset 0 -16px 18px rgba(0,0,0,.24);
    }

    .tone-card.active {
      border-color: var(--gold-dark);
      box-shadow: inset 0 0 0 2px var(--gold);
    }

    .photo-box {
      background: #121212;
      border-radius: var(--radius);
      color: var(--white);
      min-height: 390px;
      height: min(62vh, 560px);
      display: grid;
      place-items: center;
      overflow: hidden;
      border: 1px solid #262626;
      position: relative;
      cursor: default;
    }

    .photo-box img {
      width: 100%;
      height: 100%;
      object-fit: contain;
      display: none;
      background: #080808;
    }

    .photo-box.has-image img {
      display: block;
    }

    .photo-box.has-image .photo-empty {
      display: none;
    }

    .photo-box.has-image {
      cursor: zoom-in;
    }

    .photo-box.has-image .photo-ring {
      display: none;
    }

    .photo-ring {
      position: absolute;
      width: 72%;
      aspect-ratio: 1 / 1.35;
      border: 3px solid rgba(255,255,255,.88);
      border-radius: 50%;
      pointer-events: none;
      z-index: 0;
    }

    .photo-empty {
      position: relative;
      z-index: 1;
      text-align: center;
      padding: 28px;
      max-width: 88%;
      text-shadow: 0 1px 8px rgba(0,0,0,.65);
    }

    .photo-empty strong {
      display: block;
      margin-bottom: 8px;
      font-size: 18px;
    }

    #photoInput {
      display: none;
    }

    .photo-viewer {
      position: fixed;
      inset: 0;
      z-index: 70;
      display: none;
      align-items: center;
      justify-content: center;
      padding: 18px;
      background: rgba(0, 0, 0, .9);
    }

    .photo-viewer.open {
      display: flex;
    }

    .photo-viewer img {
      width: 100%;
      height: 100%;
      max-width: 980px;
      max-height: 92vh;
      object-fit: contain;
      border-radius: 8px;
      box-shadow: 0 18px 60px rgba(0, 0, 0, .45);
    }

    .photo-viewer-close {
      position: absolute;
      top: 14px;
      right: 14px;
      width: 42px;
      height: 42px;
      border: 1px solid rgba(255, 255, 255, .36);
      border-radius: 50%;
      background: rgba(0, 0, 0, .48);
      color: #fff;
      font-size: 24px;
      line-height: 1;
      cursor: pointer;
    }

    .result-grid {
      display: grid;
      gap: 10px;
    }

    .recommendation-stack {
      display: grid;
      gap: 10px;
    }

    #formulaLines,
    #applicationSteps {
      display: grid;
      gap: 10px;
    }

    .metric {
      border: 1px solid var(--line);
      background: var(--white);
      border-radius: var(--radius);
      padding: 12px;
      display: flex;
      align-items: center;
      gap: 10px;
    }

    .metric-icon {
      width: 36px;
      height: 36px;
      border-radius: 50%;
      display: grid;
      place-items: center;
      background: var(--purple-soft);
      color: var(--purple);
      font-weight: 900;
    }

    .metric strong {
      display: block;
      font-size: 15px;
    }

    .metric span {
      color: var(--muted);
      font-size: 12px;
      font-weight: 700;
    }

    .formula-line {
      display: grid;
      grid-template-columns: 1fr auto;
      align-items: center;
      gap: 10px;
      padding: 12px;
      border: 1px solid var(--line);
      border-radius: var(--radius);
      background: var(--white);
    }

    .recommendation-stack .primary {
      margin-top: 4px;
    }

    .tone-chip {
      min-width: 50px;
      padding: 7px 9px;
      border-radius: 6px;
      background: var(--black);
      color: var(--white);
      font-weight: 900;
      text-align: center;
    }

    .warning {
      display: flex;
      gap: 10px;
      align-items: flex-start;
      padding: 12px;
      border: 1px solid #e4c9c9;
      border-radius: var(--radius);
      background: #fffafa;
      color: var(--red);
      font-size: 13px;
      font-weight: 700;
      margin-bottom: 10px;
    }

    .warning:last-child {
      margin-bottom: 0;
    }

    .chat {
      display: grid;
      gap: 12px;
    }

    .bubble {
      padding: 12px 14px;
      border-radius: var(--radius);
      line-height: 1.45;
      font-size: 14px;
      white-space: pre-wrap;
    }

    .bubble h3 {
      margin: 10px 0 6px;
      font-size: 15px;
      line-height: 1.25;
    }

    .bubble p {
      margin: 0 0 9px;
    }

    .bubble p:last-child {
      margin-bottom: 0;
    }

    .bubble ul {
      margin: 6px 0 9px 18px;
      padding: 0;
    }

    .bubble li {
      margin-bottom: 5px;
    }

    .bubble.lucia {
      background: var(--purple-soft);
      border: 1px solid #d8c7ec;
    }

    .bubble.typing {
      width: 58px;
      min-height: 38px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      padding: 10px 13px;
      border-radius: 16px;
      border-bottom-left-radius: 5px;
      white-space: normal;
    }

    .typing-dots {
      display: inline-flex;
      align-items: center;
      gap: 4px;
    }

    .typing-dots span {
      width: 6px;
      height: 6px;
      border-radius: 50%;
      background: var(--purple);
      animation: chatTypingPulse 1.2s infinite ease-in-out;
    }

    .typing-dots span:nth-child(2) { animation-delay: .15s; }
    .typing-dots span:nth-child(3) { animation-delay: .3s; }

    @keyframes chatTypingPulse {
      0%, 80%, 100% { opacity: .42; transform: translateY(0); }
      40% { opacity: 1; transform: translateY(-3px); }
    }

    .bubble.user {
      background: var(--black);
      color: var(--white);
      justify-self: end;
      max-width: 88%;
    }

    .chat-input-row {
      display: grid;
      grid-template-columns: 1fr auto;
      gap: 8px;
      margin-top: 10px;
    }

    .chat-input-row textarea {
      min-height: 46px;
      border: 1px solid var(--line);
      border-radius: var(--radius);
      padding: 12px;
      background: var(--white);
      resize: none;
      outline: none;
    }

    .chat-input-row textarea:disabled {
      background: #f3f0e8;
      color: var(--muted);
      cursor: not-allowed;
    }

    .small-send {
      min-width: 48px;
      border: 0;
      border-radius: var(--radius);
      background: var(--purple);
      color: var(--white);
      font-weight: 900;
    }

    .small-send:disabled {
      background: #b8ac9a;
      cursor: not-allowed;
      opacity: .78;
    }

    .catalog-tabs {
      display: flex;
      gap: 8px;
      overflow-x: auto;
      padding-bottom: 8px;
      margin-bottom: 10px;
    }

    .tab {
      min-height: 34px;
      border: 1px solid var(--line);
      border-radius: 999px;
      background: var(--white);
      color: var(--ink);
      padding: 0 12px;
      font-size: 12px;
      font-weight: 800;
      white-space: nowrap;
    }

    .tab.active {
      background: var(--purple);
      border-color: var(--purple);
      color: var(--white);
    }

    .tone-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 10px;
    }

    .tone-card {
      border: 1px solid var(--line);
      border-radius: var(--radius);
      background: var(--white);
      padding: 10px 8px;
      text-align: center;
      min-height: 112px;
    }

    #toneGrid .tone-card {
      display: grid;
      grid-template-rows: 78px auto 1fr;
      align-items: start;
    }

    .swatch {
      width: 54px;
      height: 54px;
      margin: 0 auto 8px;
      border-radius: 50%;
      background: var(--c);
      box-shadow: inset 0 0 18px rgba(255,255,255,.15), inset 0 -10px 14px rgba(0,0,0,.22);
    }

    .tone-card strong {
      display: block;
      font-size: 15px;
    }

    .tone-card span {
      display: block;
      color: var(--muted);
      font-size: 11px;
      font-weight: 700;
      line-height: 1.25;
    }

    .history-list {
      display: grid;
      gap: 10px;
    }

    .history-item {
      display: grid;
      grid-template-columns: 48px 1fr auto;
      gap: 10px;
      align-items: center;
      padding: 10px;
      border: 1px solid var(--line);
      border-radius: var(--radius);
      background: var(--white);
    }

    .history-thumb {
      width: 48px;
      height: 48px;
      border-radius: 6px;
      background: var(--c);
    }

    .history-item strong,
    .history-item span {
      display: block;
    }

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

    .bottom-nav {
      display: grid;
      grid-template-columns: repeat(5, 1fr);
      border-top: 1px solid var(--line);
      background: var(--white);
    }

    .nav-btn {
      min-height: 62px;
      background: var(--white);
      border: 0;
      color: var(--muted);
      display: grid;
      place-items: center;
      gap: 2px;
      font-size: 11px;
      font-weight: 800;
      padding: 7px 2px;
    }

    .nav-btn span {
      display: block;
      font-size: 18px;
      line-height: 1;
    }

    .nav-btn .lucia-nav-icon {
      width: 24px;
      height: 24px;
      display: grid;
      place-items: center;
    }

    .lucia-nav-icon svg {
      width: 24px;
      height: 24px;
      display: block;
      fill: none;
      stroke: currentColor;
      stroke-width: 1.9;
      stroke-linecap: round;
      stroke-linejoin: round;
    }

    .nav-btn.active {
      color: var(--purple);
    }

    .footer-actions {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 10px;
      margin-top: 12px;
    }

    .hidden {
      display: none !important;
    }

    @media (max-width: 520px) {
      body { padding: 0; background: var(--paper); }
      .phone {
        height: 100dvh;
        min-height: 0;
        width: 100%;
        border: 0;
        border-radius: 0;
        box-shadow: none;
      }
      .topbar {
        padding: max(14px, env(safe-area-inset-top)) 14px 14px;
        gap: 14px;
      }
      .brand-row {
        gap: 10px;
      }
      .brand-mark {
        width: 128px;
      }
      .header-actions {
        gap: 6px;
      }
      .language-trigger {
        min-height: 36px;
        padding: 0 10px;
        gap: 6px;
        font-size: 13px;
      }
      .language-trigger::after {
        font-size: 15px;
      }
      .icon-button {
        min-width: 38px;
        min-height: 38px;
        font-size: 18px;
        padding: 0;
      }
      .hero-mini {
        gap: 10px;
      }
      .avatar {
        width: 50px;
        height: 50px;
      }
      .hero-copy h1 {
        font-size: 30px;
      }
      .hero-copy p {
        margin-top: 4px;
        font-size: 14px;
      }
      .workspace {
        padding: 12px 14px calc(18px + env(safe-area-inset-bottom));
      }
      .hero-card {
        min-height: clamp(210px, 34dvh, 285px);
        padding: 18px 14px 28px;
        margin: -12px -14px 12px;
      }
      .hero-card p:not(.eyebrow) {
        max-width: 275px;
        font-size: 12px;
        line-height: 1.35;
      }
      .home-actions {
        gap: 10px;
      }
      .home-action {
        min-height: 64px;
        padding: 0 16px;
        font-size: 17px;
      }
      .home-action .action-left {
        gap: 12px;
      }
      .action-icon {
        width: 40px;
        height: 40px;
      }
      .action-icon svg {
        width: 30px;
        height: 30px;
      }
      .action-chevron {
        font-size: 30px;
      }
      .bottom-nav {
        padding-bottom: env(safe-area-inset-bottom);
      }
    }
