*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

body {
  -webkit-user-select: none;
  user-select: none;
}

html,
body {
  background-color: #000;
  font-family: "IBM Plex Sans Thai", sans-serif;
  overflow: hidden;
}

.game-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
}

.game-container {
  position: relative;
  width: 100%;
  max-width: 430px;
  height: 100dvh;
  max-height: 932px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: #0a0a0a;
}

@media (min-width: 500px) {
  .game-container {
    border-radius: 12px;
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.08),
      0 24px 80px rgba(0, 0, 0, 0.8);
  }
}

:fullscreen .game-wrapper {
  align-items: center;
}

:fullscreen .game-container {
  max-width: none;
  max-height: none;
  height: 100dvh;
  width: auto;
  aspect-ratio: 430 / 932;
  border-radius: 0;
  box-shadow: none;
}

@media (max-width: 499px) {
  .game-wrapper { align-items: stretch; }
  .game-container { max-width: 100%; max-height: 100%; }
}

/* ── Fullscreen button ───────────────────────────── */
#btn-fullscreen {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 1000;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 0.5px solid rgba(255, 255, 255, 0.4);
  background: rgba(0, 0, 0, 0.5);
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  transition: background 0.2s;
}

/* ── Landscape warning ───────────────────────────── */
#landscape-warning {
  display: none;
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: #000;
  color: #fff;
  font-size: 1.1rem;
  z-index: 9999;
}

#landscape-warning.visible {
  display: flex;
}

/* ── Loading screen ──────────────────────────────── */
#loading-screen {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: #0a0a0a;
  transition: opacity 0.4s ease;
}

#loading-screen.done {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.9rem;
}

.loading-bar {
  width: 55%;
  height: 2px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  overflow: hidden;
}

#loading-bar-fill {
  height: 100%;
  width: 0%;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 999px;
  transition: width 0.2s ease;
}

/* ── Splash page ─────────────────────────────────── */
#splash {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background-image: url("../img/splash_screen.webp");
  background-size: cover;
  background-position: center top;
  transition: opacity 0.5s ease;
}

#splash.fading-out {
  opacity: 0;
  pointer-events: none;
}

.game-fade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: linear-gradient(
    to bottom,
    #0a0a0a 0%,
    transparent 20%,
    transparent 80%,
    #0a0a0a 100%
  );
}

.game-screen {
  flex: 1;
  position: relative;
  overflow: hidden;
  z-index: 2;
}

.game-title {
  margin-top: 32px;
  width: 70%;
  max-width: 300px;
  height: auto;
  display: block;
  margin-inline: auto;
}

.game-ui {
  flex-shrink: 0;
  padding: 20px 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 2;
}

.btn-start {
  width: 100%;
  padding: 16px;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background 0.2s, border-color 0.2s;
}

.btn-start:hover,
.btn-start:focus-visible {
  background: rgb(0 0 0 / 100%);
  outline: none;
}

/* ── Shared screen layer ─────────────────────────── */
.game-screen-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.game-screen-layer.visible {
  opacity: 1;
}

/* ── Shared scene background ─────────────────────── */
.scene-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  transition: transform 0.85s ease, opacity 0.85s ease;
}

.scene-bg.exiting {
  transform: scale(1.08);
  opacity: 0;
}

.scene-bg.entering {
  animation: scene-fade-in 0.6s ease forwards;
}

@keyframes scene-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Shared next button ──────────────────────────── */
.btn-round-next {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.6);
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  transition: border-color 0.2s;
}

.btn-round-next:active {
  border-color: #fff;
}

/* ── Plot page ───────────────────────────────────── */
#plot-screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.5s ease;
}

#plot-screen.visible {
  opacity: 1;
}

.plot-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(2px);
}

.plot-text-box {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 28px;
}

#plot-text {
  color: #fff;
  font-size: 1.3rem;
  line-height: 1.8;
  letter-spacing: 0.01em;
  text-align: center;
  max-width: 90%;
}

#btn-next {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.6);
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  transition: border-color 0.2s;
}

#btn-next:active {
  border-color: #fff;
}

/* ── Dialog page ─────────────────────────────────── */
#dialog-screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.5s ease;
}

#dialog-screen.visible {
  opacity: 1;
}

.dialog-char-area {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.dialog-char {
  position: absolute;
  bottom: 0;
  height: 78%;
  width: auto;
  max-width: 60%;
  object-fit: contain;
  transition: filter 0.3s ease;
}

#char-left  { left: -8px; transform: scaleX(-1); }
#char-right { right: -8px; }

.dialog-char.inactive { filter: brightness(0.35); }

#dialog-box {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(10, 10, 10, 0.88);
  backdrop-filter: blur(8px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 16px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 0.5rem 0.5rem 0.5rem;
  border-radius: 0.5rem;
  box-shadow: 0px 1px 4px #272727;
}

.dialog-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dialog-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.3);
  flex-shrink: 0;
}

#dialog-name {
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
}

#dialog-text {
  color: rgba(255, 255, 255, 0.92);
  font-size: 1.05rem;
  line-height: 1.75;
  min-height: 3.5em;
}

#dialog-btn-next {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.6);
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  transition: border-color 0.2s;
}

#dialog-btn-next:active {
  border-color: #fff;
}

/* ── Select page ─────────────────────────────────── */
#select-screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.5s ease;
}

#select-screen.visible {
  opacity: 1;
}

.select-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(2px);
}

.select-content {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 28px;
  gap: 20px;
}

#select-title {
  color: #fff;
  font-size: 1.2rem;
  font-weight: 600;
  text-align: center;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}

#select-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#select-timer-wrap {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  margin-bottom: 4px;
  border: 2px solid rgba(255, 255, 255, 0.25);
}

#select-timer-count {
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
}

.select-option {
  width: 100%;
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  color: #fff;
  font-size: 1rem;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background 0.2s, border-color 0.2s;
}

.select-option:hover,
.select-option:focus-visible {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.45);
  outline: none;
}

.select-option:active {
  background: rgba(255, 255, 255, 0.22);
}
