/* Bố cục: một sân khấu 16:9 trong khung gỗ thủy đình; phụ đề phủ đáy sân khấu khi màn hình ngang,
   nằm dưới sân khấu khi màn hình dọc. Chỉ một tông tối, có chủ đích. */
:root {
  --go-dam: #17100B;      /* nền quanh sân khấu: gỗ thủy đình */
  --go: #2C1E14;
  --giay: #EFE3C8;        /* giấy điệp */
  --giay-dam: #E4CC9C;
  --than: #2B2118;        /* nét viền */
  --son: #B5452E;         /* đỏ son */
  --hoe: #D9A33A;         /* vàng hoè */
  --phu-de: rgba(23, 16, 11, 0.9);
  --font-van: "Alegreya", Georgia, "Times New Roman", serif;
  --font-nhan: "Alegreya SC", "Alegreya", Georgia, serif;
  color-scheme: dark;
}

[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--go-dam);
  color: var(--giay);
  font-family: var(--font-van);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100%;
  box-sizing: border-box;
  padding-inline: 16px;
  padding-block: 44px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#stage-wrap {
  position: relative;
  width: 100%;
  max-width: 1280px;
  display: flex;
  flex-direction: column;
}

#screen {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-width: 100%;
  overflow: hidden;
  border: 3px solid #000;
  outline: 6px solid var(--go);
  box-shadow: 0 0 0 9px var(--hoe), 0 0 0 12px #000, 0 18px 40px rgba(0, 0, 0, 0.6);
  background: var(--giay);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
#stage { display: block; width: 100%; height: 100%; touch-action: none; }
/* vân giấy và quầng tối viền sân khấu */
#screen::after {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  background-image: var(--van-giay, none), radial-gradient(ellipse at center, transparent 55%, rgba(30, 18, 8, 0.38) 100%);
  mix-blend-mode: multiply;
}

#fade { position: absolute; inset: 0; background: #000; opacity: 1; pointer-events: none; }

#card {
  position: absolute; left: 50%; top: 50%;
  translate: -50% -50%;
  min-width: min(70%, 420px);
  padding: 22px 34px;
  background: var(--giay);
  color: var(--than);
  border: 3px solid var(--than);
  box-shadow: 6px 6px 0 var(--than);
  text-align: center;
  rotate: -0.6deg;
}
#card p { margin: 0; font-size: clamp(16px, 2.2vw, 22px); font-style: italic; }
#card p.nam { font-family: var(--font-nhan); font-style: normal; font-size: clamp(22px, 3.4vw, 36px); letter-spacing: 0.06em; color: var(--son); }

#hint {
  position: absolute; left: 50%; top: 6%;
  translate: -50% 0;
  padding: 6px 14px;
  background: var(--than); color: var(--giay);
  border: 2px solid var(--hoe);
  font-size: clamp(13px, 1.7vw, 16px);
  animation: nhay 1.6s ease-in-out infinite;
  pointer-events: none;
}
@keyframes nhay { 50% { opacity: 0.55; } }

#wipe {
  position: absolute; inset: -2% -6%;
  background-color: var(--giay);
  background-image: var(--van-giay, none);
  clip-path: polygon(3% 0, 97% 0, 95% 8%, 98% 16%, 95% 25%, 99% 36%, 96% 47%, 98% 58%, 95% 69%, 98% 80%, 96% 90%, 98% 100%, 2% 100%, 5% 91%, 2% 81%, 4% 70%, 1% 59%, 4% 47%, 2% 35%, 5% 24%, 2% 13%, 4% 6%);
  display: grid; place-items: center;
  transform: translateX(-108%);
}
#wipe span { font-family: var(--font-nhan); color: var(--son); font-size: clamp(22px, 3.6vw, 40px); letter-spacing: 0.08em; }

