/* តម្លៃថ្ងៃនេះ: a printed market page. Warm newsprint, ink rules, Moul for headlines (the
   traditional Khmer newspaper face) and Kantumruy Pro for reading. */

:root {
  color-scheme: light;
  --paper: #f4efe5;
  --paper-2: #ebe4d6;
  --paper-3: #e1d8c6;
  --ink: #1d1a16;
  --ink-2: #4a443b;
  --ink-3: #7a7265;
  --hair: #cdc2ad;
  --rule: #1d1a16;
  --up: #1b6a43;
  --up-soft: #d9e7da;
  --down: #a3291d;
  --down-soft: #f1dbd4;
  --flat: #6a6357;
  --link: #6d4b0f;
  --focus: #b07d1c;
  --kh: "Kantumruy Pro", "Noto Sans Khmer", "Khmer OS Siemreap", "Khmer UI", system-ui, sans-serif;
  --moul: "Moul", "Khmer OS Muol Light", "Khmer OS Muol", var(--kh);
  --base: 18px;
}

:root[data-size="large"] {
  --base: 21px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #17140f;
    --paper-2: #211d17;
    --paper-3: #2c271f;
    --ink: #efe8da;
    --ink-2: #cfc6b6;
    --ink-3: #9b9284;
    --hair: #3e382e;
    --rule: #efe8da;
    --up: #74cf98;
    --up-soft: #1b3125;
    --down: #f28e7d;
    --down-soft: #3b211c;
    --flat: #a59c8d;
    --link: #e2bb6c;
    --focus: #e2bb6c;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: var(--base);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 12px;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--kh);
  font-weight: 400;
  line-height: 1.75;
  overflow-wrap: anywhere;
}

a {
  color: var(--link);
  text-underline-offset: 3px;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.num {
  font-variant-numeric: tabular-nums;
}

.wrap {
  max-width: 1160px;
  margin: 0 auto;
  padding: 0 16px env(safe-area-inset-bottom);
}

/* ------------------------------------------------------------ masthead */

.masthead {
  text-align: center;
  border-bottom: 4px double var(--rule);
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 8px 0;
  border-bottom: 1px solid var(--rule);
  font-size: 0.8rem;
  color: var(--ink-2);
  text-align: left;
}

.today {
  margin: 0;
}

.prefs {
  display: flex;
  gap: 10px;
}

.seg {
  display: inline-flex;
  border: 1px solid var(--ink-2);
  border-radius: 3px;
  overflow: hidden;
}

.seg button {
  font: inherit;
  font-size: 0.85rem;
  min-width: 46px;
  min-height: 40px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  line-height: 1;
}

.seg button + button {
  border-left: 1px solid var(--ink-2);
}

.seg button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

.ka-small {
  font-size: 0.85rem;
}

.ka-big {
  font-size: 1.3rem;
  font-weight: 600;
}

.title {
  font-family: var(--moul);
  font-weight: 400;
  font-size: clamp(2.2rem, 10.5vw, 4.3rem);
  line-height: 1.55;
  margin: 0.25em 0 0;
}

.subtitle {
  margin: 0 0 0.7rem;
  font-size: 1rem;
  color: var(--ink-2);
  letter-spacing: 0.02em;
}

/* ------------------------------------------------------------ summary board */

.board {
  padding: 16px 0 14px;
  border-bottom: 1px solid var(--rule);
}

.lede {
  margin: 0 0 10px;
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.7;
}

.ticker {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--hair);
}

.ticker a {
  display: grid;
  grid-template-columns: 1fr auto 6.6em;
  align-items: baseline;
  gap: 12px;
  min-height: 52px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--hair);
  color: inherit;
  text-decoration: none;
}

.ticker .name {
  font-weight: 700;
  font-size: 1.05rem;
}

.ticker .price {
  font-weight: 600;
  font-size: 1.05rem;
}

.ticker .chg {
  text-align: right;
  font-weight: 600;
  font-size: 0.95rem;
}

