/* Design tokens — same language as the Claude Design mockups. Views must use these, not new colours. */
:root {
  --ground: #F4F5F2; --card: #FFFFFF; --line: #D9DDD6; --ink: #1A1D1B; --muted: #5A625D;
  --control: #8B938D; --soft: #EEF0EB; --accent: #A8271C; --accent-soft: #FBEDEA; --jade: #1E6650;
  --link: #6B2FA0; --birth-fill: #FBF7DA; --birth-line: #C98A3C; --band: #4F5B66;
  /* five elements, indexed like engine ELEMENTS: 0 ทอง 1 น้ำ 2 ไม้ 3 ไฟ 4 ดิน */
  --el-0: #4F5B66; --el-1: #1C5FA8; --el-2: #1F7A3D; --el-3: #B3261E; --el-4: #8A5A12;
  --fav: #8A6A00; --unfav: #B3261E; --norm: #5A625D; --midfav: #1C5FA8;
  --radius: 10px; --font: 'IBM Plex Sans Thai', system-ui, sans-serif; --han: 'Noto Serif TC', 'Songti SC', serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--ground); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.45; }
a { color: var(--link); text-decoration: none; } a:hover { color: #4A1F70; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1 { font-size: 20px; margin: 0; } h2 { font-size: 16px; margin: 0; } h3 { font-size: 15px; margin: 0; }
p { margin: 0; }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: 13px; } .han { font-family: var(--han); font-weight: 700; }
.el-0 { color: var(--el-0); } .el-1 { color: var(--el-1); } .el-2 { color: var(--el-2); } .el-3 { color: var(--el-3); } .el-4 { color: var(--el-4); }

