::-webkit-scrollbar {
  width: 0.625rem;
  height: 0.625rem;
}
::-webkit-scrollbar-thumb {
  background: #111;
  border-radius: 0.3125rem;
  box-shadow: inset 0.125rem 0.125rem 0.125rem rgba(255, 255, 255, 0.25),
    inset -0.125rem -0.125rem 0.125rem rgba(0, 0, 0, 0.25);
  cursor: default;
}
::-webkit-scrollbar-track {
  background: #333;
}
::selection {
  background: #fff;
  color: #333;
}
html,
body {
  height: 100vh;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
}
body {
  display: grid;
  grid-template-rows: calc(100dvh - 4rem) 4rem;
  font-family: system-ui, sans-serif;
}

/* Navigation */
.site-header {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: .45rem .8rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  text-decoration: none;
  font-family: 'Arial Black', sans-serif;
  font-size: .85rem;
  letter-spacing: .06em;
}
.site-header .brand-a {
  color: #7DF9FF;
}
.site-header .brand-b {
  color: #FF00CC;
}
.back-link {
  position: fixed;
  top: 1rem;
  left: 12.6rem;
  z-index: 20;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  text-decoration: none;
  font-size: 0.9rem;
  transition: background 200ms ease-in-out;
}
.back-link:hover {
  background: rgba(0, 0, 0, 0.85);
}

/* Memo Popup (auto on page load) */
.memo-popup {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.85);
  opacity: 0;
  pointer-events: none;
  transition: opacity 300ms ease;
}
.memo-popup.is-visible {
  opacity: 1;
  pointer-events: auto;
}
.memo-popup-card {
  width: min(88vw, 400px);
  border-radius: 20px;
  overflow: hidden;
  background: #1a1a2e;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  transform: translateY(25px) scale(0.94);
  transition: transform 300ms ease;
  border: 2px solid #FF1493;
}
.memo-popup.is-visible .memo-popup-card {
  transform: translateY(0) scale(1);
}
.memo-popup-card img {
  width: 100%;
  display: block;
  max-height: 70vh;
  object-fit: contain;
  background: #0a0a1a;
}
.memo-popup-card button {
  width: 100%;
  border: 0;
  border-top: 1px solid #FF1493;
  background: #16213e;
  color: #fff;
  font-size: 1rem;
  min-height: 48px;
  cursor: pointer;
  transition: background 0.2s ease;
}
.memo-popup-card button:hover {
  background: #FF1493;
  color: white;
}

/* Message Overlay (3-second message) */
.message-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.5s ease, visibility 0.5s ease;
  pointer-events: none;
}
.message-overlay.show {
  opacity: 1;
  visibility: visible;
  pointer-events: none;
}
.message-box {
  background: linear-gradient(135deg, #FF1493, #FF69B4);
  padding: 30px 50px;
  border-radius: 20px;
  text-align: center;
  color: white;
  font-family: 'Arial Black', sans-serif;
  font-size: 1.8rem;
  box-shadow: 0 0 50px rgba(255, 20, 147, 0.5);
  animation: pulse 0.5s ease;
  white-space: nowrap;
}
@keyframes pulse {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
@media (max-width: 600px) {
  .message-box {
    font-size: 1.2rem;
    padding: 20px 30px;
    white-space: normal;
    text-align: center;
  }
}

/* Memory Wall Popup (after message) */
.memory-wall-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.92);
  z-index: 2000;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}
.memory-wall-popup.show {
  opacity: 1;
  visibility: visible;
}
.memory-wall-container {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  padding: 20px;
  width: min(90vw, 500px);
  text-align: center;
  border: 1px solid rgba(255, 20, 147, 0.5);
}
.memory-wall-container h3 {
  color: white;
  font-family: 'Arial Black', sans-serif;
  margin-bottom: 15px;
  font-size: 1.5rem;
}
.memory-wall-popup .memory-cards {
  position: relative;
  height: 400px;
  border-radius: 12px;
  overflow: hidden;
}
.memory-wall-popup .memory-card {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transform: scale(0.95) translateY(12px);
  transition: opacity 700ms ease, transform 700ms ease;
  cursor: pointer;
}
.memory-wall-popup .memory-card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 12px;
}
.memory-wall-popup .memory-card.is-active {
  opacity: 1;
  transform: scale(1) translateY(0);
  z-index: 1;
}
.close-memory-btn {
  margin-top: 20px;
  padding: 10px 25px;
  background: #FF1493;
  border: none;
  border-radius: 30px;
  color: white;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.2s ease;
}
.close-memory-btn:hover {
  transform: scale(1.05);
  background: #FF69B4;
}