[data-dir="up"] > .chg,
.key[data-dir="up"] {
  color: var(--up);
}

[data-dir="down"] > .chg,
.key[data-dir="down"] {
  color: var(--down);
}

[data-dir="flat"] > .chg {
  color: var(--flat);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 14px;
  margin: 10px 0 0;
  font-size: 0.78rem;
  color: var(--ink-3);
}

.key {
  font-weight: 600;
}

.updated[data-state="stale"] {
  color: var(--down);
  font-weight: 600;
  flex-basis: 100%;
}

@media (min-width: 860px) {
  .ticker {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    border-top: 0;
  }

  .ticker li + li a {
    border-left: 1px solid var(--hair);
  }

  .ticker a {
    grid-template-columns: 1fr;
    gap: 0;
    padding: 4px 22px 10px;
    border-bottom: 0;
  }

  .ticker li:first-child a {
    padding-left: 0;
  }

  .ticker .price {
    font-size: 1.6rem;
    line-height: 1.4;
  }

  .ticker .chg {
    text-align: left;
  }
}

/* ------------------------------------------------------------ one asset */

.assets {
  display: grid;
}

.asset {
  padding: 26px 0 32px;
  border-bottom: 3px solid var(--rule);
  min-width: 0;
}

@media (min-width: 1000px) {
  /* The three columns sit side by side here, so the summary strip would only repeat them. */
  .ticker {
    display: none;
  }

  .board {
    padding: 14px 0 10px;
  }

  .lede {
    margin: 0;
  }

  .assets {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    border-bottom: 3px solid var(--rule);
  }

  .asset {
    padding: 24px 22px 32px;
    border-bottom: 0;
  }

  .asset + .asset {
    border-left: 1px solid var(--hair);
  }

  .asset:first-child {
    padding-left: 0;
  }

  .asset:last-child {
    padding-right: 0;
  }
}

.asset-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
  padding-bottom: 2px;
  border-bottom: 1px solid var(--rule);
}

.asset-name {
  margin: 0;
  font-family: var(--moul);
  font-weight: 400;
  font-size: 1.75rem;
  line-height: 1.75;
}

.asset-latin {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.unit {
  margin: 12px 0 0;
  font-size: 0.85rem;
  color: var(--ink-2);
}

.price {
  margin: 0 0 8px;
  font-size: clamp(2.5rem, 12vw, 3.15rem);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.price .cur {
  font-size: 0.5em;
  font-weight: 500;
  color: var(--ink-2);
  vertical-align: 0.75em;
  margin-right: 0.06em;
}

.price.tick-up .num {
  animation: tick-up 1.4s ease-out;
}

.price.tick-down .num {
  animation: tick-down 1.4s ease-out;
}

@keyframes tick-up {
  from {
    color: var(--up);
  }
}

@keyframes tick-down {
  from {
    color: var(--down);
  }
}

.change {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 10px;
  margin: 0;
}

.change:empty {
  display: none;
}

.change .pill {
  padding: 1px 10px;
  border-radius: 2px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.change[data-dir="up"] .pill {
  color: var(--up);
  background: var(--up-soft);
}

.change[data-dir="down"] .pill {
  color: var(--down);
  background: var(--down-soft);
}

.change[data-dir="flat"] .pill {
  color: var(--flat);
  background: var(--paper-2);
}

.change .when {
  font-size: 0.82rem;
  color: var(--ink-3);
}

.plain {
  margin: 8px 0 0;
  color: var(--ink-2);
}

.closed {
  margin: 10px 0 0;
  padding: 8px 12px;
  border: 1px dashed var(--ink-3);
  font-size: 0.85rem;
  color: var(--ink-2);
}

/* gold in ជី and តម្លឹង; crypto in riel */

.units {
  margin-top: 18px;
  padding: 8px 0 10px;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--hair);
}

.units-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 2px;
  font-weight: 700;
  font-size: 0.92rem;
}

.units-title .purity {
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--ink-3);
}

