:root{
  --bg:#0b1020;
  --bgSecondary:#0f1730;
  --text:#e7eaf3;
  --textMuted:#9aa4c3;
  --accent:#7c5cff;
  --accentHover:#6a4ff0;
  --border:rgba(255,255,255,.10);
  --victory:rgba(124,92,255,.12);
  --lesson:rgba(46,212,167,.12);
  --danger:#ff4d6d;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  --radius: 18px;
  --radiusSm: 12px;
  --focus: 0 0 0 3px rgba(124,92,255,.22);
  --glassBg: rgba(15, 23, 48, 0.2);
}

html, body { height: 100%; }
body{
  margin:0;
  background: transparent;
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  transition: background .2s ease, color .2s ease;
  overflow-x: hidden;
}

#app{ min-height: 100vh; }

::selection{ background: rgba(124,92,255,.28); }

.card{
  background: var(--glassBg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.soft{
  background: var(--glassBg);
  border: 1px solid var(--border);
  border-radius: var(--radiusSm);
  backdrop-filter: blur(8px);
}

.btn{
  background: rgba(124, 92, 255, 0.2);
  color: white;
  border-radius: 999px;
  padding: 12px 16px;
  font-weight: 650;
  transition: transform .12s ease, background .2s ease, opacity .2s ease;
  border: 1px solid rgba(124, 92, 255, 0.3);
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.btn:hover{ background: rgba(124, 92, 255, 0.35); }
.btn:active{ transform: translateY(1px); }
.btn:disabled{ opacity: .55; cursor: not-allowed; }

.btn-ghost{
  border: 1px solid var(--border);
  background: rgba(255,255,255,.05);
  border-radius: 999px;
  padding: 12px 16px;
  font-weight: 650;
  transition: background .2s ease, border-color .2s ease;
  color: var(--text);
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.btn-ghost:hover{ background: rgba(255,255,255,.1); border-color: color-mix(in srgb, var(--border) 40%, var(--accent) 60%); }

.btn-danger{
  border: 1px solid rgba(255, 77, 109, 0.3);
  background: rgba(255, 77, 109, 0.2);
  color: color-mix(in srgb, var(--danger) 90%, white);
  backdrop-filter: blur(8px);
}
.btn-danger:hover{ background: rgba(255, 77, 109, 0.3); }

.input, .textarea{
  width: 100%;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 12px;
  outline: none;
  transition: box-shadow .2s ease, border-color .2s ease, background .2s ease;
  color: var(--text);
  box-sizing: border-box;
  backdrop-filter: blur(8px);
}
.textarea{ min-height: 110px; resize: vertical; }
.input:focus, .textarea:focus{ box-shadow: var(--focus); border-color: color-mix(in srgb, var(--accent) 70%, var(--border)); background: rgba(255,255,255,.08); }

/* Password input with toggle */
.pw-wrap{ position: relative; }
.pw-input{ padding-right: 46px; }
.pw-toggle{
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.05);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.pw-toggle:hover{ background: rgba(255,255,255,.1); border-color: color-mix(in srgb, var(--border) 40%, var(--accent) 60%); }

/* AI rewrite button for textareas */
.ai-wrap{ position: relative; }
.ai-textarea{ padding-right: 46px; }
.ai-btn{
  position: absolute;
  right: 8px;
  top: 8px;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.05);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.ai-btn:hover{ background: rgba(255,255,255,.1); border-color: color-mix(in srgb, var(--border) 40%, var(--accent) 60%); }
.ai-btn:disabled{ opacity: .55; cursor: not-allowed; }

/* AI accept/undo mini bar */
.ai-bar{
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.label{ color: var(--textMuted); font-size: 12px; letter-spacing: .02em; }

.link{ color: color-mix(in srgb, var(--accent) 80%, white); text-decoration: none; }
.link:hover{ text-decoration: underline; }

.pill{
  border: 1px solid var(--border);
  background: rgba(255,255,255,.05);
  border-radius: 999px;
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  backdrop-filter: blur(8px);
}

.divider{ height: 1px; background: var(--border); }

.fade-in{ animation: fadeIn .18s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.kbd{ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12px; border: 1px solid var(--border); padding: 2px 6px; border-radius: 8px; background: rgba(255,255,255,.05); backdrop-filter: blur(8px); }

/* Sidebar */
.sidebar-scrim{ background: rgba(0,0,0,.4); }
.sidebar{ 
  background: var(--glassBg); 
  border-right: 1px solid var(--border); 
  backdrop-filter: blur(16px);
}

/* Theme chips */
.theme-dot{
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform .12s ease, border-color .2s ease, box-shadow .2s ease;
  user-select: none;
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255,255,255,.05);
  padding: 0;
  color: inherit;
  font: inherit;
  backdrop-filter: blur(8px);
}
.theme-dot:hover{ transform: translateY(-1px); border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }
.theme-dot[data-active="true"]{ box-shadow: var(--focus); border-color: color-mix(in srgb, var(--accent) 70%, var(--border)); }

.toast{
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: var(--glassBg);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  max-width: min(560px, calc(100vw - 28px));
  z-index: 60;
  backdrop-filter: blur(12px);
}
.hidden{ display:none !important; }

/* Layout helpers (minimal, no Tailwind reliance) */
.container{ width: min(920px, calc(100vw - 32px)); margin: 0 auto; }
.centerShell{ min-height: 100vh; padding: 40px 16px; }
.centerMax{ width: min(720px, calc(100vw - 32px)); margin: 0 auto; }

.header{
  position: sticky;
  top: 0;
  z-index: 40;
  border-bottom: 1px solid var(--border);
  background: var(--glassBg);
  backdrop-filter: blur(16px);
}
.headerRow{ display:flex; align-items:center; justify-content: space-between; gap: 12px; padding: 12px 0; }

.grid{ display: grid; gap: 12px; }
.grid2{ display:grid; gap:12px; grid-template-columns: 1fr; }
@media (min-width: 640px){ .grid2{ grid-template-columns: 1fr 1fr; } }

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

.textMuted{ color: var(--textMuted); }

/* Modal */
.modalWrap{ position:fixed; inset:0; z-index: 80; display:grid; place-items:center; padding: 16px; overscroll-behavior: contain; }
.modalScrim{ position:absolute; inset:0; background: rgba(0,0,0,.4); }
.modalPanel{ 
  position:relative; 
  width: min(720px, calc(100vw - 32px)); 
  max-height: min(82vh, 760px); 
  overflow:auto; 
  overscroll-behavior: contain;
  background: var(--glassBg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(16px);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* --- Telegram-like UI layer (overrides) --- */
:root{
  --radius: 22px;
  --radiusSm: 16px;
  --shadow: 0 18px 55px rgba(0,0,0,.38);
  --shadowSoft: 0 12px 28px rgba(0,0,0,.28);
  --ring: 0 0 0 3px color-mix(in srgb, var(--accent) 26%, transparent);
}

/* Header like Telegram */
.header{
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}
.headerRow{ padding: 10px 0; }

/* Cards and surfaces */
.card{
  background: var(--glassBg);
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  box-shadow: var(--shadowSoft);
}
.soft{
  background: var(--glassBg);
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

/* Buttons */
.btn, .btn-ghost, .btn-danger{
  letter-spacing: .01em;
}
.btn{
  box-shadow: 0 10px 24px rgba(124, 92, 255, 0.15);
  border-color: rgba(124, 92, 255, 0.25);
}
.btn:hover{ filter: brightness(1.1); }

/* Inputs like Telegram */
.input, .textarea{
  background: rgba(255,255,255,.05);
  border-color: color-mix(in srgb, var(--border) 85%, transparent);
}
.input:focus, .textarea:focus{
  box-shadow: var(--ring);
}

/* Date divider like chat day pill */
.divider{ background: color-mix(in srgb, var(--border) 80%, transparent); }

/* Feed as chat timeline */
#feed{ gap: 14px !important; }
#feed article.card{
  background: transparent;
  border: none;
  box-shadow: none;
  backdrop-filter: none;
  padding: 0 !important;
}

/* Bubble feel for victory/lesson blocks inside feed */
#feed article.card .soft{
  border-radius: 22px;
  padding: 12px 14px !important;
  box-shadow: 0 10px 22px rgba(0,0,0,.18);
  backdrop-filter: blur(12px);
  position: relative;
  overflow: hidden;
  background: var(--glassBg);
}

/* Tap-to-edit affordance */
#feed article.card .soft[data-action="entry-edit"]{
  cursor: pointer;
}
#feed article.card .soft[data-action="entry-edit"]:hover{
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}
#feed article.card .soft::before{
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(520px 160px at 20% 0%, rgba(255,255,255,.04), transparent 55%);
  opacity: .85;
}
#feed article.card .soft > *{ position: relative; }

/* Align chat bubbles like Telegram */
#feed article.card[data-mine="1"] .entryHead{ justify-content: flex-end; }
#feed article.card[data-mine="1"] .entryBubbles{ justify-items: end; }
#feed article.card[data-mine="0"] .entryBubbles{ justify-items: start; }

#feed article.card .entryBubbles .soft{
  width: min(640px, 100%);
}
#feed article.card[data-mine="1"] .entryBubbles .soft{
  border-top-right-radius: 8px;
  background: rgba(124, 92, 255, 0.15) !important;
}
#feed article.card[data-mine="0"] .entryBubbles .soft{
  border-top-left-radius: 8px;
}

