* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #050505;
  color: #f5f5f5;
}

body {
  overflow: hidden;
}

#app {
  height: 100vh;
  width: 100vw;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.screen {
  position: relative;
  width: 100%;
  max-width: 800px; /* Increased for desktop */
  height: 100%;
  margin: 0 auto;
  display: none;
  background: #000;
  border-left: 1px solid #333;
  border-right: 1px solid #333;
}

@media (max-width: 600px) {
  .screen {
    max-width: 100%;
    border: none;
  }
}

/* PC-only controls */
.pc-only {
  display: none;
}

.screen.active {
  display: flex;
}

/* INTRO */

#intro-screen {
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
}

.intro-layer {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 800px;
  margin: 0 auto;
  overflow: hidden;
  background: #000;
}

.intro-zoom {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 70%;
  max-width: 420px;
  height: auto;
  object-fit: contain;
  animation: introZoomIn 8s forwards;
}

.intro-border {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0.9;
  pointer-events: none;
}

.intro-border-left {
  left: 0;
  animation: borderSlideLeft 10s linear infinite alternate;
}

.intro-border-right {
  right: 0;
  opacity: 0.5;
  animation: borderSlideRight 10s linear infinite alternate;
}

.intro-skip-btn {
  position: absolute;
  right: 12px;
  bottom: 12px;
  border-radius: 999px;
  border: none;
  padding: 6px 12px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.9);
  color: #000;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  z-index: 5;
}

/* Retro intro text */
#intro-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
  pointer-events: none;
}

.intro-text-main {
  font-family: "Courier New", monospace;
  font-size: 16px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #f5f5f5;
  text-shadow:
    0 0 2px #000,
    0 0 6px rgba(0, 255, 200, 0.6);
  animation: introTextFlicker 1.1s infinite steps(2, start);
}

@keyframes introTextFlicker {
  0%, 40%, 100% { opacity: 1; }
  45%, 48% { opacity: 0.4; }
  60% { opacity: 0.8; }
}

#white-flash {
  position: absolute;
  inset: 0;
  background: #ffffff;
  opacity: 0;
  pointer-events: none;
}

@keyframes introZoomIn {
  from { transform: scale(1); opacity: 0.6; }
  40% { opacity: 1; }
  to { transform: scale(1.3); opacity: 1; }
}

@keyframes borderSlideLeft {
  from { transform: translateX(0); }
  to { transform: translateX(16%); }
}

@keyframes borderSlideRight {
  from { transform: translateX(0); }
  to { transform: translateX(-4%); }
}

/* MENU */

#menu-screen {
  align-items: center;
  justify-content: center;
  background: 
    linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.7)),
    url('paper school.webp') no-repeat center center;
  background-size: cover;
}

.menu-panel {
  width: 100%;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  z-index: 2;
}

.title-image {
  width: 100%;
  height: auto;
  max-width: 360px;
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 70%;
  max-width: 260px;
}

.primary-btn,
.secondary-btn,
.icon-btn {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  cursor: pointer;
}

.primary-btn {
  background: #e0e0e0;
  color: #151515;
}

.primary-btn:active {
  transform: translateY(1px);
  background: #f0f0f0;
}

.secondary-btn {
  background: #292929;
  color: #f5f5f5;
}

.secondary-btn:active {
  transform: translateY(1px);
  background: #343434;
}

.icon-btn {
  background: transparent;
  color: inherit;
  padding: 4px 8px;
  font-size: 18px;
}

/* Settings overlay */

.overlay-panel {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.overlay-panel.hidden {
  display: none;
}

.overlay-content {
  width: 90%;
  max-width: 340px;
  background: #141414;
  border-radius: 16px;
  padding: 14px 16px 16px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 16px;
}

.settings-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
}

input[type="range"] {
  width: 100%;
}

/* GAME */

#game-screen {
  flex-direction: column;
  background: #050505;
}

#game-top {
  flex: 0 0 54%;
  display: flex;
  flex-direction: column;
  padding: 8px 8px 4px;
  gap: 4px;
}

#location-label {
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #c4c4c4;
  padding: 2px 6px;
  border-radius: 999px;
  align-self: flex-start;
  background: #1a1a1a;
}

#scene {
  flex: 1;
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: #101010;
}

#scene-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
}

#scene-characters {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 12px;
  padding: 6px 10px;
  pointer-events: none;
  z-index: 5;
}

.character-card {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.character-card button {
  border: none;
  padding: 0;
  background: none;
}

.character-sprite {
  width: 64px;
  height: 64px;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 6px rgba(0, 0, 0, 0.85));
  transition: transform 0.3s ease;
}

.character-card.talking .character-sprite {
  transform: scale(1.8) translateY(-10px);
  filter: drop-shadow(0 0 12px rgba(255, 255, 255, 0.45));
  z-index: 10;
}

