/* Metafysix — ink and gold (墨金): stone paper, black ink, temple gold. One bold thing: the south-up nine-palace map. */
:root {
  --porcelain: #F2F0EC;
  --glaze: #FBFAF8;
  --ink: #221E1A;
  --gold: #8A5A14;
  --slate: #6B645C;
  --jade: #2F7D5B;
  --cinnabar: #B63A2B;
  --line: #D8D2C8;
  --wash: #E8E2D6;
  --serif: "Noto Serif TC", "Songti TC", serif;
  --sans: "Atkinson Hyperlegible", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --porcelain: #16130F; --glaze: #1F1B16; --ink: #EFE9DF; --gold: #D9A845; --slate: #B3AA9C;
    --jade: #6CC39B; --cinnabar: #F08A7A; --line: #3A332A; --wash: #2A241C; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --porcelain: #16130F; --glaze: #1F1B16; --ink: #EFE9DF; --gold: #D9A845; --slate: #B3AA9C;
  --jade: #6CC39B; --cinnabar: #F08A7A; --line: #3A332A; --wash: #2A241C; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--porcelain); color: var(--ink);
  font: 1.0625rem/1.55 var(--sans);
}
a, .link { color: var(--gold); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 4px; }

.top, main, .foot { max-width: 40rem; margin: 0 auto; padding: 0 16px; }
.top { padding-top: 20px; }
.brand { display: flex; align-items: baseline; gap: .6rem; text-decoration: none; color: var(--ink); }
.brand-mark { font: 900 1.05rem/1 var(--serif); color: var(--porcelain); background: var(--gold);
  padding: .35rem .4rem; border-radius: 3px; letter-spacing: .05em; }
.brand-name { font: 700 1.5rem/1 var(--serif); letter-spacing: .01em; }

.tabs { display: flex; gap: .25rem; margin: 1.25rem 0 0; border-bottom: 1px solid var(--line); }
.tabs button {
  font: 700 1rem var(--sans); color: var(--slate); background: none; border: 0; cursor: pointer;
  padding: .7rem .9rem; border-bottom: 3px solid transparent; margin-bottom: -1px; min-height: 44px;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--gold); }

main { padding-top: 1.5rem; padding-bottom: 2rem; }
h2 { font: 700 1.35rem/1.3 var(--serif); margin: 0 0 .5rem; }
.lede, .hint, .empty { color: var(--slate); }

/* the day headline: the pillar itself is the type moment */
.day-head { text-align: center; }
.date { margin: 0; color: var(--slate); }
.pillar { font: 900 clamp(4.5rem, 22vw, 7rem)/1 var(--serif); margin: .3rem 0 .2rem; letter-spacing: .08em; color: var(--gold); }
.day-name { margin: 0; font-size: 1.15rem; }

/* nine palaces, south up: row 1 = SE S SW, row 2 = E C W, row 3 = NE N NW */
.palaces { margin: 1.75rem 0 1.5rem; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; border: 2px solid var(--ink); background: var(--glaze); }
.cell { aspect-ratio: 1 / 1; padding: .5rem; border: 1px solid var(--line); display: flex; flex-direction: column;
  justify-content: space-between; min-width: 0; }
.cell .dir { font: 700 .95rem var(--serif); }
.cell .gua { font: 500 .8rem var(--serif); color: var(--slate); }
.cell .note { font-size: .82rem; line-height: 1.25; overflow-wrap: anywhere; }
.cell.good { background: color-mix(in srgb, var(--jade) 14%, var(--glaze)); }
.cell.good .note { color: var(--jade); font-weight: 700; }
.cell.avoid { background: color-mix(in srgb, var(--cinnabar) 13%, var(--glaze));
  background-image: repeating-linear-gradient(135deg, transparent 0 9px, color-mix(in srgb, var(--cinnabar) 18%, transparent) 9px 10px); }
.cell.avoid .note { color: var(--cinnabar); font-weight: 700; }
.cell.centre { justify-content: center; align-items: center; text-align: center; background: var(--wash); }
.cell.centre .star { font: 900 2rem/1 var(--serif); color: var(--gold); }
.cell.centre .gua { margin-top: .25rem; }
figcaption { margin-top: .6rem; font-size: .9rem; color: var(--slate); }
.key { white-space: nowrap; margin-left: .5rem; font-weight: 700; }
.key::before { content: ""; display: inline-block; width: .8em; height: .8em; margin-right: .3em; vertical-align: -.05em; border: 1px solid var(--line); }
.key-good { color: var(--jade); } .key-good::before { background: color-mix(in srgb, var(--jade) 30%, var(--glaze)); }
.key-avoid { color: var(--cinnabar); } .key-avoid::before { background: color-mix(in srgb, var(--cinnabar) 30%, var(--glaze)); }

.block { margin: 1.5rem 0; }
.block h2 { font-size: 1.15rem; }
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { padding: .55rem 0; border-top: 1px solid var(--line); }
.rows li:last-child { border-bottom: 1px solid var(--line); }
.rows b { font-weight: 700; }