/* Image Full View Modal */
.image-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.95);
  z-index: 3000;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.image-modal.show {
  display: flex;
}
.modal-content-wrapper {
  position: relative;
  background: transparent;
  max-width: 90vw;
  max-height: 90vh;
}
.modal-close {
  position: absolute;
  top: -40px;
  right: 0;
  color: white;
  font-size: 35px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 50%;
}
.modal-close:hover {
  color: #FF1493;
  transform: scale(1.1);
}
.modal-image {
  display: block;
  max-width: 80vw;
  max-height: 80vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
  background: white;
  padding: 5px;
}
.modal-caption {
  text-align: center;
  color: white;
  padding: 12px 20px;
  font-size: 1rem;
  margin-top: 15px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 30px;
}

/* Canvas and Editor */
canvas,
.editor,
#controls {
  grid-row: 1;
  grid-column: 1;
}
canvas {
  width: 100%;
  height: auto;
  object-fit: contain;
  background: black;
  touch-action: none;
}
.editor,
.overlay,
#error {
  background: repeating-linear-gradient(0deg, #000a, #1119, #000a .25rem);
  padding: 1em;
}
.editor {
  color: #fefefe;
  tab-size: 2;
  border: none;
  resize: none;
}
.editor:focus {
  outline: none;
}
#error {
  grid-row: 2;
  grid-column: 1;
  margin: 0;
  padding-block: 0;
  padding-top: .5em;
  color: firebrick;
  overflow: auto;
  text-wrap: pretty;
}
#indicator {
  visibility: hidden;
  position: absolute;
  top: calc(var(--top, 0px) - var(--scroll-top, 0px));
  width: 0;
  height: 0;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-left: 10px solid firebrick;
  transform: translateY(-25%);
}
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  margin: 0;
}
.editor,
.overlay {
  font-size: 1rem;
  line-height: 1.2;
  white-space: pre;
}
#controls {
  position: fixed;
  top: 1em;
  right: 2em;
}
.controls {
  position: relative;
  display: flex;
  gap: 1.5em;
  padding: .5em 1.25em;
  background: #1111;
  border-radius: 4px;
}
.controls::before,
.controls::after {
  content: '';
  position: absolute;
  z-index: -1;
  inset: 0;
  transform: scale(.95);
  border-radius: inherit;
  opacity: 0;
}
.controls::before {
  background: #aef;
  animation: pulse 2s infinite;
}
.controls::after {
  background: #fefefe66;
  transition: transform 200ms ease-in-out;
}
.controls:hover::before,
.controls:hover::after {
  opacity: 1;
}
.controls:hover::before {
  transform: scale(.98);
  filter: blur(2px);
}
.controls:hover::after {
  transform: scale(1.025, 1.1);
}
.controls:hover {
  background: #111f;
}
@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.0125);
  }
  100% {
    transform: scale(1);
  }
}
.hidden {
  display: none !important;
}
.opaque {
  opacity: 1 !important;
  background: #111 !important;
}
input {
  all: unset;
  opacity: .2;
  filter: saturate(0) invert(1);
  cursor: pointer;
  transition: opacity 200ms ease-in-out;
  padding: .25em .5em;
}
input:hover {
  opacity: 1;
}
.icon {
  text-align: center;
  line-height: 1;
}
#btnToggleView {
  width: 1.25em;
}
#btnToggleView::after {
  content: '👁';
}
#btnToggleView:checked::after {
  content: '✏️';
}
#btnToggleResolution::after {
  content: '1️⃣';
}
#btnToggleResolution:checked::after {
  content: '2️⃣';
}
#btnReset::after {
  content: '⏮️';
}

/* Footer */
.page-signature {
  position: fixed;
  left: 0;
  right: 0;
  bottom: .4rem;
  z-index: 20;
  text-align: center;
  color: #f2f2f2;
  pointer-events: none;
}
.page-signature p {
  margin: 0;
  font-size: .85rem;
  background: rgba(0, 0, 0, 0.45);
  display: inline-block;
  padding: .4rem .7rem;
  border-radius: 999px;
  pointer-events: auto;
}

/* Responsive */
@media (max-width: 600px) {
  .site-header {
    top: .75rem;
    left: .75rem;
    font-size: .8rem;
    padding: .4rem .7rem;
  }
  .back-link {
    top: 3rem;
    left: .75rem;
    font-size: .8rem;
    padding: .4rem .7rem;
  }
  .memory-wall-popup .memory-cards {
    height: 300px;
  }
  .memory-wall-container h3 {
    font-size: 1.2rem;
  }
  .modal-image {
    max-width: 95vw;
    max-height: 70vh;
  }
  .modal-close {
    top: -35px;
    font-size: 28px;
    width: 35px;
    height: 35px;
  }
  #controls {
    top: 5.9rem;
    right: .75rem;
  }
  input {
    min-width: 2rem;
    min-height: 2rem;
  }
  .page-signature p {
    font-size: .76rem;
  }
  .memo-popup-card {
    width: min(92vw, 340px);
  }
}
