/* =========================================================================
   Twin Puzzle - global stylesheet
   Sections: base | screens | buttons | landing | leaderboard | game
             terminal (CRT) | reveal | confetti | responsive
   ========================================================================= */

/* ----------------------------- base ----------------------------------- */
:root {
  --pink: #ff6b9d;
  --blue: #5bc0ff;
  --yellow: #ffd93d;
  --green-crt: #33ff66;
  --ink: #232336;
  --paper: #fff;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  --radius: 18px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  color: var(--ink);
  background: linear-gradient(135deg, #ffe0ec 0%, #e0f2ff 100%);
  overflow-x: hidden;
}

/* --------------------------- screens ---------------------------------- */
.screen {
  display: none;
  min-height: 100vh;
  width: 100%;
}
.screen.is-active {
  display: block;
}

/* --------------------------- buttons ---------------------------------- */
.btn {
  cursor: pointer;
  border: none;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.3px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.btn:not(:disabled):hover {
  transform: translateY(-2px);
}
.btn:not(:disabled):active {
  transform: translateY(0);
}

.btn-play {
  font-size: 1.5rem;
  padding: 0.9rem 2.6rem;
  color: #fff;
  background: linear-gradient(135deg, var(--pink), #ff8e53);
  box-shadow: 0 10px 24px rgba(255, 107, 157, 0.45);
}

.btn-small {
  font-size: 0.8rem;
  padding: 0.4rem 0.8rem;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border-radius: 8px;
}

/* =========================== LANDING ================================== */
.landing-wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 4vh 5vw;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 2.5rem;
  align-items: center;
  min-height: 100vh;
}

.landing-card {
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 3rem 2.5rem;
  text-align: center;
  position: relative;
}
.landing-badge {
  font-size: 2rem;
  letter-spacing: 0.5rem;
  margin-bottom: 0.5rem;
}
.landing-title {
  font-size: 2.8rem;
  margin: 0 0 1rem;
  background: linear-gradient(135deg, var(--pink), var(--blue));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.landing-text {
  font-size: 1.2rem;
  line-height: 1.6;
  color: #444;
  margin-bottom: 2rem;
}
.landing-sub {
  margin-top: 1.4rem;
  color: #888;
  font-size: 0.95rem;
  font-style: italic;
}

/* ========================= LEADERBOARD =============================== */
.leaderboard-card {
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.8rem 1.6rem;
}
.leaderboard-title {
  margin: 0 0 1rem;
  font-size: 1.4rem;
  text-align: center;
}
.leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: rank;
}
.leaderboard-row {
  display: grid;
  grid-template-columns: 2.5rem 1fr auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.4rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.leaderboard-row:last-child {
  border-bottom: none;
}
.lb-rank {
  font-size: 1.2rem;
  text-align: center;
}
.lb-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-time {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--yellow);
}
.leaderboard-empty {
  list-style: none;
  text-align: center;
  color: #aaa;
  padding: 1rem 0;
}

/* ============================== GAME ================================== */
#screen-game {
  background: #0d0d12;
  display: none;
}
#screen-game.is-active {
  display: flex;
  flex-direction: column;
}

.game-hud {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}
.game-room-label {
  font-weight: 700;
  font-size: 1.1rem;
}
.game-timer {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--yellow);
}

.game-viewport {
  position: relative;
  margin: auto;
  max-width: 100%;
  /* Center the photo and leave room for the HUD. */
  display: inline-block;
  line-height: 0;
}

.game-image {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 52px);
  width: auto;
  height: auto;
  margin: 0 auto;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.game-image.loaded {
  opacity: 1;
}

/* The hotspot layer sits exactly over the rendered image. */
.hotspot-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hotspot {
  position: absolute;
  pointer-events: auto;
  background: transparent;
  border: 2px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
  transition: background 0.15s ease;
}
.hotspot:hover {
  background: rgba(91, 192, 255, 0.25);
}
.hotspot-label {
  opacity: 0;
  font-size: 1rem;
  transition: opacity 0.15s ease;
}
.hotspot:hover .hotspot-label {
  opacity: 1;
}