.units dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  margin: 0;
}

.units dt {
  font-weight: 600;
  line-height: 1.5;
}

.units dt small {
  display: block;
  font-weight: 400;
  font-size: 0.75rem;
  color: var(--ink-3);
}

.units dd {
  margin: 0;
  text-align: right;
  line-height: 1.45;
}

.units dd b {
  display: block;
  font-size: 1.15rem;
  font-weight: 600;
}

.units dd span {
  font-size: 0.8rem;
  color: var(--ink-2);
}

.units-note {
  margin: 8px 0 0;
  font-size: 0.76rem;
  line-height: 1.65;
  color: var(--ink-3);
}

.riel {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0 12px;
  margin: 18px 0 0;
  padding: 8px 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--hair);
}

.riel .label {
  font-weight: 700;
  font-size: 0.92rem;
}

/* the "why" box */

.why {
  margin-top: 20px;
  padding: 14px 16px 12px;
  background: var(--paper-2);
  border-left: 4px solid var(--ink-3);
}

.why[data-dir="up"] {
  border-left-color: var(--up);
}

.why[data-dir="down"] {
  border-left-color: var(--down);
}

.why-title {
  margin: 0;
  font-size: 1.12rem;
  line-height: 1.65;
}

.why-sub {
  margin: 2px 0 6px;
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--ink-3);
}

.why-sub:empty {
  display: none;
}

.reasons {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: reason;
}

.reason {
  position: relative;
  counter-increment: reason;
  padding: 10px 0 8px 2.2em;
  border-top: 1px solid var(--hair);
}

.reason:first-child {
  border-top: 0;
}

.reason::before {
  content: counter(reason, khmer);
  position: absolute;
  left: 0;
  top: 7px;
  font-family: var(--moul);
  font-size: 1.15rem;
  line-height: 1.6;
  color: var(--ink-3);
}

:root[data-digits="latn"] .reason::before {
  content: counter(reason);
  font-family: var(--kh);
  font-weight: 700;
}

.reason h4 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.65;
}

.reason .body {
  margin: 2px 0 4px;
  font-size: 0.92rem;
  line-height: 1.85;
  color: var(--ink-2);
}

.reason .meta {
  margin: 0;
  font-size: 0.74rem;
  line-height: 1.6;
  color: var(--ink-3);
}

.reason details {
  margin-top: 2px;
}

.reason summary {
  display: inline-block;
  padding: 6px 0;
  font-size: 0.8rem;
  color: var(--link);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.reason details[open] summary {
  text-decoration: none;
}

.reason .note {
  margin: 0;
  font-size: 0.72rem;
  color: var(--ink-3);
}

.reason details ul {
  margin: 4px 0 2px;
  padding-left: 1.1em;
  font-size: 0.8rem;
  line-height: 1.55;
}

.reason details li {
  margin: 0 0 6px;
}

.reason details .src {
  color: var(--ink-3);
}

.reasons .none {
  padding: 6px 0;
  font-size: 0.92rem;
  color: var(--ink-2);
}

.other {
  font-size: 0.82rem;
  line-height: 1.6;
}

.other:not(:empty) {
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--hair);
}

.other-title {
  margin: 0 0 2px;
  color: var(--ink-3);
}

.other-item {
  margin: 0;
  color: var(--ink-2);
}

.other-item[data-dir="up"] .arrow {
  color: var(--up);
}

.other-item[data-dir="down"] .arrow {
  color: var(--down);
}

/* chart */

.chart-box {
  margin-top: 22px;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--rule);
}

.tabs button {
  flex: 1;
  min-height: 44px;
  margin-bottom: -1px;
  padding: 6px 2px 4px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: none;
  color: var(--ink-3);
  font: inherit;
  font-size: 0.84rem;
  cursor: pointer;
}

.tabs button[aria-selected="true"] {
  color: var(--ink);
  font-weight: 700;
  border-bottom-color: var(--ink);
}

