/* Джаганнатха Хора по-русски — оформление страницы. Цвета карты и размеры задаются переменными,
   которые страница меняет из «Настроек вида». */
:root {
  --bg: #f3efe6; --panel: #fbfaf6; --line: #d9d2c1; --ink: #2b2a27; --muted: #7b756a;
  --accent: #8a3b2a; --hi: #efe6cf;
  /* настраиваемые */
  --lagna: #b0128f; --planet: #a8322a; --upagraha: #3f6b3a; --special: #7a6a3a; --sphuta: #5a4a8a; --varnada: #8a6a2a; --arudha: #2c8a85;
  --chart-bg: #fffdf8; --chart-line: #3a3a3a; --chart-num: #5a7a52;
  --c1: 210px; --c2: 30%; --r2: 50%; --r3: 54%; --r4: 52%;
  --head: 52px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.4 "Segoe UI", system-ui, sans-serif; overflow: hidden; display: flex; flex-direction: column; }
button, input, select { font: inherit; color: inherit; }
button { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 5px 12px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.small { padding: 2px 8px; font-size: 13px; }
header { flex: none; display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; min-height: var(--head); }
header h1 { font-size: 16px; margin: 0 8px 0 0; font-weight: 600; }
#summary { color: var(--muted); margin-left: auto; text-align: right; }
#summary b { color: var(--ink); }
.muted { color: var(--muted); }
/* шаг времени для ректификации */
#timebar { display: none; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; background: #fff; }
#timebar.on { display: flex; }
#timebar select { border: 0; background: none; }
#timebar #tbDate { font-variant-numeric: tabular-nums; margin-right: 4px; }
#timebar #tbDate.pending { color: #999; }  /* дата уже новая, карта ещё считается */

/* раскладка: 6 ячеек; блоки перетаскиваются между ячейками, перегородки тянутся мышью */
.layout { display: grid; grid-template-columns: var(--c1) 6px var(--c2) 6px minmax(0, 1fr); padding: 8px 10px 10px; flex: 1; min-height: 0; }
.layout.drag * { user-select: none; }
.col { display: grid; min-height: 0; height: 100%; }
.col.b { grid-template-rows: var(--r2) 6px minmax(0, 1fr); }
.col.c { grid-template-rows: var(--r3) 6px minmax(0, 1fr); }
.row { display: grid; grid-template-columns: var(--r4) 6px minmax(0, 1fr); min-height: 0; min-width: 0; height: 100%; }
.slot { min-height: 0; min-width: 0; display: flex; }
.slot > .box { flex: 1; }
.slot.over { outline: 2px dashed var(--accent); outline-offset: -3px; border-radius: 8px; }
.gut { background: transparent; }
.gut.v { cursor: col-resize; }
.gut.h { cursor: row-resize; }
.gut:hover, .gut.on { background: var(--line); border-radius: 3px; }
.box { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.box.dragging { opacity: .4; }
.ghost { position: fixed; z-index: 50; pointer-events: none; background: var(--panel); border: 1px solid var(--accent); border-radius: 6px; padding: 4px 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink); box-shadow: 0 6px 18px rgba(0,0,0,.2); }
.box > h2, .box > .chead { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0; padding: 7px 10px; border-bottom: 1px solid var(--line); font-weight: 600; cursor: grab; }
.box > h2 { display: flex; align-items: center; gap: 6px; }
.handle::before { content: "⋮⋮"; letter-spacing: -2px; color: var(--line); margin-right: 6px; font-weight: 400; }
.chead { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; }  /* метка «от N-го дома» в узком блоке переносится, а не обрезается */
.chead h3 { margin: 0; font-size: 12px; font-weight: 600; flex: 1; }
.chead select { flex: 1; max-width: 220px; text-transform: none; letter-spacing: 0; font-size: 12px; border: 1px solid var(--line); border-radius: 4px; background: #fff; padding: 1px 4px; cursor: pointer; }
.scroll { overflow: auto; min-height: 0; flex: 1; }
/* список карт */
#blk-files .dir { padding: 6px 8px; border-bottom: 1px solid var(--line); }
#blk-files .dir input { width: 100%; border: 1px solid var(--line); border-radius: 4px; padding: 3px 5px; font-size: 12px; background: #fff; }
#list div { padding: 5px 10px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#list div:hover { background: var(--hi); }
#list div.on { background: var(--hi); font-weight: 600; }
/* карты-ромбы */
.chartbox .chartwrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 4px 8px 8px; }
.chartbox svg { width: 100%; height: 100%; max-height: 100%; }
svg .frame { fill: var(--chart-bg); stroke: var(--chart-line); stroke-width: .5; }
svg .grid line { stroke: var(--chart-line); stroke-width: .45; }
svg text { font-family: "Segoe UI", system-ui, sans-serif; pointer-events: none; user-select: none; }
svg .lbl { font-family: var(--f-chart-family); font-weight: var(--f-chart-weight); font-style: var(--f-chart-style); }
svg .num { fill: var(--chart-num); font-family: var(--f-num-family); font-weight: var(--f-num-weight); font-style: var(--f-num-style); }
/* дома карты: ПКМ — «смотреть от этого дома» */
svg .hs { fill: transparent; }
.chartbox svg .hs:hover { fill: rgba(138, 59, 42, .07); }
.chead .from { text-transform: none; letter-spacing: 0; background: var(--accent); color: #fff; border-radius: 10px; padding: 1px 8px; cursor: pointer; white-space: nowrap; }
.chead .png { margin-left: auto; text-transform: none; letter-spacing: 0; font-size: 11px; padding: 1px 7px; }
#ctx { position: fixed; z-index: 60; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.2); padding: 4px; min-width: 200px; }
#ctx .hd { font-size: 12px; color: var(--muted); padding: 4px 8px; }
#ctx button { display: block; width: 100%; text-align: left; border: 0; background: none; border-radius: 5px; padding: 5px 8px; }
#ctx button:hover { background: var(--hi); }
#moment { flex: none; background: #e9eef8; border: 1px solid #b9c5dd; border-radius: 6px; padding: 6px 10px; margin: 8px 10px 0; }
#moment[hidden], #ctx[hidden] { display: none; }
svg .lagna { fill: var(--lagna); } svg .planet { fill: var(--planet); }
svg .upagraha { fill: var(--upagraha); } svg .special { fill: var(--special); }
svg .sphuta { fill: var(--sphuta); } svg .varnada { fill: var(--varnada); } svg .arudha { fill: var(--arudha); }
/* таблица */
table { border-collapse: collapse; width: 100%; }
#blk-table table { font: var(--f-table-style) var(--f-table-weight) var(--f-table-size)/1.4 var(--f-table-family); }
#keyinfo table { font: var(--f-panel-style) var(--f-panel-weight) var(--f-panel-size)/1.4 var(--f-panel-family); }
#list { font: var(--f-files-style) var(--f-files-weight) var(--f-files-size)/1.4 var(--f-files-family); }
th, td { padding: 3px 9px; text-align: left; white-space: nowrap; }
thead th { position: sticky; top: 0; background: var(--panel); border-bottom: 1px solid var(--line); font-weight: 600; font-size: 12px; color: var(--muted); }
tbody tr:nth-child(even) { background: #f6f2e8; }
td.c { text-align: center; }
.k-lagna { color: var(--lagna); } .k-planet { color: var(--planet); } .k-upagraha { color: var(--upagraha); } .k-special { color: var(--special); }
.k-sphuta { color: var(--sphuta); } .k-varnada { color: var(--varnada); } .k-arudha { color: var(--arudha); }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs .handle { padding: 7px 0 7px 10px; font-size: 12px; color: var(--muted); cursor: grab; }
.tabs button { border: 0; border-radius: 0; background: none; padding: 7px 12px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
#keyinfo table td:first-child { color: var(--upagraha); width: 1%; padding-right: 16px; }
/* Вимшоттари: дерево периодов */
#dasha { padding: 6px 8px 10px; font: var(--f-dasha-style) var(--f-dasha-weight) var(--f-dasha-size)/1.35 var(--f-dasha-family); }
/* силы: три таблицы, шрифт — как у панели «Ключевое» */
#strengths { padding: 4px 8px 10px; font: var(--f-panel-style) var(--f-panel-weight) var(--f-panel-size)/1.4 var(--f-panel-family); }
#strengths h4 { margin: 10px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
#strengths table.st { border-collapse: collapse; width: 100%; }
#strengths table.st th { text-align: left; font-weight: 600; color: var(--muted); padding: 2px 8px 2px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
#strengths table.st td { padding: 2px 8px 2px 0; vertical-align: top; border-bottom: 1px solid #f0ebe0; }
#strengths table.st td:first-child { color: var(--planet); white-space: nowrap; }
#strengths table.st td.c { white-space: nowrap; font-variant-numeric: tabular-nums; }
#strengths .gl { color: var(--muted); font-size: 90%; }
#strengths table.st td.b { font-weight: 600; }
#dasha .nowline { background: var(--hi); border-radius: 6px; padding: 5px 10px; margin-bottom: 6px; }
#dasha .dr { position: relative; display: grid; grid-template-columns: 14px 10px minmax(4.5em, auto) 1fr auto 24px; align-items: center; gap: 6px;
  padding: 3px 4px 3px calc(4px + var(--ind) * 18px); border-radius: 5px; cursor: pointer; white-space: nowrap; }
#dasha .dr:hover { background: #f1ecde; }
#dasha .dr.leaf { cursor: default; }
#dasha .d1 { font-weight: 600; padding-top: 5px; padding-bottom: 5px; border-top: 1px solid var(--line); border-radius: 0; }
#dasha .d1:first-of-type { border-top: 0; }
#dasha .tw { color: var(--muted); font-size: .8em; transition: transform .12s; display: inline-block; text-align: center; }
#dasha .dr.open > .tw { transform: rotate(90deg); }
#dasha .dot { width: 9px; height: 9px; border-radius: 50%; }
#dasha .dt { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 400; overflow: hidden; text-overflow: ellipsis; }
#dasha .dt small { font-size: .85em; opacity: .8; }
#dasha .len { color: var(--muted); font-size: .86em; font-weight: 400; text-align: right; }
#dasha .go { border: 0; background: none; padding: 0 3px; color: var(--muted); opacity: 0; font-size: 1.05em; line-height: 1; }
#dasha .dr:hover .go, #dasha .dr.picked .go { opacity: 1; }
#dasha .go:hover { color: var(--accent); }
#dasha .now > .nm { color: var(--accent); font-weight: 600; }
#dasha .picked { background: #e9eef8; }
#dasha .bar { position: absolute; left: calc(34px + var(--ind) * 18px); right: 34px; bottom: 0; height: 2px; background: var(--line); border-radius: 1px; }
#dasha .bar b { display: block; height: 100%; background: var(--accent); border-radius: 1px; }
#dasha .kids[hidden] { display: none; }
#dasha .note { padding: 10px 4px 0; font-size: 12px; white-space: normal; font-weight: 400; font-style: normal; }
#av { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 10px; padding: 6px 10px; }
#av figure { margin: 0; text-align: center; }
#av figcaption { font-size: 12px; color: var(--planet); }
#av svg text { font: var(--f-av-style) var(--f-av-weight) var(--f-av-size) var(--f-av-family); fill: #26407a; }
#av svg .own { fill: #e3ddcc; }
#av svg .frame { fill: none; }
.note { color: var(--muted); padding: 10px; }
#warn { flex: none; display: none; background: #fff3c4; border: 1px solid #d9b84a; border-radius: 6px; padding: 7px 10px; margin: 8px 10px 0; }
/* диалоги */
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; background: var(--panel); color: var(--ink); min-width: 480px; max-width: 92vw; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(40, 34, 20, .25); }
dialog h2 { margin: 0; padding: 12px 16px; font-size: 16px; border-bottom: 1px solid var(--line); }
dialog .body { padding: 12px 16px; display: grid; grid-template-columns: 130px 1fr; gap: 8px 10px; align-items: center; max-height: 75vh; overflow: auto; }
dialog .foot { padding: 10px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; align-items: center; }
dialog .foot .muted { margin-right: auto; font-size: 12px; }
dialog input[type=number], dialog input[type=text], dialog select { border: 1px solid var(--line); border-radius: 5px; padding: 4px 6px; background: #fff; }
dialog input[type=number] { width: 70px; }
dialog input[type=range] { width: 160px; vertical-align: middle; }
.rowf { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.hint { grid-column: 1 / -1; color: var(--muted); font-size: 12px; margin-top: -4px; }
/* выпадающий список городов */
.citywrap { position: relative; }
.citywrap input { width: 100%; }
#cities { position: absolute; left: 0; right: 0; top: 100%; z-index: 10; max-height: 230px; overflow: auto; border: 1px solid var(--line); border-radius: 0 0 6px 6px; background: #fff; box-shadow: 0 8px 20px rgba(0,0,0,.15); }
#cities .opt { padding: 4px 8px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
#cities .opt span { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#cities .opt:hover, #cities .opt.sel { background: var(--hi); }
#tznote { grid-column: 2; color: var(--muted); font-size: 12px; }
/* настройки вида */
.set .colors { display: grid; grid-template-columns: repeat(3, auto); gap: 4px 14px; }
.set .colors label { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.set input[type=color] { width: 30px; height: 22px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: #fff; cursor: pointer; }
#sBodies { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 16px; }
#sBodies .grp { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
#sBodies .grp > label { font-weight: 600; display: flex; gap: 6px; align-items: center; }
#sBodies .grp .items { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px 10px; margin-top: 4px; font-size: 13px; }
#sBodies .grp .items label { display: flex; gap: 5px; align-items: center; white-space: nowrap; }
#sBodies .grp .items label i { font-style: normal; color: var(--muted); font-size: 12px; }
/* шрифты по блокам */
#sFonts { grid-column: 1 / -1; display: grid; gap: 4px; }
#sFonts .fr { display: grid; grid-template-columns: 170px 1fr 74px 34px 34px; gap: 6px; align-items: center; }
#sFonts .fh { color: var(--muted); font-size: 12px; }
#sFonts input[type=text] { width: 100%; }
#sFonts .tg { display: flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 5px; height: 28px; cursor: pointer; background: #fff; }
#sFonts .tg input { display: none; }
#sFonts .tg:has(input:checked) { background: var(--accent); border-color: var(--accent); color: #fff; }
#dlgSet { min-width: 620px; }
/* карта в PNG */
#dlgPng { min-width: 760px; }
.pngbody { display: grid; grid-template-columns: 340px 1fr; gap: 16px; padding: 14px 16px; align-items: start; }
#pngPrev { background: repeating-conic-gradient(#e6e2d8 0% 25%, #f6f3ec 0% 50%) 0 0 / 16px 16px; border-radius: 8px; padding: 10px; }
#pngPrev svg { display: block; width: 100%; height: auto; }
.pngopts { display: grid; grid-template-columns: 90px 1fr; gap: 8px 10px; align-items: center; }
.pngopts input[type=text] { width: 100%; }
.pngopts .chk { display: flex; gap: 6px; align-items: center; }
.pngopts .colors { display: grid; grid-template-columns: repeat(2, auto); gap: 4px 14px; }
.pngopts .colors label { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.pngopts input[type=color] { width: 30px; height: 22px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: #fff; cursor: pointer; }

/* чогадии и хоры дня (под «Ключевым») */
.daytable { margin: 8px 4px 4px; }
.daytable summary { cursor: pointer; color: var(--muted); font-size: 12px; padding: 4px 0; }
#keyinfo .daytable table td:first-child { color: inherit; width: auto; padding-right: 9px; }
.daytable td { font-size: 12px; }
.daytable td.now { font-weight: 700; background: #efe6cf; }
.daytable .dim { color: var(--muted); font-size: 11px; }
.daytable .note { padding: 4px 0; font-size: 11px; }
/* свои обозначения тел в «Что рисовать» */
#sBodies input.abbr { width: 4.2em; margin-left: 4px; padding: 1px 4px; font: italic 12px/1.3 inherit; border: 1px solid var(--line); border-radius: 3px; background: transparent; }
#sBodies input.abbr:not(:placeholder-shown) { font-style: normal; font-weight: 600; background: #fff; }
/* вкладка «База Д. А.» */
#wiki .wr { padding: 6px 4px 2px; border-bottom: 1px solid var(--line, #ddd); }
#wiki h4 { margin: 4px 0; }
#wiki .wp summary { cursor: pointer; white-space: normal; padding: 2px 0; }
#wiki h5 { margin: 8px 0 2px; }
#wiki ul { margin: 2px 0 6px 18px; padding: 0; white-space: normal; }
#wiki .wq { font-style: italic; margin: 2px 0 4px 10px; }

#mtabs { display: none; }
#wiki p { margin: 3px 0 6px; white-space: normal; }
#wiki h4 .dim { font-weight: 400; }

/* Телефон (мини-апп Telegram, узкий экран): вкладки вверху (#mtabs) вместо раскладки из шести блоков.
   Карта — список карт, D-1, D-9; Положения — таблица и «Ключевое»; Даша; Справка; Силы — силы и аштакаварга.
   Страница прокручивается целиком, перетаскивание и перегородки не нужны. */
@media (max-width: 760px) {
  html, body { height: auto; }
  body { overflow: auto; font-size: 15px; }
  header { padding: 6px 10px; gap: 6px; }
  header h1 { width: 100%; font-size: 15px; }
  header button { padding: 5px 9px; }
  #bQuit, #bDownload, #bOpen { display: none; }
  #summary { margin-left: 0; text-align: left; width: 100%; font-size: 13px; }
  body:not([data-m="chart"]) header > :not(#summary) { display: none; }
  #mtabs { display: flex; position: sticky; top: 0; z-index: 5; background: var(--panel); border-bottom: 1px solid var(--line); }
  #mtabs button { flex: 1; border: 0; border-radius: 0; background: none; padding: 9px 2px; font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent; }
  #mtabs button.on { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
  .layout { display: flex; flex-direction: column; gap: 10px; padding: 8px; }
  .layout .col, .layout .row, .layout .slot { display: contents; }
  .gut { display: none; }
  .box { flex: none !important; overflow: visible; display: none; }
  body[data-m="chart"] #blk-files, body[data-m="chart"] #blk-top, body[data-m="chart"] #blk-bottom,
  body[data-m="pos"] #blk-table, body[data-m="pos"] #blk-panel, body[data-m="dasha"] #blk-panel,
  body[data-m="ref"] #blk-panel, body[data-m="more"] #blk-panel, body[data-m="more"] #blk-av { display: flex; }
  .box > h2, .box > .chead { cursor: default; }
  #blk-files { order: 1; }
  #blk-top { order: 2; }
  #blk-bottom { order: 3; }
  #blk-table { order: 4; }
  #blk-panel { order: 5; }
  #blk-av { order: 6; }
  #blk-panel .tabs { display: none; }
  #blk-files .scroll { max-height: 190px; }
  .chartbox .chartwrap { padding: 4px 6px 8px; }
  .chartbox .chartwrap svg { width: 100%; height: auto; max-height: none; aspect-ratio: 1; }
  #blk-table .scroll { overflow: auto; max-height: 60vh; }
  #blk-panel .scroll { overflow: visible; }
  th, td { padding: 3px 6px; }
  #wiki .wr { padding: 8px 6px 4px; }
  dialog .body { grid-template-columns: 1fr; }
}