/* ---------- Phụ đề và lựa chọn ---------- */
#panel { display: flex; flex-direction: column; gap: 10px; padding-block: 16px 4px; min-height: 8.5em; }
#sub { position: relative; max-width: 62ch; padding-right: 24px; }
#sub .prev {
  margin: 0 0 6px;
  font-size: clamp(14px, 1.7vw, 17px);
  line-height: 1.4;
  color: var(--giay-dam);
  font-style: italic;
}
#sub .who {
  font-family: var(--font-nhan);
  color: var(--hoe);
  letter-spacing: 0.08em;
  font-size: clamp(13px, 1.6vw, 16px);
  min-height: 1.2em;
}
#sub .line { margin: 2px 0 0; font-size: clamp(17px, 2.1vw, 22px); line-height: 1.45; text-wrap: pretty; }
#sub.narr .line { font-style: italic; color: var(--giay-dam); }
#sub .next {
  position: absolute; right: 0; bottom: 8px;
  width: 0; height: 0;
  border-left: 7px solid transparent; border-right: 7px solid transparent; border-top: 9px solid var(--hoe);
  opacity: 0;
}
#sub.ready .next { opacity: 1; animation: nhay 1.1s ease-in-out infinite; }

#choices { display: flex; flex-wrap: wrap; gap: 10px; }
.choice {
  font: inherit;
  font-size: clamp(15px, 1.8vw, 18px);
  color: var(--than);
  background: var(--giay);
  border: 2.5px solid #000;
  box-shadow: 3px 3px 0 #000;
  padding: 9px 14px;
  text-align: left;
  cursor: pointer;
  rotate: -0.5deg;
  transition: background 0.15s, translate 0.15s;
}
.choice:nth-child(2) { rotate: 0.4deg; }
.choice:hover, .choice:focus-visible { background: var(--giay-dam); translate: 0 -2px; }
.choice:focus-visible { outline: 3px solid var(--hoe); outline-offset: 2px; }
.choice.chosen { background: var(--hoe); }

#xoay { margin: 18px 0 0; font-size: 14px; font-style: italic; color: var(--giay-dam); opacity: 0.7; text-align: center; }
@media (orientation: landscape) { #xoay { display: none; } }

/* màn hình ngang: phụ đề phủ đáy sân khấu */
@media (orientation: landscape) and (min-width: 700px) {
  #app { padding-block: 40px 16px; }
  #stage-wrap { width: min(100%, calc((100dvh - 64px) * 16 / 9)); }
  #panel {
    position: absolute; left: 3px; right: 3px; bottom: 3px;
    padding: 46px 28px 18px;
    min-height: 0;
    background: linear-gradient(to top, var(--phu-de) 58%, transparent);
    pointer-events: none;
  }
  #panel > * { pointer-events: auto; }
  #panel:has(#sub[hidden]):has(#choices[hidden]) { background: none; }
}

/* ---------- Thanh điều khiển và màn kết ---------- */
#hud {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  right: 16px;
  display: flex; gap: 8px;
}
#hud button, #end button {
  font: inherit; font-size: 14px;
  color: var(--giay);
  background: var(--go);
  border: 1.5px solid var(--hoe);
  padding: 5px 12px;
  cursor: pointer;
}
#hud button:focus-visible, #end button:focus-visible { outline: 3px solid var(--hoe); outline-offset: 2px; }
#hud .ten { position: fixed; left: 16px; top: calc(env(safe-area-inset-top, 0px) + 12px); font-family: var(--font-nhan); color: var(--giay-dam); letter-spacing: 0.08em; font-size: 14px; }

#end {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: rgba(10, 7, 4, 0.82);
  padding-inline: 16px;
}
#end .giay {
  max-width: 440px;
  background: var(--giay); color: var(--than);
  border: 3px solid var(--than);
  box-shadow: 8px 8px 0 #000;
  padding: 24px 26px;
  display: flex; flex-direction: column; gap: 10px;
}
#end h2 { margin: 0; font-family: var(--font-nhan); color: var(--son); font-size: 28px; letter-spacing: 0.05em; font-weight: 400; }
#end p { margin: 0; line-height: 1.5; }
#end .nho { font-size: 14px; opacity: 0.75; font-style: italic; }
#end .nut { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
#end button { color: var(--than); background: var(--giay-dam); border: 2px solid var(--than); }

/* con trỏ cho nửa con cá kéo được */
.keo-duoc { cursor: grab; }
.bong-ma path:first-child { fill-opacity: 0.35; stroke-dasharray: 8 7; }

@media (prefers-reduced-motion: reduce) {
  #hint, #sub.ready .next { animation: none; }
}
