:root {
  --ink: #17151c;
  --muted: #77717d;
  --paper: #f6f2ea;
  --panel: #fffdf8;
  --accent: #6d42dc;
  --line: #ddd6ca;
  --shadow: 0 20px 60px rgba(48, 36, 54, .11);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Vazirmatn, Tahoma, Arial, system-ui, sans-serif;
  background:
    radial-gradient(circle at 8% 8%, #e8dcff 0, transparent 29%),
    radial-gradient(circle at 92% 88%, #ffdccc 0, transparent 26%),
    var(--paper);
}
body.app-active { height: 100dvh; overflow: hidden; }
button, textarea, input { font: inherit; }
button { border: 0; cursor: pointer; }

.shell {
  width: min(1440px, calc(100% - 28px));
  min-height: 100vh;
  margin: auto;
  display: flex;
  flex-direction: column;
}
.app-active .shell { height: 100dvh; min-height: 0; }
.topbar {
  height: 72px;
  flex: 0 0 72px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding-inline: 5px;
}
.logo { justify-self: start; display: flex; align-items: center; gap: 7px; color: var(--ink); font-size: 24px; font-weight: 800; text-decoration: none; }
.logo img { width: 34px; height: 34px; }
.logo span { color: var(--accent); }
.creator { color: var(--muted); font-size: 10px; text-decoration: none; transition: color .15s; }
.creator:hover { color: var(--accent); }
.ghost { justify-self: end; color: var(--muted); background: transparent; }
.hidden { display: none !important; }

.intro { max-width: 780px; margin: auto; padding: 40px 0 130px; text-align: center; }
.eyebrow { color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: .22em; }
.intro h1 { margin: 18px 0; font-size: clamp(52px, 9vw, 104px); line-height: 1.08; letter-spacing: -.06em; }
.intro h1 em { color: var(--accent); font-style: normal; }
.intro > p:not(.eyebrow) { max-width: 580px; margin: 0 auto 34px; color: var(--muted); font-size: clamp(17px, 2vw, 22px); }
.primary { padding: 15px 26px; border-radius: 18px; color: #fff; background: var(--ink); font-weight: 600; }
.primary span { display: inline-block; margin-right: 15px; }
.intro small { display: block; margin-top: 24px; color: #958e96; }

.workspace {
  flex: 1;
  min-height: 0;
  padding: 8px 0 16px;
  display: grid;
  grid-template-columns: 250px minmax(410px, 1fr) 340px;
  grid-template-areas: "history chat phase";
  gap: 14px;
  direction: ltr;
}
.workspace > * { min-width: 0; direction: rtl; }
.phase-card, .chat-panel, .history-panel {
  min-height: 0;
  border: 1px solid rgba(255, 255, 255, .9);
  border-radius: 26px;
  background: rgba(255, 253, 248, .88);
  box-shadow: var(--shadow);
}

.phase-card {
  grid-area: phase;
  padding: 15px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.art-wrap {
  position: relative;
  width: 100%;
  height: clamp(170px, 26vh, 235px);
  overflow: hidden;
  flex: 0 0 auto;
  border-radius: 20px;
  background: #ddd;
}
.art-wrap img { width: 100%; height: 100%; object-fit: cover; }
.art-wrap > span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 64px;
  text-shadow: 0 3px 20px #0004;
}
.share-block { padding: 9px 2px 2px; }
.share-block > span { color: var(--muted); font-size: 11px; }
.share {
  min-width: 0;
  margin-top: 6px;
  display: flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.share input { width: 0; min-width: 0; flex: 1; padding: 9px; border: 0; background: transparent; direction: ltr; font-size: 10px; }
.share button { padding: 0 10px; color: var(--accent); background: transparent; white-space: nowrap; font-size: 11px; }
.privacy { margin: 5px 2px 0; color: var(--muted); font-size: 9px; }
.phase-copy { padding: 8px 4px 4px; }
.phase-copy > span { color: var(--muted); font-size: 11px; }
.phase-copy h2 { margin: 4px 0; font-size: clamp(20px, 2vw, 26px); line-height: 1.55; }
.phase-copy p { margin: 0; color: var(--muted); font-size: 11px; }
.meters { margin: 3px 4px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.meters label { color: var(--muted); font-size: 11px; }
.meters i { height: 5px; margin-top: 6px; display: block; overflow: hidden; border-radius: 9px; background: #ece6de; }
.meters b { width: 0; height: 100%; display: block; border-radius: 9px; background: var(--accent); transition: width .5s; }
.phase-insights { margin-top: 5px; display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.phase-insights::before { content: "۶ نشانه از فاز تو"; grid-column: 1 / -1; color: var(--accent); font-size: 9px; font-weight: 700; }
.phase-insights > div { min-width: 0; padding: 5px 7px; border: 1px solid #e7dfd4; border-radius: 10px; background: #fff; }
.phase-insights span { display: block; margin-bottom: 3px; color: var(--muted); font-size: 8px; }
.phase-insights strong { display: block; overflow: hidden; font-size: 8.5px; line-height: 1.4; text-overflow: ellipsis; }

.chat-panel { grid-area: chat; overflow: hidden; display: flex; flex-direction: column; }
.messages {
  flex: 1;
  min-height: 0;
  padding: 22px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: #c8bfc8 transparent;
}
.message-row { max-width: 88%; display: flex; align-items: flex-end; gap: 7px; }
.message-row.assistant { align-self: flex-start; }
.message-row.user { align-self: flex-end; flex-direction: row-reverse; }
.mood-avatar {
  width: 33px;
  height: 33px;
  flex: 0 0 33px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  box-shadow: 0 4px 12px #30243612;
  font-size: 17px;
}
.message {
  padding: 12px 16px;
  border-radius: 17px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.9;
}
.message.assistant { border-bottom-right-radius: 5px; background: #f0eae1; }
.message.user { border-bottom-left-radius: 5px; color: #fff; background: var(--ink); }
.recommendations { margin-top: 13px; padding-top: 11px; border-top: 1px solid #d8cfc2; }
.recommendations strong { display: block; margin-bottom: 7px; color: var(--accent); font-size: 11px; }
.recommendations ol { margin: 0; padding-right: 22px; }
.recommendations li { padding: 2px 0; }
.message-link {
  margin-top: 10px;
  padding: 8px 10px;
  display: block;
  border-radius: 9px;
  color: var(--accent);
  background: #fff;
  direction: ltr;
  text-align: left;
  overflow-wrap: anywhere;
}
.thinking { min-height: 45px; display: flex; align-items: center; gap: 5px; }
.thinking-label { margin-left: 5px; color: var(--muted); }
.thinking i { width: 6px; height: 6px; display: block; border-radius: 50%; background: var(--accent); animation: thinking 1.1s infinite ease-in-out; }
.thinking i:nth-of-type(2) { animation-delay: .15s; }
.thinking i:nth-of-type(3) { animation-delay: .3s; }
@keyframes thinking { 0%, 60%, 100% { transform: translateY(0); opacity: .35; } 30% { transform: translateY(-5px); opacity: 1; } }
.chat-panel form {
  margin: 0 16px 14px;
  padding: 7px;
  display: flex;
  align-items: flex-end;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: #fff;
}
.chat-panel textarea { min-width: 0; max-height: 120px; flex: 1; padding: 9px; resize: none; border: 0; outline: 0; background: transparent; }
.chat-panel form button { width: 40px; height: 40px; flex: 0 0 40px; border-radius: 13px; color: #fff; background: var(--accent); font-size: 21px; }
.chat-panel form button:disabled { opacity: .45; cursor: wait; }
.status { height: 18px; margin: -8px 26px 8px; overflow: hidden; color: var(--muted); font-size: 10px; white-space: nowrap; text-overflow: ellipsis; }

.history-panel {
  grid-area: history;
  padding: 18px 12px 13px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.history-head { padding: 0 5px 12px; display: flex; justify-content: space-between; align-items: flex-start; }
.history-head span { color: var(--accent); font-size: 10px; }
.history-head h3 { margin: 3px 0 0; font-size: 17px; }
.history-head button { display: none; color: var(--muted); background: transparent; font-size: 28px; line-height: 1; }
.history-list { min-height: 0; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; scrollbar-width: thin; scrollbar-color: #c8bfc8 transparent; }
.history-item {
  padding: 8px;
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
  transition: transform .15s, border-color .15s;
}
.history-item:hover { transform: translateY(-1px); border-color: #bba8e9; }
.history-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.history-item.current { border-color: #9c7bea; box-shadow: inset 0 0 0 1px #9c7bea; }
.history-item img { width: 62px; height: 62px; object-fit: cover; border-radius: 10px; }
.history-item time { color: var(--muted); font-size: 8px; }
.history-item h4 { margin: 4px 0 7px; overflow: hidden; font-size: 11px; white-space: nowrap; text-overflow: ellipsis; }
.history-stats { display: flex; gap: 4px; }
.history-stats span { padding: 3px 5px; border-radius: 6px; color: var(--muted); background: #f2ede6; font-size: 8px; }
.history-empty { margin: auto 8px; color: var(--muted); font-size: 11px; line-height: 1.8; text-align: center; }
.return-card { margin-top: 10px; padding: 11px; border-radius: 13px; background: #eee7ff; }
.return-card strong { font-size: 11px; }
.return-card p { margin: 4px 0 8px; color: #625b68; font-size: 9px; line-height: 1.65; }
.return-card button { width: 100%; padding: 7px; border-radius: 8px; color: #fff; background: var(--accent); font-size: 9px; }
.return-card small { margin-top: 6px; display: block; color: #7c6c83; font-size: 7px; line-height: 1.5; }
.history-toggle { display: none; }

.confirm-modal {
  width: min(410px, calc(100% - 30px));
  padding: 0;
  border: 0;
  border-radius: 24px;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 30px 100px #17151c40;
}
.confirm-modal::backdrop { background: rgba(23, 21, 28, .42); backdrop-filter: blur(5px); }
.confirm-modal form { padding: 28px; text-align: center; }
.modal-icon { width: 52px; height: 52px; margin: auto; display: grid; place-items: center; border-radius: 17px; color: var(--accent); background: #eee7ff; font-size: 26px; }
.confirm-modal h2 { margin: 15px 0 7px; }
.confirm-modal p { margin: 0 0 22px; color: var(--muted); font-size: 13px; line-height: 1.8; }
.confirm-modal form > div { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.confirm-modal button { padding: 11px; border-radius: 11px; }
.modal-cancel { color: var(--muted); background: #eee9e2; }
.modal-confirm { color: #fff; background: var(--accent); }

.history-detail-modal {
  width: min(700px, calc(100% - 24px));
  max-height: 90vh;
  padding: 0;
  overflow: auto;
  border: 0;
  border-radius: 24px;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 30px 100px #17151c40;
}
.history-detail-modal::backdrop { background: rgba(23, 21, 28, .46); backdrop-filter: blur(5px); }
.history-detail-modal > article { position: relative; padding: 24px; }
.detail-close { position: absolute; top: 13px; left: 13px; width: 34px; height: 34px; border-radius: 11px; color: var(--muted); background: #eee9e2; font-size: 22px; }
.detail-title { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; padding-left: 42px; }
.detail-title img { width: 90px; height: 90px; object-fit: cover; border-radius: 16px; }
.detail-title time { color: var(--muted); font-size: 10px; }
.detail-title h2 { margin: 5px 0 0; font-size: 22px; }
.history-detail-modal section { margin-top: 12px; padding: 13px; border-radius: 14px; background: #f2ede6; }
.history-detail-modal section > span { color: var(--accent); font-size: 10px; font-weight: 700; }
.history-detail-modal section p { margin: 6px 0 0; font-size: 12px; line-height: 1.9; white-space: pre-wrap; }
.history-detail-modal section ol { margin: 7px 0 0; padding-right: 21px; font-size: 12px; line-height: 1.9; }
.detail-insights { margin-top: 12px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.detail-insights > div { padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.detail-insights span { display: block; color: var(--muted); font-size: 9px; }
.detail-insights strong { display: block; margin-top: 4px; font-size: 11px; line-height: 1.55; }
.toast { position: fixed; z-index: 100; right: 50%; bottom: 24px; max-width: calc(100% - 24px); padding: 10px 15px; border-radius: 12px; color: #fff; background: #26202c; box-shadow: 0 12px 40px #17151c4d; font-size: 11px; opacity: 0; pointer-events: none; transform: translate(50%, 16px); transition: .2s; }
.toast.show { opacity: 1; transform: translate(50%, 0); }
.toast.error { background: #9f2f3f; }

@media (max-width: 1120px) {
  .workspace { grid-template-columns: 220px minmax(360px, 1fr) 300px; gap: 10px; }
  .shell { width: min(100% - 18px, 1180px); }
  .phase-card { padding: 12px; }
}

@media (max-width: 860px) {
  body.app-active { overflow: hidden; }
  .shell { width: calc(100% - 14px); }
  .topbar { height: 58px; flex-basis: 58px; }
  .logo { font-size: 20px; }
  .logo img { width: 30px; height: 30px; }
  .creator { font-size: 0; }
  .creator::after { content: "Araz Shahkarami"; font-size: 8px; }
  .workspace {
    position: relative;
    padding: 4px 0 8px;
    grid-template-columns: 1fr;
    grid-template-rows: 174px minmax(0, 1fr);
    grid-template-areas: "phase" "chat";
    gap: 8px;
  }
  .phase-card {
    padding: 9px;
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    column-gap: 10px;
    border-radius: 20px;
  }
  .art-wrap { grid-row: 1 / 4; width: 112px; height: 112px; align-self: center; border-radius: 15px; }
  .art-wrap > span { font-size: 38px; }
  .phase-copy { grid-column: 2; grid-row: 1; padding: 3px 0; }
  .phase-copy h2 { margin: 2px 0; font-size: 16px; line-height: 1.35; }
  .phase-copy p, .phase-copy > span { font-size: 9px; }
  .meters { grid-column: 2; grid-row: 2; width: 100%; margin: 3px 0; align-self: end; }
  .share-block { grid-column: 2; grid-row: 3; padding: 3px 0 0; display: block; }
  .share-block > span, .share-block .privacy, .share-block input { display: none; }
  .share-block .share { height: 28px; margin: 0; }
  .share-block .share button { width: 100%; }
  .share-block .share button::before { content: "لینک تصویر · "; }
  .phase-insights { display: none; }
  .chat-panel { border-radius: 20px; }
  .messages { padding: 14px 10px; }
  .message-row { max-width: 96%; }
  .message { padding: 10px 12px; font-size: 12px; }
  .mood-avatar { width: 29px; height: 29px; flex-basis: 29px; font-size: 15px; }
  .chat-panel form { margin: 0 9px 9px; }
  .status { margin-inline: 15px; }
  .history-toggle {
    position: fixed;
    z-index: 20;
    left: 14px;
    bottom: 100px;
    padding: 9px 12px;
    display: flex;
    align-items: center;
    gap: 7px;
    border: 1px solid #fff;
    border-radius: 14px;
    color: #fff;
    background: var(--accent);
    box-shadow: 0 10px 30px #4f2ba74d;
    font-size: 11px;
  }
  .history-toggle b { min-width: 19px; height: 19px; display: grid; place-items: center; border-radius: 7px; color: var(--accent); background: #fff; font-size: 9px; }
  .history-panel {
    position: fixed;
    z-index: 50;
    inset: 64px 8px 8px;
    padding: 18px 13px;
    border-radius: 23px;
    transform: translateY(calc(100% + 80px));
    transition: transform .28s ease;
  }
  .history-panel.open { transform: translateY(0); }
  .history-head button { display: block; }
  .history-item { grid-template-columns: 72px minmax(0, 1fr); }
  .history-item img { width: 72px; height: 72px; }
  .return-card { margin-top: 8px; }
  .history-detail-modal > article { padding: 18px 13px; }
  .detail-title { padding-left: 38px; }
  .detail-title img { width: 72px; height: 72px; }
  .detail-title h2 { font-size: 17px; }
  .detail-insights { grid-template-columns: 1fr 1fr; }
}

@media (max-height: 700px) and (min-width: 861px) {
  .topbar { height: 58px; flex-basis: 58px; }
  .workspace { padding-top: 3px; }
  .phase-card { padding: 11px; }
  .phase-copy { padding-top: 8px; }
  .return-card p { display: none; }
}
