/* Thương Cảng 1800 — Đại Nam UI prototype (nháp). Semantic tokens over palette.css (palette.json of the foundations). */
:root {
  color-scheme: light;
  --surface-paper: var(--paper-100);
  --surface-paper-2: var(--paper-200);
  --surface-well: var(--paper-300);
  --surface-lacquer: var(--son-500);
  --surface-lacquer-dark: var(--then-800);
  --frame: var(--son-frame);
  --frame-edge: var(--vang-400);
  --text: var(--muc-900);
  --text-2: var(--muc-700);
  --text-muted: var(--muc-600);
  --text-title: var(--chu-500);
  --text-on-lacquer: var(--paper-50);
  --accent-on-lacquer: var(--vang-200);
  --good: var(--la-text);
  --good-ui: var(--la-ui);
  --warn: var(--nghe-text);
  --warn-ui: var(--nghe-ui);
  --bad: var(--chusa-bad);
  --bad-on-dark: var(--chusa-bright);
  --luxury: var(--hoaca-text);
  --luxury-ui: var(--hoaca-500);
  --info: var(--song-700);
  --focus-paper: var(--ngoc-500);
  --focus-lacquer: var(--vang-200);

  /* tier tones (provisional): rice-green · indigo · terracotta · steel · gold */
  --tier-nong-dan: #5d7425;
  --tier-tho: #2c5868;
  --tier-thi-dan: #8a4b22;
  --tier-bac-vat: #44505c;
  --tier-phu-thuong: #8a6420;

  --font-display: 'Water Brush', 'Brygada 1918', Georgia, serif;
  --font-title: 'Brygada 1918', Georgia, 'Times New Roman', serif;
  --font-ui: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-num: 'Brygada 1918', Georgia, serif;

  --gap: 12px;
  --radius: 8px;
  --radius-sm: 5px;
  --tap: 30px; /* smallest hit target; touch: 44px */
  --shadow: 0 10px 26px rgba(9, 8, 6, 0.38), 0 2px 6px rgba(9, 8, 6, 0.28);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  /* dó paper: fine speckle + long fibres (SVG noise) */
  --paper-tex: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='a'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' seed='4'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .32 0 0 0 0 .16 0 0 0 .55 -.18'/%3E%3C/filter%3E%3Cfilter id='b'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.012 .32' numOctaves='3' seed='9'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .36 0 0 0 0 .18 0 0 0 .9 -.42'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23a)'/%3E%3Crect width='240' height='240' filter='url(%23b)' transform='rotate(28 120 120)'/%3E%3C/svg%3E");
  --lacquer-red: linear-gradient(180deg, #7e1c0a 0%, #651106 46%, #520902 100%);
  --lacquer-black: linear-gradient(180deg, #211f1b 0%, #14120e 55%, #090806 100%);
}
:root[data-input='touch'] {
  --tap: 44px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}
body {
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.35;
  color: var(--text);
  background: #6e7a78;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button,
input,
select {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
}
.vh {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.num {
  font-family: var(--font-num);
  font-variant-numeric: lining-nums tabular-nums;
  font-weight: 600;
}
.pos {
  color: var(--good);
}
.neg {
  color: var(--bad);
}
.warn-t {
  color: var(--warn);
}
.muted {
  color: var(--text-muted);
}
.glyph {
  flex: none;
  display: block;
}
img {
  display: block;
}

/* ---------------------------------------------------------------- the 3D world placeholder */
.world {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    repeating-linear-gradient(30deg, transparent 0 39px, rgba(255, 255, 255, 0.16) 39px 40px),
    repeating-linear-gradient(150deg, transparent 0 39px, rgba(255, 255, 255, 0.16) 39px 40px),
    radial-gradient(120% 90% at 40% 35%, #a9b4a3 0%, #94a3a0 55%, #7f9196 100%);
}
.world__label {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  border: 1px dashed rgba(36, 27, 18, 0.35);
  border-radius: 6px;
  color: rgba(36, 27, 18, 0.62);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-align: center;
  pointer-events: none;
  white-space: nowrap;
}
.world__label small {
  font-weight: 500;
  letter-spacing: 0;
}
.world__pick {
  position: absolute;
  width: 74px;
  height: 42px;
  transform: translate(-50%, -50%);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  background: rgba(239, 200, 112, 0.35);
  outline: 2px solid var(--vang-200);
  pointer-events: none;
}
.world__pick::after {
  content: '';
  position: absolute;
  inset: 3px;
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  border: 2px solid var(--vang-200);
}

/* ---------------------------------------------------------------- surfaces */
.paper {
  background-color: var(--surface-paper);
  background-image: var(--paper-tex), radial-gradient(130% 100% at 50% 0%, rgba(255, 250, 235, 0.55), transparent 60%);
  color: var(--text);
}
.paper-2 {
  background-color: var(--surface-paper-2);
  background-image: var(--paper-tex);
}
/* lacquer frame: son frame, a thin gold-leaf line inside, a black edge outside, cloud-scroll corners */
.frame {
  position: relative;
  border: 4px solid var(--frame);
  border-radius: var(--radius);
  box-shadow:
    inset 0 0 0 1px var(--vang-400),
    inset 0 0 0 2px rgba(60, 8, 2, 0.35),
    0 0 0 1px var(--then-900),
    var(--shadow);
}
.frame--dark {
  border-color: var(--then-700);
}
.corner {
  position: absolute;
  width: 26px;
  height: 26px;
  color: var(--vang-500);
  pointer-events: none;
  z-index: 1;
}
.corner svg {
  width: 100%;
  height: 100%;
}
.corner--tl {
  top: 2px;
  left: 2px;
}
.corner--tr {
  top: 2px;
  right: 2px;
  transform: scaleX(-1);
}
.corner--bl {
  bottom: 2px;
  left: 2px;
  transform: scaleY(-1);
}
.corner--br {
  bottom: 2px;
  right: 2px;
  transform: scale(-1, -1);
}
.watermark {
  position: absolute;
  right: -46px;
  bottom: -46px;
  width: 210px;
  height: 210px;
  color: var(--chu-500);
  opacity: 0.075;
  pointer-events: none;
}
.watermark svg {
  width: 100%;
  height: 100%;
}
.lacquer {
  background: var(--lacquer-red);
  color: var(--text-on-lacquer);
}
.lacquer-black {
  background: var(--lacquer-black);
  color: var(--text-on-lacquer);
}
.hairline {
  height: 1px;
  border: 0;
  margin: 8px 0;
  background: linear-gradient(90deg, transparent, var(--paper-400) 15%, var(--paper-400) 85%, transparent);
}
.ornament-rule {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-title);
  font-family: var(--font-title);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.ornament-rule::before,
.ornament-rule::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--muc-500));
}
.ornament-rule::after {
  background: linear-gradient(90deg, var(--muc-500), transparent);
}

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: max(32px, var(--tap));
  padding: 0 12px;
  border: 1px solid var(--paper-400);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, var(--paper-50), var(--paper-200));
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset, 0 1px 2px rgba(36, 27, 18, 0.2);
}
.btn:hover {
  border-color: var(--muc-500);
}
.btn:focus-visible,
.icon-btn:focus-visible,
.tile:focus-visible {
  outline: 2px solid var(--focus-paper);
  outline-offset: 2px;
}
.btn--primary {
  border-color: var(--then-900);
  background: var(--lacquer-red);
  color: var(--paper-50);
  box-shadow: inset 0 0 0 1px var(--vang-500), 0 2px 4px rgba(9, 8, 6, 0.35);
}
.btn--primary .glyph {
  color: var(--vang-200);
}
.btn--danger {
  color: var(--bad);
}
.btn--ghost {
  background: transparent;
  box-shadow: none;
}
.btn[disabled],
.btn.is-disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.btn kbd,
.keycap {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border: 1px solid var(--paper-400);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--paper-50);
  color: var(--text-2);
  font: 600 10.5px/1 var(--font-ui);
}
.btn--primary kbd {
  border-color: var(--vang-600);
  background: rgba(9, 8, 6, 0.3);
  color: var(--vang-200);
}
:root[data-input='touch'] kbd,
:root[data-input='touch'] .keycap {
  display: none;
}
.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: max(30px, var(--tap));
  height: max(30px, var(--tap));
  padding: 0;
  border: 1px solid var(--then-900);
  border-radius: 50%;
  background: var(--lacquer-red);
  color: var(--vang-200);
  box-shadow: inset 0 0 0 1px var(--vang-500), 0 1px 3px rgba(9, 8, 6, 0.35);
}
.icon-btn--paper {
  border-color: var(--paper-400);
  background: linear-gradient(180deg, var(--paper-50), var(--paper-200));
  color: var(--text-2);
  box-shadow: 0 1px 2px rgba(36, 27, 18, 0.2);
}

