:root {
  --bg-page: #0d0f13;
  --text-main: #e7eaf0;
  --text-dim: #8c95a6;
  --panel-bg: #171a22;
  --panel-border: #2a303e;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at 50% 0%, #241921 0%, #12141a 46%, var(--bg-page) 100%);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  touch-action: manipulation;
  overflow-x: hidden;
}

.app {
  max-width: 420px;
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 12px calc(108px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* === KHUNG 3D VỎ ẢNH THẬT === */
.device-stage {
  position: relative;
  width: min(378px, 98vw);
  display: flex;
  justify-content: center;
  perspective: 1200px;
}

.egg-flipper {
  position: relative;
  width: 100%;
  aspect-ratio: 540 / 602;
  transform-style: preserve-3d;
  transition: transform 0.72s cubic-bezier(0.22, 0.85, 0.32, 1);
  filter: drop-shadow(0 20px 30px rgba(0, 0, 0, 0.65));
}

.egg-flipper.flipped {
  transform: rotateY(180deg);
}

.egg-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.egg-back {
  transform: rotateY(180deg);
}

.shell-photo {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  pointer-events: none;
}

/* === Ô MÀN HÌNH IPS LỌT KHÍT KHUNG ĐỎ RƯỢU === */
.lcd-mount {
  position: absolute;
  left: 29.67%;
  top: 36.01%;
  width: 35.29%;
  height: 32.68%;
  border-radius: 7px;
  overflow: hidden;
  background: #141824;
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.65),
    0 0 0 1px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  z-index: 3;
}

/* Phản chiếu kính IPS nhẹ */
.lcd-mount::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.14) 0%, rgba(255, 255, 255, 0.02) 34%, transparent 56%);
  z-index: 6;
}

.icon-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: center;
  justify-items: center;
  height: 14.5%;
  background: linear-gradient(180deg, #fff5f8 0%, #ffe6ef 100%);
  border-bottom: 1px solid #e7bed0;
  padding: 0 2px;
  z-index: 2;
  flex-shrink: 0;
}

.icon-row.bottom {
  background: linear-gradient(180deg, #eef9ff 0%, #daf0ff 100%);
  border-bottom: none;
  border-top: 1px solid #b8d7ee;
}

.lcd-mount.night-bar .icon-row {
  background: linear-gradient(180deg, #242942 0%, #191d30 100%);
  border-color: #3a4266;
}

.lcd-icon {
  width: 82%;
  height: 82%;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.34;
  transition: transform 0.1s ease, opacity 0.1s ease, background 0.1s ease;
}

.lcd-icon svg {
  width: 80%;
  height: 80%;
  max-width: 14px;
  max-height: 14px;
  shape-rendering: crispEdges;
}

.lcd-icon.active {
  opacity: 1;
  background: rgba(255, 208, 92, 0.52);
  box-shadow: inset 0 0 0 1px #ff5d8f;
  transform: scale(1.1);
}

.lcd-icon.blink {
  animation: attnPulse 0.55s ease-in-out infinite;
}

@keyframes attnPulse {
  0%, 100% {
    opacity: 1;
    background: rgba(255, 64, 96, 0.36);
    box-shadow: inset 0 0 0 1px #ff3355;
    transform: scale(1.12);
  }
  50% {
    opacity: 0.25;
    background: transparent;
    box-shadow: none;
    transform: scale(0.95);
  }
}

.lcd-canvas-wrap {
  flex: 1;
  width: 100%;
  min-height: 0;
  position: relative;
  background: #1a2030;
}

#lcdCanvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  object-fit: cover;
}

/* === 3 VÙNG CHẠM NÚT A / B / C TRÊN ẢNH VỎ THẬT === */
.shell-btn {
  position: absolute;
  width: 11.5%;
  aspect-ratio: 1 / 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  z-index: 5;
  outline: none;
  transition: background 0.08s ease, box-shadow 0.08s ease, transform 0.06s ease;
}

.shell-btn.btn-a { left: 35.93%; top: 80.50%; }
.shell-btn.btn-b { left: 49.36%; top: 83.26%; }
.shell-btn.btn-c { left: 62.40%; top: 80.50%; }

.shell-btn:active,
.shell-btn.pressed {
  background: rgba(0, 0, 0, 0.24);
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.5), 0 0 0 3px rgba(255, 255, 255, 0.22);
  transform: translate(-50%, -46%) scale(0.94);
}

