* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0b0e0a;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
#game {
  position: fixed; inset: 0;
  display: block;
  cursor: crosshair;
  touch-action: none;
}
#hud {
  position: fixed; top: 12px; left: 12px;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px; line-height: 1.5;
  user-select: none; pointer-events: none;
}
#hud .hint { opacity: 0.7; font-size: 12px; }
#commit {
  position: fixed; top: 12px; left: 12px;
  z-index: 5;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 4px 10px;
  font-family: ui-monospace, monospace;
  font-size: 12px; line-height: 1.5;
  user-select: none;
}
#commit.hidden { display: none; }
#commit a { color: #fff; text-decoration: none; pointer-events: auto; }
#commit a:hover { text-decoration: underline; }
#err {
  position: fixed; left: 12px; bottom: 12px; right: 12px;
  color: #ffd7d7;
  background: rgba(120, 10, 10, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px; line-height: 1.5;
  z-index: 20;
  white-space: pre-wrap; word-break: break-word;
}
#err.hidden { display: none; }
#loader {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px;
  background: #0b0e0a; color: #d8e6c3;
  font-size: 16px;
  transition: opacity 0.4s ease;
  z-index: 10;
}
#loader.hidden { opacity: 0; pointer-events: none; }
#loader-track {
  width: 220px; height: 8px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px; overflow: hidden;
}
#loader-bar {
  height: 100%; width: 0%;
  background: #f2c531;
  transition: width 0.2s ease;
}
#loader .error { max-width: 420px; text-align: center; line-height: 1.6; padding: 0 20px; }
#loader code { background: rgba(255,255,255,0.1); padding: 1px 6px; border-radius: 4px; }
#popup {
  position: fixed; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  z-index: 30;
  pointer-events: none;
  animation: popup-in 0.25s ease-out;
}
#popup.hidden { display: none; }
@keyframes popup-in {
  from { opacity: 0; transform: translate(-50%, -47%) scale(0.94); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
#popup-card {
  position: relative;
  pointer-events: auto;
  font-family: Palatino, "Palatino Linotype", "Book Antiqua", Georgia, "Iowan Old Style", "Source Serif Pro", serif;
  color: #3a2410;
  background:
    radial-gradient(ellipse at 50% 20%, #f7e9c6 0%, #eed9a8 45%, #dfba78 100%);
  border: 3px double #6b4a1f;
  outline: 2px solid #3a2410;
  outline-offset: 5px;
  border-radius: 4px;
  padding: 22px 30px 18px;
  width: min(560px, 88vw);
  max-height: 78vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 44px rgba(0,0,0,0.75), inset 0 0 46px rgba(107,74,31,0.35);
}
#popup-title {
  font-variant: small-caps;
  letter-spacing: 4px;
  font-size: 14px;
  color: #6b4a1f;
  border-bottom: 1px solid #6b4a1f;
  padding-bottom: 6px;
  margin-bottom: 10px;
  padding-right: 30px; /* keep clear of close button */
}
#popup-text {
  font-size: 16px;
  font-weight: normal;
  line-height: 1.6;
  text-align: left;
  text-shadow: 0 1px 0 rgba(255,248,230,0.6);
  overflow-y: auto;
  padding-right: 8px;
  flex: 1 1 auto;
}
/* Let real content breathe inside popup-text */
#popup-text p { margin: 0 0 10px; }
#popup-text p:last-child { margin-bottom: 0; }
#popup-text ul, #popup-text ol {
  margin: 0 0 10px 22px;
}
#popup-text li { margin-bottom: 4px; }
#popup-text h1 {
  font-variant: small-caps;
  letter-spacing: 1px;
  color: #5a3a15;
  margin: 14px 0 8px;
  font-size: 26px;
}
#popup-text h2 {
  font-variant: small-caps;
  letter-spacing: 1px;
  color: #5a3a15;
  margin: 12px 0 6px;
  font-size: 21px;
}
#popup-text h3 {
  font-variant: small-caps;
  letter-spacing: 1px;
  color: #5a3a15;
  margin: 10px 0 6px;
  font-size: 18px;
}
#popup-text h1:first-child,
#popup-text h2:first-child,
#popup-text h3:first-child { margin-top: 0; }
#popup-text code {
  background: rgba(107,74,31,0.15);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 0.9em;
}
#popup-text strong { color: #5a3a15; }

/* B3 projects list */
#popup-text .projects-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
#popup-text .project-item {
  margin: 0 0 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(107,74,31,0.35);
}
#popup-text .project-item:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}
#popup-text .project-title {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 2px;
}
#popup-text .project-title a { color: #5a3a15; }
#popup-text .project-desc {
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 6px;
}
#popup-text .project-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
#popup-text .project-tag {
  display: inline-block;
  font-size: 12px;
  line-height: 1.4;
  letter-spacing: 0.5px;
  color: #f3e3bd;
  background: linear-gradient(#6b4a1f, #4d3515);
  border: 1px solid #3a2410;
  border-radius: 999px;
  padding: 2px 10px;
  text-shadow: none;
  white-space: nowrap;
}