/* ---------------------------------------------------------------- chips, rings, status */
.stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.good-icon {
  flex: none;
  object-fit: contain;
  filter: drop-shadow(0 1px 1px rgba(36, 27, 18, 0.35));
}
.portrait {
  flex: none;
  border-radius: 50%;
  object-fit: cover;
  object-position: 50% 20%;
  background: radial-gradient(circle at 50% 35%, var(--paper-50), var(--paper-300));
  box-shadow: 0 0 0 2px var(--tone, var(--vang-400)), 0 0 0 3px var(--then-900);
}
.bar {
  position: relative;
  height: 4px;
  border-radius: 2px;
  background: rgba(36, 27, 18, 0.16);
  overflow: hidden;
}
.bar > i {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 2px;
  background: var(--good-ui);
}
.bar.is-warn > i {
  background: var(--warn-ui);
}
.bar.is-bad > i {
  background: var(--bad);
}

/* need ring (NeedList): fulfilment ring, ! when short, padlock + residents when locked, violet when luxury */
.need {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--ring, 52px);
  height: var(--ring, 52px);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
}
.need svg.ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.need .ring__track {
  fill: var(--paper-50);
  stroke: rgba(36, 27, 18, 0.14);
}
.need .ring__fill {
  fill: none;
  stroke: var(--good-ui);
  stroke-linecap: round;
}
.need.is-warn .ring__fill {
  stroke: var(--warn-ui);
}
.need.is-bad .ring__fill {
  stroke: var(--bad);
}
.need.is-luxury .ring__fill {
  stroke: var(--luxury-ui);
}
.need.is-locked .ring__track {
  stroke: var(--muc-400);
  stroke-dasharray: 3 3;
}
.need__img {
  position: relative;
  width: 68%;
  height: 68%;
  object-fit: contain;
}
.need.is-locked .need__img {
  filter: grayscale(1) opacity(0.45);
}
.need__flag {
  position: absolute;
  top: -2px;
  right: -2px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid var(--paper-50);
  background: var(--nghe-500);
  color: var(--then-900);
  font: 800 12px/1 var(--font-ui);
}
.need.is-bad .need__flag {
  background: var(--bad);
  color: var(--paper-50);
}
.need__lock {
  position: absolute;
  right: -3px;
  bottom: -3px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--paper-50);
  background: var(--then-700);
  color: var(--paper-50);
}
.need__lux {
  position: absolute;
  left: -3px;
  bottom: -3px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid var(--paper-50);
  background: var(--luxury-ui);
  color: var(--paper-50);
}
.need__svc {
  position: absolute;
  left: -3px;
  top: -3px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid var(--paper-50);
  background: var(--ngoc-500);
  color: var(--paper-50);
}
.need-cell {
  display: grid;
  justify-items: center;
  gap: 3px;
  min-width: 0;
  text-align: center;
}
.need-cell__name {
  max-width: 100%;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.need-cell__sub {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.1;
  white-space: nowrap;
}
.need-cell__sub .glyph {
  display: inline-block;
  vertical-align: -2px;
}
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 4px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
}
.status__dot {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: var(--paper-50);
}
.status--ok {
  background: rgba(70, 125, 34, 0.12);
  color: var(--good);
}
.status--ok .status__dot {
  background: var(--good-ui);
}
.status--warn {
  background: rgba(168, 95, 0, 0.12);
  color: var(--warn);
}
.status--warn .status__dot {
  background: var(--nghe-500);
  color: var(--then-900);
}
.status--bad {
  background: rgba(163, 31, 18, 0.1);
  color: var(--bad);
}
.status--bad .status__dot {
  background: var(--bad);
}