/* DEV mode: visible borders so coordinates can be tuned to the photos. */
.hotspot-layer.borders-on .hotspot {
  border-color: rgba(255, 215, 61, 0.95);
  background: rgba(255, 215, 61, 0.12);
}
.hotspot-layer.borders-on .hotspot .hotspot-label {
  opacity: 1;
}
.hotspot-layer.borders-on .hotspot-computer {
  border-color: #00e5ff;
}

/* The TWIN_SECRET.exe Windows-style shortcut in room S. */
.hotspot-computer {
  flex-direction: column;
  gap: 4px;
  background: rgba(0, 0, 0, 0.15);
}
.hotspot-computer:hover {
  background: rgba(0, 120, 215, 0.35);
}
.exe-icon {
  font-size: clamp(1.5rem, 4vw, 3rem);
  filter: drop-shadow(1px 2px 2px rgba(0, 0, 0, 0.6));
}
.exe-label {
  font-size: clamp(0.6rem, 1.4vw, 0.9rem);
  background: rgba(0, 60, 140, 0.85);
  color: #fff;
  padding: 1px 6px;
  border-radius: 3px;
  white-space: nowrap;
  /* The classic dotted "selected icon" outline. */
  outline: 1px dotted rgba(255, 255, 255, 0.8);
  outline-offset: 2px;
}

/* ===================== HOTSPOT EDITOR (dev tool) ====================== */
/* HUD edit button active state. */
#toggle-editor.active {
  background: #c2410c;
}

/* While editing: boxes are grab-able, show a resize handle, no navigation. */
.hotspot-layer.edit-mode .hotspot {
  cursor: grab;
  border-color: rgba(255, 215, 61, 0.95);
  background: rgba(255, 215, 61, 0.12);
}
.hotspot-layer.edit-mode .hotspot:hover {
  background: rgba(255, 215, 61, 0.25);
}
.hotspot-layer.edit-mode .hotspot.selected {
  border-color: #00e5ff;
  background: rgba(0, 229, 255, 0.22);
  box-shadow: 0 0 0 2px rgba(0, 229, 255, 0.6);
  z-index: 5;
}
.hotspot-layer.edit-mode .hotspot .hotspot-label {
  opacity: 1;
}

/* Resize handle (bottom-right corner) — only visible in edit mode. */
.resize-handle {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: #00e5ff;
  border: 2px solid #003b46;
  cursor: nwse-resize;
  display: none;
  touch-action: none;
}
.hotspot-layer.edit-mode .resize-handle {
  display: block;
}

/* The editor side panel. */
.editor-panel {
  position: fixed;
  top: 52px;
  right: 0;
  width: min(330px, 92vw);
  max-height: calc(100vh - 52px);
  overflow-y: auto;
  z-index: 50;
  background: #1b1f2a;
  color: #e8ecf3;
  border-left: 2px solid #00e5ff;
  box-shadow: -8px 0 28px rgba(0, 0, 0, 0.45);
  padding: 1rem 1rem 2rem;
  font-size: 0.9rem;
}
.editor-title {
  margin: 0 0 0.4rem;
  font-size: 1.1rem;
}
.editor-hint {
  margin: 0 0 1rem;
  color: #9aa4b6;
  font-size: 0.8rem;
  line-height: 1.4;
}
.editor-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.editor-row > span {
  flex: 0 0 70px;
  color: #9aa4b6;
}
.editor-row input,
.editor-row select {
  flex: 1;
  padding: 0.35rem 0.5rem;
  background: #0f131b;
  color: #e8ecf3;
  border: 1px solid #39404f;
  border-radius: 6px;
  font: inherit;
}
.editor-row input:focus,
.editor-row select:focus {
  outline: none;
  border-color: #00e5ff;
}
.editor-fields {
  border-top: 1px solid #2a3140;
  border-bottom: 1px solid #2a3140;
  padding: 0.7rem 0;
  margin-bottom: 0.7rem;
  transition: opacity 0.15s ease;
}
.editor-selected {
  font-size: 0.78rem;
  color: #aeb7c7;
  min-height: 2.2rem;
  word-break: break-word;
}
.editor-selected code {
  color: #7df3a1;
  font-size: 0.74rem;
}
.editor-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}
.editor-actions .btn-small {
  flex: 1;
  background: #2a3140;
}
.editor-actions .btn-small:hover {
  background: #39404f;
}
.editor-output {
  width: 100%;
  height: 150px;
  margin-top: 0.4rem;
  background: #0f131b;
  color: #7df3a1;
  border: 1px solid #39404f;
  border-radius: 6px;
  padding: 0.5rem;
  font-family: "Courier New", monospace;
  font-size: 0.74rem;
  resize: vertical;
}