/* Shell */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 24px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 28px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: var(--ink); }
.brand-mark { width: 34px; height: 34px; border-radius: 6px; background: var(--accent); color: #fff; font-family: var(--han); font-size: 20px; display: flex; align-items: center; justify-content: center; }
.nav { display: flex; flex-wrap: wrap; gap: 4px; }
.nav a { color: var(--ink); padding: 10px 14px; border-radius: 6px; font-weight: 500; }
.nav a:hover { background: var(--soft); }
.nav a[aria-current="page"] { background: var(--accent); color: #fff; }
.topbar .who { margin-left: auto; font-size: 13px; color: var(--muted); }
.page { flex: 1; width: 100%; max-width: 1360px; margin: 0 auto; padding: 24px; display: flex; flex-direction: column; gap: 20px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }

/* Layout helpers */
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 12px; }
.cols { display: flex; flex-wrap: wrap; gap: 20px; align-items: stretch; }
.grow { flex: 999 1 620px; min-width: 0; } .side { flex: 1 1 380px; min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.band { background: var(--band); color: #fff; }
.scroll-x { overflow-x: auto; }

/* Controls */
.btn { min-height: 44px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--control); background: var(--card); color: var(--ink); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; } .btn.primary:hover { background: #8F2018; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn.icon { width: 44px; padding: 0; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn.link { border: 0; background: none; color: var(--link); padding: 0 4px; min-height: 32px; text-decoration: underline; font-weight: 500; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.seg > button, .chip { min-height: 44px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--control); background: var(--card); font-weight: 600; }
.seg > button[aria-pressed="true"], .chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .label { font-size: 13px; font-weight: 600; color: var(--muted); }
.input, select.input { min-height: 44px; padding: 0 12px; border: 1px solid var(--control); border-radius: 8px; background: #fff; width: 100%; }
textarea.input { padding: 10px 12px; min-height: 96px; }
.birth-box { display: block; width: 100%; text-align: left; background: var(--birth-fill); border: 1px solid var(--birth-line); border-radius: 8px; padding: 10px 12px; color: #3B2A8C; }
.table { width: 100%; border-collapse: collapse; } .table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { font-size: 13px; color: var(--muted); font-weight: 600; }
.table tr[aria-selected="true"] td { background: var(--accent-soft); }

/* Fav / unfav marks */
.mark { font-size: 13px; font-weight: 700; } .mark.fav { color: #E6A700; font-size: 1.2em; line-height: 1; } .mark.unfav { color: var(--unfav); } .mark.norm { color: var(--norm); } .mark.midfav { color: var(--midfav); } .mark.tri { color: var(--unfav); }
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; border: 1px solid currentColor; }
.tag.fav { color: var(--fav); } .tag.unfav { color: var(--unfav); } .tag.norm { color: var(--norm); } .tag.midfav { color: var(--midfav); }

/* Pillar grid (ui/pillars.js) */
.pillars { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); position: relative; }
.pcol { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.pcol.sep { border-left: 2px solid var(--ink); }
.pcol.day .pbody { background: var(--ground); }
.pcol.transit .pbody { background: var(--birth-fill); }
.phead { width: 100%; background: var(--band); color: #fff; border: 0; padding: 10px 4px; min-height: 58px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-align: center; }
.phead .t { font-weight: 700; font-size: 17px; } .phead .s { font-size: 12px; }
button.phead .s { text-decoration: underline; }
.pcol.transit .phead { background: var(--accent); }
.pbody { width: 100%; flex: 1; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 16px 4px 14px; }
.pcell { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.glyph-row { display: flex; align-items: flex-start; gap: 2px; }
.glyph { font-family: var(--han); font-weight: 700; font-size: clamp(1.9rem, 3.4vw, 3.1rem); line-height: 1.15; min-width: 48px; min-height: 48px; text-align: center; background: none; border: 2px solid transparent; border-radius: 8px; padding: 0 4px; }
button.glyph:hover { background: var(--soft); }
.glyph.hit { border-color: var(--accent); background: var(--accent-soft); }
.glyph.hit-good { border-color: var(--jade); background: #E7F2EE; }
.pcell .ele { font-size: 13px; font-weight: 500; } .pcell .animal { font-size: 13px; font-weight: 600; }
.pcell .god { font-size: 13px; padding: 4px 2px; background: none; border: 0; color: var(--link); min-height: 28px; }
.hidden-row { display: flex; justify-content: center; gap: 6px; border-top: 1px dashed var(--line); padding-top: 10px; width: 100%; }
.hid { display: flex; flex-direction: column; align-items: center; min-width: 26px; }
.hid .g { font-family: var(--han); font-weight: 600; font-size: 18px; line-height: 1.2; } .hid .e { font-size: 12px; }
.arrow-layer { position: absolute; inset: 0; pointer-events: none; overflow: visible; }

/* Dialog + toast */
.dialog-backdrop { position: fixed; inset: 0; background: rgba(26, 29, 27, .45); display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; overflow-y: auto; z-index: 20; }
.dialog { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); width: 100%; max-width: 720px; padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.dialog.wide { max-width: 1000px; }
.dialog-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
#toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; }
.error-box { border: 1px solid var(--unfav); color: var(--unfav); background: var(--accent-soft); border-radius: 8px; padding: 10px 12px; }
.reading { white-space: pre-line; max-width: 70ch; }
.dialog-body { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* Desktop / mobile markup switches */
@media (min-width: 901px) { .m-only { display: none !important; } }

/* ---------- Mobile (≤ 900px): compact top bar, fixed bottom toolbar, full-screen sheets ---------- */
@media (max-width: 900px) {
  :root { --tabbar-h: 58px; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  .d-only { display: none !important; }
  input, select, textarea, .input { font-size: 16px; }

  .topbar { flex-wrap: nowrap; gap: 10px; padding: calc(6px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left)); }
  .brand { font-size: 16px; gap: 8px; min-height: 44px; flex: none; }
  .brand-mark { width: 30px; height: 30px; font-size: 18px; }
  .topbar .who { min-width: 0; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .page { padding: 12px max(8px, env(safe-area-inset-right)) calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px) max(8px, env(safe-area-inset-left)); gap: 12px; overflow-x: clip; }
  .page-head h1 { font-size: 18px; }
  .card { padding: 12px; }
  .cols { gap: 12px; }

  .tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; display: flex; background: var(--card); border-top: 1px solid var(--line);
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  .tabbar a { flex: 1 1 0; min-width: 0; min-height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 4px 2px; color: var(--ink); font-size: 12px; font-weight: 500; }
  .tabbar a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tabbar a[aria-current="page"] { color: var(--accent); font-weight: 700; background: var(--accent-soft); }

  #toast-root { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); width: calc(100% - 32px); }

  /* Small dialogs stay centred; .sheet dialogs fill the screen */
  .dialog-backdrop { padding: 16px; }
  .dialog { margin: auto 0; padding: 16px; }
  .dialog.sheet { position: fixed; inset: 0; margin: 0; max-width: none; height: 100%; border: 0; border-radius: 0; padding: 0; gap: 0; }
  .dialog.sheet > h2 { flex: none; padding: calc(14px + env(safe-area-inset-top)) 16px 12px; border-bottom: 1px solid var(--line); background: var(--card); font-size: 17px; }
  .dialog.sheet > .dialog-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
    padding: 16px max(16px, env(safe-area-inset-right)) 20px max(16px, env(safe-area-inset-left)); }
  .dialog.sheet > .dialog-foot { flex: none; flex-wrap: nowrap; gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--card); }
  .dialog.sheet > .dialog-foot .btn { flex: 1 1 0; min-width: 0; padding: 0 8px; }

  /* Compact pillar grid: 6 columns must fit 360px (opt in with .compact-pillars on a wrapper) */
  .compact-pillars .phead { min-height: 46px; padding: 4px 1px; gap: 0; }
  .compact-pillars .phead .t { font-size: 15px; line-height: 1.2; }
  .compact-pillars .phead .s { font-size: 12px; line-height: 1.15; }
  .compact-pillars .pbody { gap: 6px; padding: 8px 0 6px; }
  .compact-pillars .pcell { gap: 0; width: 100%; }
  .compact-pillars .glyph-row { gap: 0; justify-content: center; }
  .compact-pillars .glyph { font-size: 26px; min-width: 40px; min-height: 40px; padding: 0 2px; line-height: 1.3; }
  .compact-pillars .pcell .ele, .compact-pillars .pcell .animal { font-size: 12px; line-height: 1.3; text-align: center; }
  .compact-pillars .pcell .god { font-size: 12px; line-height: 1.15; min-height: 32px; padding: 2px 0; max-width: 100%; }
  .compact-pillars .hidden-row { gap: 1px; padding-top: 6px; }
  .compact-pillars .hid { min-width: 0; flex: 0 1 auto; }
  .compact-pillars .hid .g { font-size: 15px; } .compact-pillars .hid .e { font-size: 12px; }
  .compact-pillars .mark { font-size: 12px; }
}

/* ฤกษ์ซาฮะ | ฤกษ์ขั้นสูง 64 ข่วย switch (ui/luck-switch.js) */
.luck-switch { display: inline-flex; flex: none; border: 1px solid var(--control); border-radius: 8px; overflow: hidden; background: var(--card); }
.luck-switch a { display: flex; align-items: center; min-height: 40px; padding: 0 14px; font-weight: 700; color: var(--ink); white-space: nowrap; }
.luck-switch a + a { border-left: 1px solid var(--control); }
.luck-switch a[aria-current="page"] { background: var(--accent); color: #fff; }
@media (max-width: 900px) { .luck-switch a { min-height: 44px; padding: 0 12px; } }

@media (max-width: 900px) { .tabbar a { font-size: 11px; } .tabbar a svg { width: 22px; height: 22px; } }