/* Overlays reuse existing overlay-panel but make inner list scrollable */
#relationships-list, #saves-list {
  max-height: 48vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.character-name {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
}

/* Top right time/lesson */

.time-lesson {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-size: 11px;
  color: #d0d0d0;
}

#stat-time {
  font-weight: 600;
}

#stat-lesson {
  color: #f1c27d;
}

#stat-role {
  color: #9bd7ff;
}

/* Bottom UI */

#game-bottom {
  flex: 0 0 46%;
  display: flex;
  flex-direction: column;
  padding: 4px 8px 8px;
  gap: 4px;
  background: linear-gradient(to top, #050505 0, #050505 60%, rgba(5, 5, 5, 0.2) 100%);
}

#status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: #b0b0b0;
}

#status-right span + span {
  margin-left: 10px;
}

#dialogue-box {
  flex: 1;
  border-radius: 12px;
  padding: 6px 8px;
  background: #141414;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
}

#dialogue-speaker {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #ffdf9b;
}

#dialogue-text {
  font-size: 13px;
  line-height: 1.35;
  color: #f0f0f0;
  overflow: auto;
}

#action-input-container {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

#action-input {
  flex: 1;
  background: #222;
  border: 1px solid #444;
  border-radius: 8px;
  color: #fff;
  padding: 8px 12px;
  font-size: 12px;
}

#btn-submit-action {
  background: #444;
  border: none;
  border-radius: 8px;
  color: #fff;
  padding: 0 12px;
  cursor: pointer;
  font-size: 12px;
}

#choices {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.choice-btn {
  border: none;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  background: #262626;
  color: #f3f3f3;
  cursor: pointer;
}

.choice-btn.primary {
  background: #e0e0e0;
  color: #151515;
}

.choice-btn.danger {
  background: #601b1b;
  color: #fbe4e4;
}

/* Special Red Fog Void Effect */
.void-bg {
  background: #050000;
  position: relative;
  overflow: hidden;
}

.red-fog {
  position: absolute;
  width: 200%;
  height: 200%;
  top: -50%;
  left: -50%;
  background: radial-gradient(circle, rgba(255, 0, 0, 0.15) 0%, transparent 70%);
  filter: blur(40px);
  animation: fog-drift 10s infinite alternate ease-in-out;
  pointer-events: none;
  z-index: 1;
}

.red-fog-2 {
  background: radial-gradient(circle, rgba(150, 0, 0, 0.1) 0%, transparent 60%);
  animation-duration: 15s;
  animation-delay: -5s;
}

@keyframes fog-drift {
  from { transform: translate(-5%, -5%) scale(1); }
  to { transform: translate(5%, 5%) scale(1.1); }
}

/* Sleep overlay */

.sleep-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.sleep-overlay.hidden {
  display: none;
}

.sleep-text {
  color: #f5f5f5;
  font-size: 20px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

/* MINIGAMES */

#minigame-screen {
  align-items: center;
  justify-content: center;
  background: #050505;
}

/* PC / Desktop mode layout */
@media (min-width: 900px) {
  .screen {
    max-width: 1100px;
  }

  .pc-only {
    display: inline-flex;
  }

  #game-screen {
    flex-direction: row;
  }

  #game-top {
    flex: 1 1 50%;
    padding: 8px 4px 8px 8px;
    border-right: 1px solid #222;
  }

  #game-bottom {
    flex: 1 1 50%;
    padding: 8px 8px 8px 4px;
  }

  #dialogue-box {
    flex: 1;
  }
}

.minigame-root {
  width: 100%;
  max-width: 800px;
  height: 100%;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.minigame-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}

.minigame-container {
  flex: 1;
  border-radius: 12px;
  background: #101010;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.minigame-container canvas {
  max-width: 100%;
  max-height: 100%;
}

/* ENDING */

#ending-screen {
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #202020 0, #050505 55%);
}

.ending-panel {
  width: 90%;
  max-width: 360px;
  background: #111111;
  border-radius: 18px;
  padding: 18px 16px 16px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.8);
}

.ending-panel h1 {
  font-size: 20px;
  margin: 0 0 8px;
}

.ending-panel p {
  font-size: 14px;
  margin: 0 0 14px;
  color: #e1e1e1;
}

/* Menu disclaimer */
.disclaimer {
  margin-top: 12px;
  max-width: 420px;
  text-align: center;
  font-size: 12px;
  color: #d8d8d8;
  background: rgba(255,255,255,0.03);
  padding: 8px 10px;
  border-radius: 10px;
  line-height: 1.2;
}
.disclaimer strong {
  color: #f6e2a3;
  font-weight: 700;
}