/* Give the photo room so the fixed panel doesn't cover it on wide screens. */
#screen-game.editing .game-viewport {
  margin-right: min(330px, 92vw);
}
@media (max-width: 720px) {
  #screen-game.editing .game-viewport {
    margin-right: 0;
  }
}

/* =========================== TERMINAL (CRT) =========================== */
.crt {
  background: #020a02;
  color: var(--green-crt);
  font-family: "Courier New", Courier, monospace;
  position: relative;
  overflow: hidden;
}
#screen-terminal.is-active {
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.crt-inner {
  width: min(820px, 94vw);
  padding: 4vh 2vw 8vh;
  position: relative;
  z-index: 2;
  text-shadow: 0 0 6px rgba(51, 255, 102, 0.6);
}
/* Scanline + flicker overlay. */
.crt-scanlines {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.25) 3px,
    rgba(0, 0, 0, 0.25) 4px
  );
  animation: flicker 3s infinite;
}
@keyframes flicker {
  0%, 96%, 100% { opacity: 0.85; }
  97% { opacity: 0.7; }
  98% { opacity: 1; }
}

/* "Exit / back to the house" control at the top of the terminal. */
.crt-back-btn {
  display: inline-block;
  margin-bottom: 1rem;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.4rem 0.9rem;
  color: var(--green-crt);
  background: rgba(51, 255, 102, 0.08);
  border: 1px solid var(--green-crt);
  border-radius: 6px;
  cursor: pointer;
  text-shadow: inherit;
  transition: background 0.15s ease;
}
.crt-back-btn:hover {
  background: rgba(51, 255, 102, 0.25);
}

.crt-banner {
  font-size: clamp(0.35rem, 1.4vw, 0.7rem);
  line-height: 1.05;
  margin: 0 0 1rem;
  white-space: pre;
  overflow-x: auto;
}
.crt-line {
  margin: 0.2rem 0;
  font-size: 0.95rem;
}

.terminal-form {
  margin-top: 1.5rem;
}
.puzzle-rows {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.puzzle-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid rgba(51, 255, 102, 0.25);
  border-radius: 6px;
}
.puzzle-name {
  width: 72px;
  font-weight: 700;
}
.hint-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--green-crt);
  background: transparent;
  color: var(--green-crt);
  font-weight: 700;
  cursor: pointer;
  text-shadow: inherit;
}
.hint-btn:hover {
  background: rgba(51, 255, 102, 0.2);
}
.char-boxes {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}
.char-box {
  width: 1.7rem;
  height: 2.2rem;
  text-align: center;
  font-family: inherit;
  font-size: 1.1rem;
  text-transform: uppercase;
  color: var(--green-crt);
  background: rgba(0, 30, 0, 0.6);
  border: 1px solid var(--green-crt);
  border-radius: 4px;
  caret-color: var(--green-crt);
}
.char-box:focus {
  outline: none;
  box-shadow: 0 0 8px rgba(51, 255, 102, 0.9);
  background: rgba(0, 60, 0, 0.8);
}
.hint-text {
  flex-basis: 100%;
  font-size: 0.85rem;
  color: #9dffb0;
  display: none;
  padding-left: 72px;
}
.hint-text.show {
  display: block;
}