/* form */
.form label { display: block; margin: .9rem 0; font-weight: 700; }
.form input[type=date], .form input[type=time], .form select {
  display: block; width: 100%; margin-top: .35rem; font: 400 1rem var(--sans); color: var(--ink);
  background: var(--glaze); border: 1px solid var(--line); border-radius: 6px; padding: .7rem; min-height: 48px;
}
fieldset { border: 0; padding: 0; margin: 1rem 0; }
legend { font-weight: 700; padding: 0; }
.inline { display: inline-flex !important; align-items: center; gap: .4rem; margin: .5rem 1.2rem 0 0 !important; font-weight: 400 !important; }
.inline input { width: 1.2rem; height: 1.2rem; accent-color: var(--gold); }
.primary { font: 700 1.05rem var(--sans); color: var(--glaze); background: var(--gold); border: 0; border-radius: 6px;
  padding: .85rem 1.4rem; cursor: pointer; min-height: 48px; width: 100%; }
.primary[disabled] { opacity: .6; cursor: progress; }
.link { background: none; border: 0; padding: 0; font: inherit; text-decoration: underline; cursor: pointer; }
.form-error { color: var(--cinnabar); font-weight: 700; min-height: 1.5em; margin: .5rem 0; }

/* chart: four pillars as tall vertical characters, laid out like the classics: year on the right, hour on the left */
.pillars { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .5rem; margin: 1.25rem 0; }
.pcol { text-align: center; border-top: 2px solid var(--ink); padding-top: .5rem; min-width: 0; }
.pcol .zh { font: 900 clamp(2.2rem, 10vw, 3.2rem)/1.1 var(--serif); margin: .2rem 0 0; }
.pcol .en { font-size: .8rem; line-height: 1.2; color: var(--slate); min-height: 2.4em; }
.pillars-note { color: var(--slate); font-size: .92rem; margin: .25rem 0 0; }
.pcol.me .zh { color: var(--gold); }
.pcol .lab { font-size: .85rem; color: var(--slate); margin-top: .4rem; }
.facts { margin: 1rem 0; }
.facts dt { font-weight: 700; margin-top: .9rem; }
.facts dd { margin: .15rem 0 0; }
.edit { margin-top: 1.25rem; }

.rating { display: flex; align-items: center; gap: .75rem; margin: 0 0 1rem; font: 700 1.25rem/1.3 var(--serif); }
.rating::before { content: ""; flex: none; width: 1.1rem; height: 1.1rem; border-radius: 50%; background: var(--slate); }
.rating.green::before { background: var(--jade); }
.rating.red::before { background: var(--cinnabar); }
.sit { border-left: 4px solid var(--jade); padding: .4rem 0 .4rem .9rem; margin: 1rem 0; font-size: 1.1rem; }

.ts { margin: 1rem 0; display: flex; justify-content: center; }
.foot { font-size: .85rem; color: var(--slate); padding-bottom: 2.5rem; border-top: 1px solid var(--line); }
.notice { color: var(--cinnabar); font-weight: 700; }

@media (prefers-reduced-motion: no-preference) {
  .grid.ready .cell { animation: ink .5s ease-out both; animation-delay: calc(var(--i) * 45ms); }
  @keyframes ink { from { opacity: 0; } to { opacity: 1; } }
}
@media (max-width: 380px) { .cell .note { font-size: .74rem; } .cell { padding: .35rem; } }

/* DESKTOP_V1: wide screens use the width — Today shows the map beside the hours; chart shows pillars beside the facts */
@media (min-width: 960px) {
  .top, main, .foot { max-width: 72rem; padding-left: 32px; padding-right: 32px; }
  #panel-today:not([hidden]) { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); column-gap: 3.5rem;
    grid-template-areas: "head hours" "map hours" "map officer" "map hint" "map ." ; align-items: start; }
  #panel-today .day-head { grid-area: head; }
  #panel-today .palaces { grid-area: map; margin-top: 1.25rem; }
  #today-hours { grid-area: hours; margin-top: 0; }
  #today-officer { grid-area: officer; }
  #panel-today .hint { grid-area: hint; }
  .pillar { font-size: 7.5rem; }
  .cell { padding: .8rem; } .cell .dir { font-size: 1.1rem; } .cell .note { font-size: .95rem; }
  .cell.centre .star { font-size: 3rem; }
  #birth-form { max-width: 34rem; }
  #chart-out:not([hidden]) { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); column-gap: 3.5rem; align-items: start; }
  #chart-out > :not(.pillars):not(.facts) { grid-column: 1 / -1; }
  #chart-out .pillars { grid-column: 1; margin-top: 0; }
  #chart-out .facts { grid-column: 2; margin-top: 0; }
  #day-out { max-width: 46rem; }
  .pcol .zh { font-size: 3.6rem; } .pcol .en { font-size: .9rem; }
  .primary { width: auto; justify-self: start; padding-left: 2.5rem; padding-right: 2.5rem; }
}