/* Small tail */
#feed article.card .entryBubbles .soft::after{
  content:"";
  position:absolute;
  bottom: 10px;
  width: 12px;
  height: 12px;
  background: inherit;
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  transform: rotate(45deg);
  border-left: 0;
  border-top: 0;
  opacity: .85;
}
#feed article.card[data-mine="1"] .entryBubbles .soft::after{ right: -6px; }
#feed article.card[data-mine="0"] .entryBubbles .soft::after{ left: -6px; transform: rotate(225deg); }

/* Slightly different tints */
#feed article.card .soft[style*="var(--victory)"]{
  background: rgba(124, 92, 255, 0.15) !important;
}
#feed article.card .soft[style*="var(--lesson)"]{
  background: rgba(46, 212, 167, 0.15) !important;
}

/* Make the date line look like Telegram chip */
#feed > .row{
  margin: 2px 0 4px;
}
#feed > .row .textMuted{
  background: rgba(255,255,255,.08);
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  border-radius: 999px;
  padding: 6px 12px;
  letter-spacing: .14em;
  backdrop-filter: blur(8px);
}

/* Composer: make the input area feel like a chat composer */
#todayForm{
  background: var(--glassBg);
  border-radius: 26px;
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  box-shadow: 0 16px 38px rgba(0,0,0,.22);
  backdrop-filter: blur(16px);
}
@media (max-width: 820px){
  #todayForm{
    position: sticky;
    bottom: 10px;
    z-index: 25;
  }
}
#todayForm .textarea{ min-height: 90px; }

