/* Trang /lap-la-so: công cụ lập lá số riêng, không dùng header/footer trang chủ.
   Máy tính: cột trái (thanh nhập + tùy chọn), lá số bên phải; có thể chia đôi màn hình.
   Điện thoại: một dòng tóm tắt, lá số rộng hết màn hình, tùy chọn ở dưới. */
@font-face {
  font-family: "Be Vietnam Pro";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/lap-la-so/fonts/BeVietnamPro-Regular.ttf") format("truetype");
}
@font-face {
  font-family: "Be Vietnam Pro";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/lap-la-so/fonts/BeVietnamPro-SemiBold.ttf") format("truetype");
}
@font-face {
  font-family: "Be Vietnam Pro";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/lap-la-so/fonts/BeVietnamPro-Bold.ttf") format("truetype");
}

/* Fraunces: font chữ "Tử Vi Thanh Dương" cạnh logo trang chủ, dùng cho tiêu đề lá số. */
@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/lap-la-so/fonts/Fraunces.ttf") format("truetype");
}

:root {
  --brand: #0f3b2e;
  --brand-2: #164d3c;
  --accent: #e8b54a;
  --accent-ink: #2a1f05;
  --page: #eef0ea;
  --card: #ffffff;
  --ink: #1d2622;
  --muted: #56625b;
  --line: #d9ddd5;
  --field: #f6f7f3;
  --focus: #c8901f;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 59, 46, 0.06), 0 8px 24px rgba(15, 59, 46, 0.08);
  --font: "Be Vietnam Pro", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --side: 288px;
  --gap: 16px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
}
button, input, select { font: inherit; color: inherit; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Bố cục ---------- */
.workspace {
  display: grid;
  gap: var(--gap);
  padding: var(--gap);
  max-width: 1600px;
  margin: 0 auto;
}

.panel {
  display: grid;
  grid-template-columns: var(--side) minmax(0, 1fr);
  gap: var(--gap);
  align-items: start;
  min-width: 0;
}

/* ---------- Cột trái ---------- */
.side {
  position: sticky;
  top: var(--gap);
  display: grid;
  gap: 12px;
  max-height: calc(100vh - 2 * var(--gap));
  max-height: calc(100dvh - 2 * var(--gap));
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
.side-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 2px 4px;
  font-size: 18px;
  font-weight: 700;
  color: var(--brand);
}
.side-title img { border-radius: 50%; background: #fff; box-shadow: 0 0 0 1px var(--line); }
.summary { display: none; }

.entry {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.field { display: flex; align-items: center; gap: 6px; min-width: 0; margin: 0; }
.field-stack { flex-direction: column; align-items: stretch; gap: 3px; }
.field-cap { font-size: 12px; font-weight: 600; color: var(--muted); line-height: 1.2; padding-left: 2px; }
.field-label { flex: none; font-size: 12.5px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.field input,
.field select {
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  transition: border-color 0.15s, background-color 0.15s;
}
.field select { padding-right: 4px; cursor: pointer; }
.field input::placeholder { color: #8b958f; }
.field input:hover,
.field select:hover { border-color: #b9c1b7; }
.field input:focus,
.field select:focus { outline: none; border-color: var(--focus); background: #fff; }
.field input[aria-invalid="true"],
.field select[aria-invalid="true"] { border-color: #d0573e; background: #fff1ed; }
/* Bỏ nút tăng giảm của ô số cho gọn. */
.field input[type="number"]::-webkit-outer-spin-button,
.field input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.field input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

.field-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.field-row > * { flex: 1 1 0; }
.field-row > .segment:first-child { flex: 0.8 1 0; }
.field-row > .segment:last-child { flex: 1.3 1 0; }
.field-date { display: grid; grid-template-columns: 1fr 1fr 1.25fr; }
.field-time { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); }
.field-date select, .field-time select { padding: 0 2px 0 6px; }
.field-submit { flex-wrap: wrap; }
.field-view-year { flex: 1 1 auto; }
.year-stepper { display: flex; flex: 1; min-width: 0; }
.year-stepper input { border-radius: 0; text-align: center; padding: 0 2px; }
.step {
  flex: none;
  width: 30px;
  height: 36px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  color: var(--brand);
  cursor: pointer;
}
.step:first-child { border-radius: 8px 0 0 8px; border-right: 0; }
.step:last-child { border-radius: 0 8px 8px 0; border-left: 0; }
.step:hover { background: var(--field); }

.segment {
  display: flex;
  margin: 0;
  padding: 3px;
  border: 0;
  border-radius: 9px;
  background: #e6e9e2;
}
.segment label { position: relative; flex: 1; cursor: pointer; }
.segment input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.segment span {
  display: block;
  padding: 5px 4px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  color: var(--muted);
  white-space: nowrap;
  transition: background-color 0.18s, color 0.18s;
}
.segment input:checked + span { background: var(--brand); color: #fff; }
.segment input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }

.leap { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.leap[hidden] { display: none; }
.leap input { width: 16px; height: 16px; margin: 0; accent-color: var(--brand); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.15s, background-color 0.15s, opacity 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn-primary { flex: 1 0 auto; background: var(--accent); color: var(--accent-ink); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12); }
.btn-primary:hover:not([disabled]) { background: #f1c463; }
.btn-primary[aria-busy="true"] { cursor: progress; opacity: 0.8; }
.entry-error { margin: 0; color: #b4321a; font-size: 13px; font-weight: 600; }
.entry-error:empty { display: none; }

.options {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.options summary {
  padding: 12px 14px 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  list-style: none;
  cursor: default;
}
.options summary::-webkit-details-marker { display: none; }
.options-list { display: grid; padding: 0 6px 8px; }

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 13.5px;
  cursor: pointer;
  transition: background-color 0.15s;
}
.toggle:hover { background: #f3f5f1; }
.toggle-private { margin-bottom: 4px; border-bottom: 1px solid var(--line); border-radius: 8px 8px 0 0; font-weight: 600; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-switch {
  position: relative;
  flex: none;
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: #c9cfc7;
  transition: background-color 0.2s;
}
.toggle-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease;
}
.toggle input:checked + .toggle-switch { background: var(--brand-2); }
.toggle input:checked + .toggle-switch::after { transform: translateX(14px); }
.toggle input:focus-visible + .toggle-switch { outline: 2px solid var(--focus); outline-offset: 2px; }
.toggle input:disabled ~ * { opacity: 0.5; }

.side-actions { display: grid; gap: 8px; }
.btn-download { width: 100%; height: 42px; background: var(--brand); color: #fff; box-shadow: var(--shadow); }
.btn-download:hover:not([disabled]) { background: var(--brand-2); }
.btn-split { width: 100%; height: 38px; background: var(--card); color: var(--brand); border: 1px solid var(--line); }
.btn-split:hover { background: var(--field); }
.btn-split[aria-pressed="true"] { background: #fdf3dc; border-color: var(--accent); }
.side-note { margin: 0; padding: 0 4px; color: var(--muted); font-size: 12px; }

/* Lá số luôn 3:4 như TVL; trên máy tính co theo chiều cao màn hình để thấy trọn. */
.chart-area { min-width: 0; display: flex; flex-direction: column; }
.chart-frame {
  position: relative;
  width: min(100%, max(420px, calc((100vh - 2 * var(--gap)) * 0.75)));
  width: min(100%, max(420px, calc((100dvh - 2 * var(--gap)) * 0.75)));
  aspect-ratio: 3 / 4;
  margin: 0 auto;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.chart-frame:focus { outline: none; }
.chart-frame svg { display: block; width: 100%; height: auto; }
.chart-frame.is-loading svg { opacity: 0.45; transition: opacity 0.2s; }

.chart-empty {
  display: grid;
  place-content: center;
  gap: 4px;
  height: 100%;
  padding: 32px;
  text-align: center;
  color: var(--muted);
  background:
    linear-gradient(var(--line) 1px, transparent 1px) 0 0 / 25% 25%,
    linear-gradient(90deg, var(--line) 1px, transparent 1px) 0 0 / 25% 25%,
    #fbfaf5;
}
.chart-empty p { margin: 0; background: #fbfaf5; padding: 2px 10px; }
.chart-empty-title { font-size: 16px; color: var(--ink); }

/* Lá số SVG: sao chuyển vị trí và mờ dần khi bật/tắt tùy chọn. */
.laso-svg .anim { transition: transform 0.28s ease, opacity 0.22s ease; }
.laso-svg .is-hidden { opacity: 0; pointer-events: none; }
@media (prefers-reduced-motion: reduce) {
  .laso-svg .anim, .toggle-switch, .toggle-switch::after, .segment span { transition: none; }
}

.chart-tools { display: none; }
.zoom-toggle { display: none; }

/* ---------- Chia đôi (máy tính và tablet) ----------
   Hai lá số đứng sát nhau ở giữa; cột thông tin khung 1 bên trái, khung 2 bên phải. */
.workspace.is-split { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; max-width: none; --side: 228px; --gap: 10px; }
.is-split .panel { border-radius: calc(var(--radius) + 4px); padding: 4px; outline: 2px solid transparent; transition: outline-color 0.15s; }
.is-split .panel.is-active { outline-color: var(--accent); }
.is-split .chart-frame {
  width: min(100%, max(300px, calc((100vh - 2 * var(--gap) - 8px) * 0.75)));
  width: min(100%, max(300px, calc((100dvh - 2 * var(--gap) - 8px) * 0.75)));
}
.is-split .panel[data-panel="1"]:not(.is-compact) .chart-frame { margin: 0 0 0 auto; }
.is-split .panel[data-panel="2"]:not(.is-compact) { grid-template-columns: minmax(0, 1fr) var(--side); }
.is-split .panel[data-panel="2"]:not(.is-compact) .side { grid-column: 2; grid-row: 1; }
.is-split .panel[data-panel="2"]:not(.is-compact) .chart-area { grid-column: 1; grid-row: 1; }
.is-split .panel[data-panel="2"]:not(.is-compact) .chart-frame { margin: 0 auto 0 0; }

@media (max-width: 760px) {
  .btn-split { display: none; }
}
@media (max-width: 1000px) and (min-width: 761px) {
  :root { --side: 230px; --gap: 12px; }
}
@media (max-width: 760px) {
  .workspace { display: block; padding: 0; }
  /* Điện thoại: lá số nằm giữa phần màn hình dưới thanh tóm tắt, cách thanh một khoảng. */
  .is-compact .chart-area {
    justify-content: center;
    min-height: calc(100vh - 46px);
    min-height: calc(100svh - 46px);
    padding: 12px 0;
  }
}

/* ---------- Khung gọn: điện thoại, hoặc chia đôi trên tablet ----------
   Thanh tóm tắt + nút Sửa ở trên, lá số rộng hết khung, tùy chọn ở dưới. */
.panel.is-compact { display: flex; flex-direction: column; align-items: stretch; gap: 0; padding: 0; }
.is-split .panel.is-compact { padding: 3px; }
.is-compact .side { display: contents; }
.is-compact .side-title { display: none; }

.is-compact .summary {
  position: sticky;
  top: 0;
  z-index: 10;
  order: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 6px 8px 6px 12px;
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}
.is-split .is-compact .summary { border-radius: 10px 10px 0 0; }
.is-compact .summary-text {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.is-compact .btn-edit { flex: none; height: 34px; padding: 0 14px; background: var(--accent); color: var(--accent-ink); }

.is-compact .entry { order: 2; display: none; margin: 0; border-radius: 0; border-width: 0 0 1px; box-shadow: none; padding: 12px 12px 14px; }
.is-compact.is-editing .entry { display: grid; }
.is-compact .field input, .is-compact .field select, .is-compact .step { height: 40px; }
.is-compact .field-date select, .is-compact .field-time select { padding: 0 4px 0 8px; }
.is-compact .segment span { padding: 7px 4px; font-size: 14px; }

.is-compact .chart-area { order: 3; width: 100%; }
.is-compact .chart-frame { width: 100%; border-radius: 0; box-shadow: none; }
.is-compact .chart-frame.is-zoomed { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.is-compact .chart-frame.is-zoomed svg { width: 900px; max-width: none; }
.is-compact .chart-tools { display: flex; justify-content: flex-end; padding: 6px 12px 0; }
.is-compact .zoom-toggle {
  display: inline-flex;
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
  background: var(--card);
  color: var(--brand);
  border: 1px solid var(--line);
}
.is-compact .zoom-toggle[hidden] { display: none; }

.is-compact .options { order: 4; margin: 10px 12px 0; }
.is-compact .options summary { cursor: pointer; display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; }
.is-compact .options summary::after { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform 0.2s; }
.is-compact .options[open] summary::after { transform: rotate(225deg); }
.is-compact .options-list { grid-template-columns: 1fr 1fr; gap: 2px; }
.is-compact .toggle-private { grid-column: 1 / -1; }
.is-compact .toggle { font-size: 13px; }
.is-compact .side-actions { order: 5; margin: 10px 12px 0; }
.is-compact .side-note { order: 6; margin: 10px 12px 18px; }
