:root {
  color-scheme: light;
  --ivory: #f1ece3;
  --warm-white: #fffaf2;
  --ink: #292823;
  --bronze: #8b6d46;
  --orange: #ed5b20;
  --line: rgba(71, 61, 48, 0.17);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: Inter, "Noto Sans Khmer", "Noto Sans SC", "PingFang SC", system-ui, sans-serif;
  background: var(--ivory);
  color: var(--ink);
}

button { font: inherit; }

#app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 239, 230, 0.92);
  backdrop-filter: blur(18px);
  z-index: 20;
}

.eyebrow {
  margin: 0 0 2px;
  color: #806d55;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .16em;
}

h1 {
  margin: 0;
  font-size: clamp(20px, 3vw, 30px);
  letter-spacing: .02em;
  font-weight: 720;
}

h1 span {
  margin-left: 7px;
  color: var(--orange);
  font-size: .52em;
  font-weight: 800;
  vertical-align: middle;
}

.top-actions { display: flex; gap: 8px; }

.ghost {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid rgba(88, 73, 54, .24);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255, 255, 255, .58);
  cursor: pointer;
}

.ghost:hover, .ghost.active {
  color: #fff;
  background: var(--ink);
}

#viewport {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 48% 34%, rgba(255,255,255,.88), transparent 42%),
    linear-gradient(#dce8ed 0 56%, #ddd2c1 56% 100%);
}

#viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#loading {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  background: #eee7dc;
  transition: opacity .45s ease, visibility .45s ease;
}

#loading.hidden { opacity: 0; visibility: hidden; }

#loading small { color: #7b7062; }

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(70, 59, 45, .14);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.brand-card {
  position: absolute;
  top: 18px;
  left: 20px;
  display: grid;
  padding: 10px 14px;
  border: 1px solid rgba(255,255,255,.65);
  border-radius: 13px;
  color: #5a4936;
  background: rgba(255, 250, 242, .72);
  box-shadow: 0 10px 34px rgba(63, 51, 37, .08);
  backdrop-filter: blur(14px);
  pointer-events: none;
}

.brand-card b { font-size: 18px; }
.brand-card span { font-size: 10px; opacity: .72; }
.brand-card em { font-size: 10px; font-style: normal; letter-spacing: .18em; }

.info-card {
  position: absolute;
  top: 20px;
  right: 20px;
  width: min(310px, calc(100% - 40px));
  padding: 19px;
  border: 1px solid rgba(255,255,255,.63);
  border-radius: 16px;
  background: rgba(255, 250, 242, .8);
  box-shadow: 0 18px 54px rgba(52, 43, 33, .13);
  backdrop-filter: blur(18px);
  transition: opacity .25s, transform .25s;
}

.info-card.closed {
  opacity: 0;
  transform: translateX(18px);
  pointer-events: none;
}

#infoClose {
  position: absolute;
  top: 9px;
  right: 10px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  font-size: 20px;
}

.info-kicker {
  margin: 0 0 6px;
  color: var(--orange);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .14em;
}

.info-card h2 { margin: 0 0 7px; font-size: 22px; }
.info-card > p:not(.info-kicker) { margin: 0; color: #635c52; font-size: 13px; line-height: 1.6; }
.info-card dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 14px 0 0; }
.info-card dl div { padding: 8px; border-radius: 10px; background: rgba(117, 97, 69, .07); }
.info-card dt { color: #897c6c; font-size: 9px; }
.info-card dd { margin: 2px 0 0; font-size: 11px; font-weight: 700; }

.hint {
  position: absolute;
  bottom: 92px;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 12px;
  border-radius: 999px;
  color: rgba(255,255,255,.92);
  background: rgba(35,33,29,.62);
  backdrop-filter: blur(8px);
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
  animation: hint 5s 1.8s forwards;
}

@keyframes hint { 70%, 100% { opacity: 0; } }

.views {
  position: absolute;
  z-index: 10;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  padding: 7px;
  border: 1px solid rgba(255,255,255,.5);
  border-radius: 17px;
  background: rgba(42, 39, 34, .72);
  box-shadow: 0 12px 34px rgba(25,22,18,.2);
  backdrop-filter: blur(14px);
}

.view {
  display: grid;
  justify-items: center;
  gap: 2px;
  min-width: 75px;
  padding: 8px 10px;
  border: 0;
  border-radius: 11px;
  color: rgba(255,255,255,.76);
  background: transparent;
  cursor: pointer;
  font-size: 11px;
}

.view i { color: #ddc3a2; font-size: 8px; font-style: normal; letter-spacing: .14em; }
.view:hover, .view.active { color: var(--ink); background: #fff8ec; }
.view.active i { color: var(--orange); }

footer {
  min-height: 32px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 7px 24px;
  border-top: 1px solid var(--line);
  background: #eee7dc;
  color: #71685b;
  font-size: 10px;
}

body.night .topbar, body.night footer { background: #25282b; color: #ede5d8; border-color: rgba(255,255,255,.1); }
body.night .eyebrow, body.night footer { color: #aea599; }
body.night .ghost { color: #eee5d8; border-color: rgba(255,255,255,.22); background: rgba(255,255,255,.07); }
body.night #viewport { background: linear-gradient(#101820 0 56%, #1b1b1b 56% 100%); }

@media (max-width: 760px) {
  .topbar { min-height: 66px; padding: 10px 12px; }
  .eyebrow { font-size: 8px; }
  h1 { font-size: 20px; }
  .ghost { min-height: 36px; padding: 0 10px; font-size: 11px; }
  .brand-card { top: 10px; left: 10px; padding: 7px 10px; }
  .brand-card b { font-size: 14px; }
  .info-card { top: 10px; right: 10px; max-width: 270px; padding: 14px; }
  .info-card h2 { font-size: 18px; }
  .info-card dl { display: none; }
  .views {
    left: 8px;
    right: 8px;
    bottom: 10px;
    transform: none;
    overflow-x: auto;
    justify-content: flex-start;
    scrollbar-width: none;
  }
  .views::-webkit-scrollbar { display: none; }
  .view { min-width: 68px; padding: 7px 8px; }
  .hint { bottom: 84px; }
  footer { display: none; }
}

@media (max-width: 430px) {
  h1 span { display: none; }
  .info-card { top: auto; right: 10px; bottom: 84px; width: calc(100% - 20px); }
  .info-card > p:not(.info-kicker) { font-size: 11px; }
  .brand-card span, .brand-card em { display: none; }
}