/* B9 blog list + reader */
#popup-text .blog-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
#popup-text .blog-item {
  margin: 0 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(107,74,31,0.35);
}
#popup-text .blog-item:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}
#popup-text .blog-item a { color: #5a3a15; font-weight: bold; }
#popup-text .blog-date {
  font-size: 13px;
  opacity: 0.75;
}
#popup-text .blog-back {
  display: inline-block;
  font-size: 14px;
  color: #5a3a15;
  margin-bottom: 6px;
}
#popup-text .blog-post-title { margin-bottom: 0; }
#popup-text .blog-post-date {
  font-size: 13px;
  font-style: italic;
  opacity: 0.75;
  margin-bottom: 10px;
}
#popup-text .blog-post-body { font-size: 15px; }
#popup-text .blog-post-body a { color: #5a3a15; }
#popup-text .blog-post-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 10px 0;
}
#popup-text .blog-post-body th,
#popup-text .blog-post-body td {
  border: 1px solid rgba(107,74,31,0.4);
  padding: 4px 6px;
  text-align: left;
}

/* B9 guestbooke stub (inert until real comments land) */
#popup-text .blog-guestbooke {
  margin-top: 16px;
  padding-top: 10px;
  border-top: 3px double #6b4a1f;
}
#popup-text .blog-guestbooke-note {
  font-size: 14px;
  font-style: italic;
}
#popup-text .blog-guestbooke-box {
  width: 100%;
  min-height: 64px;
  font-family: inherit;
  font-size: 14px;
  color: #3a2410;
  background: rgba(255,248,230,0.5);
  border: 1px solid rgba(107,74,31,0.5);
  border-radius: 4px;
  padding: 6px 8px;
  margin-bottom: 8px;
  resize: vertical;
}
#popup-text .blog-guestbooke-seal {
  font-family: inherit;
  font-variant: small-caps;
  letter-spacing: 2px;
  font-size: 14px;
  color: #f3e3bd;
  background: linear-gradient(#7a1f1f, #4d1414);
  border: 1px solid #2c0d0d;
  border-radius: 4px;
  padding: 6px 14px;
  cursor: not-allowed;
  opacity: 0.75;
}

/* Last.fm popup (house tile 174) */
#popup-text .lastfm-main {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(107,74,31,0.35);
}
#popup-text .lastfm-art {
  border: 2px solid #6b4a1f;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  image-rendering: auto;
}
#popup-text .lastfm-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
#popup-text .lastfm-heading {
  font-size: 16px;
  margin: 0 0 4px;
}
#popup-text .lastfm-artist {
  font-size: 20px;
  font-weight: bold;
  color: #5a3a15;
}
#popup-text .lastfm-title {
  font-size: 16px;
  font-style: italic;
}
#popup-text .lastfm-inner {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#popup-text .lastfm-inner-inner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
#popup-text .lastfm-art-small {
  width: 64px;
  height: 64px;
  border: 2px solid #6b4a1f;
  border-radius: 4px;
  flex: none;
}
#popup-text .lastfm-inner-inner .lastfm-heading { font-size: 13px; }
#popup-text .lastfm-inner-inner .lastfm-artist { font-size: 16px; }
#popup-text .lastfm-inner-inner .lastfm-title { font-size: 14px; }

/* Parchment-toned scrollbar */
#popup-text::-webkit-scrollbar { width: 8px; }
#popup-text::-webkit-scrollbar-track { background: transparent; }
#popup-text::-webkit-scrollbar-thumb {
  background: rgba(107,74,31,0.4);
  border-radius: 4px;
}

#popup-close {
  position: absolute;
  top: -14px; right: -14px;
  pointer-events: auto;
  cursor: pointer;
  font-family: inherit;
  font-variant: small-caps;
  letter-spacing: 2px;
  font-size: 14px;
  color: #f3e3bd;
  background: linear-gradient(#7a1f1f, #4d1414);
  border: 1px solid #2c0d0d;
  outline: 1px solid #c9a45c;
  outline-offset: -4px;
  border-radius: 50%;
  width: 32px; height: 32px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}
#leave-house {
  position: fixed;
  left: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 40;
  min-height: 44px;
  padding: 10px 16px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #f3e3bd;
  background: linear-gradient(#7a1f1f, #4d1414);
  border: 1px solid #2c0d0d;
  outline: 1px solid #c9a45c;
  outline-offset: -4px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#leave-house.hidden { display: none; }
#leave-house:active { transform: scale(0.97); }
#popup-card {
  overflow-wrap: break-word;
  word-break: break-word;
}
#popup-text {
  -webkit-text-size-adjust: 100%;
  overflow-wrap: break-word;
}
#popup-text strong,
#popup-text .blog-post-body strong {
  overflow-wrap: anywhere;
}
@media (max-width: 480px) {
  #popup-card {
    font-family: Georgia, "Iowan Old Style", "Source Serif Pro", serif;
    padding: 18px 18px 14px;
    width: min(560px, calc(100vw - 24px));
    max-height: 82dvh;
  }
  #popup-title {
    letter-spacing: 2px;
    font-size: 13px;
  }
  #popup-text { font-size: 15px; line-height: 1.55; }
  #popup-text h1 { font-size: 22px; }
  #popup-text h2 { font-size: 19px; }
  #popup-text h3 { font-size: 17px; }
  #popup-close {
    top: -12px; right: -6px;
    width: 44px; height: 44px;
    font-size: 16px;
  }
}