/* InfoTip ⓘ and tooltips (hover / focus; data-show forces one open for the gallery) */
.tipped {
  position: relative;
}
.tip {
  position: absolute;
  z-index: 50;
  left: 50%;
  top: calc(100% + 8px);
  width: max-content;
  max-width: 240px;
  padding: 7px 10px;
  border: 1px solid var(--vang-600);
  border-radius: 6px;
  background: var(--then-800);
  color: var(--paper-50);
  font: 500 12.5px/1.35 var(--font-ui);
  text-align: left;
  white-space: normal;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.12s;
}
.tip b {
  color: var(--vang-200);
}
.tip::before {
  content: '';
  position: absolute;
  left: 50%;
  top: -6px;
  width: 10px;
  height: 10px;
  border-left: 1px solid var(--vang-600);
  border-top: 1px solid var(--vang-600);
  background: var(--then-800);
  transform: translateX(-50%) rotate(45deg);
}
.tip--up {
  top: auto;
  bottom: calc(100% + 8px);
}
.tip--up::before {
  top: auto;
  bottom: -6px;
  transform: translateX(-50%) rotate(225deg);
}
.tip--left {
  left: auto;
  right: -6px;
  transform: none;
}
.tip--left::before {
  left: auto;
  right: 12px;
  transform: rotate(45deg);
}
.tipped:hover > .tip,
.tipped:focus-visible > .tip,
.tipped:focus-within > .tip,
.tipped[data-show] > .tip {
  opacity: 1;
  visibility: visible;
}
.infotip {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--info);
  vertical-align: -3px;
}
.badge-new {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--ngoc-500);
  color: var(--paper-50);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.draft-tag {
  display: inline-block;
  padding: 0 5px;
  border: 1px solid currentColor;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.75;
}
a {
  color: inherit;
  text-decoration: none;
}