.chart-summary {
  margin: 8px 0 0;
  font-size: 0.84rem;
  font-weight: 600;
  min-height: 1.6em;
}

.chart-summary[data-dir="up"] {
  color: var(--up);
}

.chart-summary[data-dir="down"] {
  color: var(--down);
}

.chart {
  position: relative;
  height: 200px;
  margin-top: 2px;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.chart svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.chart .line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.chart .line[data-dir="up"],
.chart .end[data-dir="up"] {
  stroke: var(--up);
  fill-opacity: 1;
}

.chart .line[data-dir="down"],
.chart .end[data-dir="down"] {
  stroke: var(--down);
}

.chart .end {
  fill: var(--paper);
  stroke-width: 2.5;
}

.chart .area {
  stroke: none;
  opacity: 0.12;
}

.chart .area[data-dir="up"] {
  fill: var(--up);
}

.chart .area[data-dir="down"] {
  fill: var(--down);
}

.chart .base {
  stroke: var(--ink-3);
  stroke-width: 1;
  stroke-dasharray: 2 4;
  vector-effect: non-scaling-stroke;
}

.chart .mark {
  fill: var(--ink-2);
}

.chart text {
  font-family: var(--kh);
  font-size: 11.5px;
  fill: var(--ink-2);
}

.chart .lbl {
  font-weight: 600;
}

.chart .axis {
  fill: var(--ink-3);
}

.chart .cursor {
  stroke: var(--ink);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.chart .cursor-dot {
  fill: var(--ink);
}

.chart .tip {
  position: absolute;
  top: -6px;
  transform: translateX(-50%);
  padding: 1px 8px;
  border-radius: 2px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.76rem;
  line-height: 1.7;
  white-space: nowrap;
  pointer-events: none;
}

.chart-msg {
  margin: 0;
  padding-top: 78px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--ink-3);
}

/* small facts table */

.stats {
  display: grid;
  grid-template-columns: 1fr auto;
  margin: 18px 0 0;
  font-size: 0.84rem;
}

.stats dt,
.stats dd {
  margin: 0;
  padding: 6px 0;
  border-bottom: 1px dotted var(--hair);
}

.stats dt {
  color: var(--ink-2);
  padding-right: 12px;
}

.stats dd {
  text-align: right;
  font-weight: 600;
}

/* ------------------------------------------------------------ glossary and footer */

.learn {
  padding: 26px 0 30px;
  border-bottom: 1px solid var(--rule);
}

.learn h2 {
  margin: 0;
  font-family: var(--moul);
  font-weight: 400;
  font-size: 1.4rem;
  line-height: 1.8;
}

.learn .intro {
  margin: 0 0 10px;
  font-size: 0.85rem;
  color: var(--ink-3);
}

.terms details {
  border-top: 1px solid var(--hair);
  break-inside: avoid;
}

.terms details:last-child {
  border-bottom: 1px solid var(--hair);
}

@media (min-width: 760px) {
  .terms {
    columns: 2;
    column-gap: 44px;
  }

  .terms details:last-child {
    border-bottom: 0;
  }
}

.terms summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 48px;
  padding: 6px 0;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

.terms summary::-webkit-details-marker {
  display: none;
}

.terms summary::after {
  content: "+";
  font-weight: 400;
  font-size: 1.3rem;
  color: var(--ink-3);
}

.terms details[open] summary::after {
  content: "−";
}

.terms details p {
  margin: 0 0 14px;
  font-size: 0.92rem;
  line-height: 1.85;
  color: var(--ink-2);
}

.foot {
  padding: 18px 0 44px;
  font-size: 0.78rem;
  line-height: 1.8;
  color: var(--ink-3);
}

.foot p {
  margin: 0 0 10px;
  max-width: 68em;
}

.foot .sources {
  margin-top: 14px;
  font-size: 0.72rem;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .price .num {
    animation: none !important;
  }
}