.row-correct {
  border-color: #33ff66;
  box-shadow: 0 0 8px rgba(51, 255, 102, 0.5);
}
.row-wrong {
  border-color: #ff5b5b;
  box-shadow: 0 0 8px rgba(255, 91, 91, 0.5);
  animation: shake 0.3s;
}
/* A verified-correct row that is locked so it persists across navigation. */
.row-locked .char-box {
  cursor: default;
  opacity: 0.95;
  background: rgba(0, 60, 0, 0.6);
}
.row-locked .char-box:focus {
  box-shadow: none;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.terminal-message {
  min-height: 1.4rem;
  margin: 1rem 0;
  font-size: 0.95rem;
}
.terminal-message.msg-ok { color: #7dffa1; }
.terminal-message.msg-error { color: #ff6b6b; }

.btn-terminal {
  margin-top: 0.5rem;
  font-family: inherit;
  font-size: 1.1rem;
  padding: 0.7rem 1.6rem;
  border: 1px solid var(--green-crt);
  border-radius: 6px;
  background: rgba(51, 255, 102, 0.12);
  color: var(--green-crt);
  text-shadow: inherit;
}
.btn-terminal:not(:disabled):hover {
  background: rgba(51, 255, 102, 0.28);
}

/* ============================= REVEAL ================================ */
#screen-reveal {
  background: linear-gradient(135deg, #ffdde1 0%, #c7eaff 50%, #fff6c7 100%);
}
#screen-reveal.is-active {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4vh 5vw;
  position: relative;
}
.reveal-card {
  background: rgba(255, 255, 255, 0.92);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 3rem 2.5rem;
  text-align: center;
  max-width: 560px;
  width: 100%;
  position: relative;
  z-index: 5;
  animation: pop 0.5s ease;
}
@keyframes pop {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.reveal-headline {
  font-size: clamp(1.8rem, 5vw, 3rem);
  margin: 0 0 0.5rem;
}
.reveal-headline .boy { color: var(--blue); }
.reveal-headline .girl { color: var(--pink); }
.reveal-emoji {
  font-size: 2.4rem;
  margin: 0.4rem 0 1rem;
}
.reveal-time {
  font-size: 1.2rem;
  margin-bottom: 1.6rem;
}
.reveal-form {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  align-items: center;
}
.reveal-form.hidden { display: none; }
.reveal-label {
  font-weight: 600;
}
.reveal-input {
  width: 100%;
  max-width: 320px;
  padding: 0.7rem 1rem;
  font-size: 1.1rem;
  border: 2px solid #ddd;
  border-radius: 10px;
  text-align: center;
}
.reveal-input:focus {
  outline: none;
  border-color: var(--pink);
}
.btn-reveal {
  font-size: 1.1rem;
  padding: 0.7rem 1.8rem;
  color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--pink));
  box-shadow: 0 8px 20px rgba(91, 192, 255, 0.4);
}
.reveal-message {
  min-height: 1.4rem;
  margin-top: 1rem;
  font-weight: 600;
}
.reveal-message.msg-ok { color: #2e9e5b; }
.reveal-message.msg-error { color: #d23; }

/* ============================ CONFETTI =============================== */
.confetti-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
}
.confetti-piece {
  position: absolute;
  top: -10vh;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  opacity: 0.9;
  animation-name: confetti-fall;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}
@keyframes confetti-fall {
  0% { transform: translateY(-10vh) rotate(0deg); }
  100% { transform: translateY(110vh) rotate(720deg); }
}

/* =========================== RESPONSIVE ============================== */
@media (max-width: 820px) {
  .landing-wrap {
    grid-template-columns: 1fr;
    padding: 6vh 6vw;
  }
  .landing-card { padding: 2rem 1.4rem; }
  .puzzle-name { width: 64px; }
  .hint-text { padding-left: 0; }
  .char-box { width: 1.5rem; height: 2rem; font-size: 1rem; }
}