/* Sidebar: smooth */
.sidebar{ backdrop-filter: blur(20px); }
.sidebar-scrim{ background: rgba(0,0,0,.4); }

/* Modal polish */
.modalPanel{ box-shadow: var(--shadow); }

/* AI button: sleek */
.ai-btn{
  background: rgba(255,255,255,.08);
  border-color: color-mix(in srgb, var(--border) 70%, transparent);
  backdrop-filter: blur(12px);
}
.ai-btn:hover{
  border-color: color-mix(in srgb, var(--accent) 52%, var(--border));
}

/* Scrollbar (webkit) */
@supports selector(::-webkit-scrollbar){
  ::-webkit-scrollbar{ height: 10px; width: 10px; }
  ::-webkit-scrollbar-thumb{ background: rgba(255,255,255,.10); border-radius: 999px; border: 2px solid rgba(0,0,0,0); background-clip: padding-box; }
  ::-webkit-scrollbar-thumb:hover{ background: rgba(255,255,255,.16); border: 2px solid rgba(0,0,0,0); background-clip: padding-box; }
}

/* --- Synchronization / Lunar stars layer --- */
:root{
  --lunar-bg-deep: #0a0a0f;
  --lunar-bg: #0d0d14;
  --lunar-bg-raised: #14141f;
  --lunar-bg-hover: #1a1a28;
  --lunar-text: #b8c0cc;
  --lunar-text-bright: #d4dbe8;
  --lunar-text-muted: #7a8599;
  --lunar-border: rgba(150, 160, 180, 0.12);
  --lunar-accent: #8fa4c9;

  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: "Manrope", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

/* When stars canvas is active - let canvas draw the night */
html.l00m-stars-on,
html.l00m-stars-on body{
  background: transparent !important;
}
html.l00m-stars-on body::before{
  opacity: 0 !important;
}

/* Ensure stars appear behind all elements */
.stars-bg {
  z-index: -1 !important;
}

.stars-bg{
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: -1;
}
#starsCanvas{
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: var(--bg);
}

/* Landing-only subtle crystal canvas overlay */
#cosmosRoot{ position: relative; overflow: visible; }
#crystalCanvas{
  position: absolute;
  inset: -70px;
  width: calc(100% + 140px);
  height: calc(100% + 140px);
  z-index: 0;
  pointer-events: none;
  mix-blend-mode: screen;
  opacity: .55;
}
#cosmosRoot > *:not(#crystalCanvas){ position: relative; z-index: 2; }