/* === THANH CÔNG CỤ & DEBUG === */
.toolbar {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.ui-btn {
  background: var(--panel-bg);
  color: var(--text-main);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 9px 6px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: background 0.14s ease, border-color 0.14s ease;
}

.ui-btn:active { transform: scale(0.97); }
.ui-btn.on { border-color: #6ea8fe; color: #9ec5fe; background: #1a2436; }
.ui-btn.crimson { border-color: #9e273a; color: #f7bac4; background: #26141a; }
.ui-btn.warn { border-color: #d97706; color: #fbbf24; }

.debug-panel {
  width: 100%;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.5;
}

.debug-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--panel-border);
  color: var(--text-dim);
  font-weight: 700;
}

.debug-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px 10px;
}

.debug-item span { color: var(--text-dim); }
.debug-item strong.alert { color: #f87171; }
.debug-item strong.ok { color: #86efac; }

.debug-actions {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--panel-border);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.mini-btn {
  background: #242934;
  color: #d3dae6;
  border: 1px solid #384152;
  border-radius: 7px;
  padding: 5px 8px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
}

.mini-btn:active { transform: scale(0.96); }
.mini-btn.danger { border-color: #7f1d1d; color: #fca5a5; }

/* === MODALS === */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 60;
}

.modal-backdrop.open { display: flex; }

.modal-card {
  width: min(370px, 100%);
  max-height: 88dvh;
  overflow-y: auto;
  background: #171a22;
  border: 1px solid #303847;
  border-radius: 14px;
  padding: 14px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.modal-head h3 { margin: 0; font-size: 14px; }

.modal-desc {
  margin: 0 0 10px;
  font-size: 11.5px;
  color: var(--text-dim);
  line-height: 1.45;
}

.modal-desc code {
  background: #242a36;
  padding: 1px 4px;
  border-radius: 4px;
  color: #f3b2ba;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 9px;
}

.form-row label,
.grid-3 label {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 600;
}

.ui-input {
  width: 100%;
  background: #0f1218;
  color: var(--text-main);
  border: 1px solid #303847;
  border-radius: 8px;
  padding: 7px 8px;
  font-size: 12px;
  font-family: inherit;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 9px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--text-main);
  margin-bottom: 10px;
  cursor: pointer;
}

.preview-box {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #0f1218;
  border: 1px solid #282f3d;
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 10px;
}

#packPreviewCanvas {
  width: 72px;
  height: 72px;
  border-radius: 8px;
  background: repeating-conic-gradient(#262c38 0% 25%, #1b2029 0% 50%) 50% / 12px 12px;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.preview-meta {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.45;
}

.archive-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.archive-slot {
  background: #101319;
  border: 1px solid #282f3c;
  border-radius: 10px;
  padding: 9px 6px;
  text-align: center;
  font-size: 10.5px;
  color: var(--text-dim);
}

.archive-slot.unlocked {
  border-color: #7c3547;
  background: #1b161c;
  color: #eef1f6;
}

.archive-preview {
  width: 58px;
  height: 54px;
  margin: 0 auto 6px;
  border-radius: 9px;
  background: #1d222c;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #4b5568;
  font-weight: 800;
  overflow: hidden;
}

.archive-slot.unlocked .archive-preview {
  background: linear-gradient(180deg, #fff5e8 0%, #ffe4ec 100%);
  border: 1.5px solid rgba(255, 180, 200, 0.65);
}

.archive-preview canvas {
  image-rendering: pixelated;
  width: 52px;
  height: 52px;
}

.save-textarea {
  width: 100%;
  height: 96px;
  background: #0f1218;
  color: #c8d3e6;
  border: 1px solid #303847;
  border-radius: 8px;
  padding: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  resize: none;
  user-select: text;
  -webkit-user-select: text;
}

.save-row {
  margin-top: 8px;
  display: flex;
  gap: 8px;
}

.save-row .ui-btn { flex: 1; }

.save-msg {
  margin-top: 6px;
  font-size: 11px;
  color: #9ec5fe;
  min-height: 15px;
}

.hint-line {
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.5;
}
