:root {
  color-scheme: dark;
  font: 1rem system-ui, sans-serif;
  color: #f8efd8;
  background: #102720;
  --lacquer: #102720;
  --lacquer-deep: #0a1b17;
  --bronze: #9a6b2f;
  --bronze-light: #d3b06a;
  --parchment: #f0e1bd;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { height: 100dvh; display: flex; flex-direction: column; margin: 0; overflow: hidden; }
#toolbar {
  position: absolute; z-index: 3;
  top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right));
  display: flex; align-items: center; justify-content: flex-end; gap: .35rem;
  width: max-content; max-width: calc(100% - 16px); padding: 0;
}
#toolbar button {
  height: 40px; min-height: 40px; min-width: 0; padding: 0 clamp(.35rem, 2cqw, .55rem); white-space: normal;
  font: 700 clamp(.6rem, 2.8cqw, .76rem)/1 system-ui, sans-serif; letter-spacing: .01em; cursor: pointer; touch-action: manipulation;
  background: var(--bronze); color: #fff7df; border: 1px solid var(--bronze-light); border-radius: .25rem;
  box-shadow: inset 0 0 0 1px #3d271466;
}
#toolbar button:active { background: #7f5425; }
#toolbar[data-game-id="hao-khi-co-loa"] {
  /* Co Loa draws its 9:16 main background inside a wider Unity canvas. */
  right: calc((100% - min(100%, 56.25cqh)) / 2 + max(8px, env(safe-area-inset-right)));
  max-width: calc(min(100%, 56.25cqh) - 16px);
}
#mode-name {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
button:focus-visible { outline: 2px solid var(--parchment); outline-offset: 2px; }
#stage { position: relative; display: grid; flex: 1; min-width: 0; min-height: 0; place-items: center; container-type: size; }
#game-frame { position: relative; width: 100%; height: 100%; min-width: 0; min-height: 0; container-type: size; }
#canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#stage.mode #game-frame {
  --ratio: 1.777778;
  width: min(100cqw, calc(100cqh * var(--ratio)));
  height: min(100cqh, calc(100cqw / var(--ratio)));
}
#stage.portrait #game-frame { --ratio: .5625; }
#stage.hub #canvas {
  width: 100cqw;
  height: 100cqh;
}
#progress {
  position: absolute; z-index: 4; max-width: min(90%, 24rem); margin: 0; padding: .75rem 1rem;
  border: 1px solid #765328; border-radius: .25rem; background: #0c241cf5; text-align: center;
  box-shadow: 0 .4rem 1.5rem #0008;
}
#progress.loading::before {
  content: ""; display: inline-block; width: .8rem; height: .8rem; margin-right: .55rem;
  border: 2px solid var(--bronze-light); border-top-color: transparent; border-radius: 50%;
  animation: unified-loading-spin .8s linear infinite; vertical-align: -.12rem;
}
@keyframes unified-loading-spin { to { transform: rotate(360deg); } }
#sync-status {
  position: fixed; right: max(.55rem, env(safe-area-inset-right)); bottom: max(.45rem, env(safe-area-inset-bottom));
  max-width: min(22rem, calc(100vw - 1.1rem)); pointer-events: none;
  margin: 0; padding: .38rem .55rem; border: 1px solid #765328; border-radius: .25rem;
  background: #102720ed; color: #f8efd8; font-size: .8rem; line-height: 1.3;
}
#room-panel { position: absolute; z-index: 2; width: min(92%, 390px); max-height: 92%; overflow: auto;
  background: #fffaf0; color: #194133; padding: .9rem; border-radius: .6rem; box-shadow: 0 0 0 100vmax #13251fb3; }
#room-panel p { margin: 0 0 .65rem; font-weight: 650; }
#room-panel button, #room-strip button { min-height: 40px; margin: .2rem; }
#room-panel input { display: block; width: 100%; min-height: 40px; margin: .3rem 0; }
#room-strip { position: absolute; top: .3rem; right: .3rem; background: #102720ed; padding: .2rem .5rem; }
#stage:has(#room-panel:not([hidden])) #canvas { pointer-events: none; }
#reward-toast { position: fixed; right: 18px; bottom: 28px; z-index: 10; max-width: min(380px, 90vw); padding: 20px; background: #efe3bc; color: #17382c; border: 1px solid #b59c62; box-shadow: 0 8px 35px #0005; }
#reward-toast p { margin: 0 0 12px; font-weight: 600; }
#reward-toast button { min-height: 40px; padding: 8px 14px; margin-right: 8px; cursor: pointer; background: #17382c; color: #fff8e5; border: 0; font: inherit; }