@media (prefers-reduced-motion: reduce){
  #starsCanvas, #crystalCanvas{ display:none !important; }
}

/* Safe-area support (iOS/Android gesture bars) */
:root{
  --safeTop: env(safe-area-inset-top, 0px);
  --safeBottom: env(safe-area-inset-bottom, 0px);
  --safeLeft: env(safe-area-inset-left, 0px);
  --safeRight: env(safe-area-inset-right, 0px);
}

body{
  padding-left: var(--safeLeft);
  padding-right: var(--safeRight);
}

/* Disabled the dotted pattern to show stars better */
body::before{
  display: none;
}

/* Header: more Telegram-ish proportions */
.header{
  padding-top: var(--safeTop);
}
.headerRow{
  min-height: 52px;
}

/* Icon-like ghost buttons */
.btn-ghost{
  border-radius: 14px;
  padding: 10px 12px;
}

/* Feed bubbles typography */
#feed article.card .soft{
  line-height: 1.45;
  font-size: 14px;
}
#feed article.card .soft > div:first-child{
  opacity: .92;
}

/* More "chat bubble" maximum width on large screens */
#feed article.card .entryBubbles .soft{
  width: min(560px, 100%);
}

/* Make my bubbles slightly more "telegram-blue" tinted by accent */
#feed article.card[data-mine="1"] .entryBubbles .soft{
  box-shadow: 0 14px 30px rgba(124, 92, 255, 0.1);
}

/* Composer as real bottom bar on mobile */
@media (max-width: 820px){
  #todayForm{
    bottom: calc(10px + var(--safeBottom));
    margin-bottom: calc(8px + var(--safeBottom));
  }
  #feedSentinel{ height: 24px; }
  #feedStatus{ padding-bottom: calc(22px + var(--safeBottom)); }
}

/* Textareas: make them feel like Telegram compose fields */
#todayForm .textarea{
  border-radius: 18px;
  padding-top: 12px;
}

/* AI button looks like an in-field action */
.ai-btn{
  backdrop-filter: blur(12px);
}

/* Toast: slightly higher on mobile to avoid gesture bar */
.toast{
  bottom: calc(22px + var(--safeBottom));
}

/* === Make all UI surfaces ~10% opaque so stars are visible === */
:root {
  --ui-bg-mix: 10%;
  --ui-blur: 0px;
}

/* main surfaces */
.card,
.soft,
.header,
.sidebar,
.toast,
.modalPanel,
#todayForm,
.pill,
.theme-dot,
.input,
.textarea,
.pw-toggle,
.ai-btn,
.btn-ghost {
  background: color-mix(in srgb, var(--bgSecondary) var(--ui-bg-mix), transparent) !important;
  backdrop-filter: blur(var(--ui-blur));
}

/* primary / danger buttons (тоже делаем “стеклянными”) */
.btn {
  background: color-mix(in srgb, var(--accent) var(--ui-bg-mix), transparent) !important;
  border-color: color-mix(in srgb, var(--accent) 40%, transparent) !important;
}

.btn-danger {
  background: color-mix(in srgb, var(--danger) var(--ui-bg-mix), transparent) !important;
  border-color: color-mix(in srgb, var(--danger) 40%, transparent) !important;
}

/* chat bubble special-case (my bubble tint) */
#feed article.card[data-mine="1"] .entryBubbles .soft {
  background: color-mix(in srgb, var(--accent) var(--ui-bg-mix), transparent) !important;
}



/* === Force background for OTHER users bubbles === */
:root {
  --ui-bg-mix: 10%;
}

/* обычные пузыри других */
#feed article.card[data-mine="0"] .entryBubbles .soft {
  background: color-mix(in srgb, var(--bgSecondary) var(--ui-bg-mix), transparent) !important;
}

/* если у чужих пузырей фон задаётся как victory/lesson (перебивает общий .soft) */
#feed article.card[data-mine="0"] .entryBubbles .soft[style*="var(--victory)"] {
  background: color-mix(in srgb, var(--victory) var(--ui-bg-mix), transparent) !important;
}

#feed article.card[data-mine="0"] .entryBubbles .soft[style*="var(--lesson)"] {
  background: color-mix(in srgb, var(--lesson) var(--ui-bg-mix), transparent) !important;
}