* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --background: #141414;
  --foreground: #f7f7f7;
  --card: #222;
  --muted: #303030;
  --muted-foreground: #a3a3a3;
  --primary: #c93b2b;
  --primary-foreground: #fff;
  --accent: #facc15;
  --border: #444;
  --board: #181818;
  --mission: #4a1d1d;
  --mission-done: #15803d;
  --level-bg: #38bdf8;
  --level-fg: #0f172a;
  --ribbon-bg: #ec4899;
  --ribbon-fg: #fff;
  --crab: #dc2626;
  --fish: #f97316;
  --spark: #facc15;
  --font-pixel: "Press Start 2P", monospace;
  --font-body: "Space Mono", monospace;
}

html { scroll-padding-top: 100px; scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--background);
  color: var(--foreground);
  min-height: 100vh;
  transition: background-color .3s, color .3s;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

.btn {
  border: none;
  border-radius: 8px;
  padding: 12px 18px;
  font: 10px/1.6 var(--font-pixel);
  cursor: pointer;
  transition: filter .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover { filter: brightness(1.15); }
.btn-outline { background: none; border: 2px solid var(--foreground); color: var(--foreground); }
.btn-outline:hover { background: rgba(128, 128, 128, .15); }

.navbar {
  background: #171717;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 2000;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  width: 100%;
  min-height: 72px;
  padding: 14px 6%;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
}

.navbar-logo { color: #fff; text-decoration: none; font-size: 15px; font-weight: 800; letter-spacing: 1px; white-space: nowrap; }
.navbar-links { display: flex; align-items: center; gap: 28px; }
.nav-link { color: #fff; text-decoration: none; font-size: 13px; font-weight: 700; transition: color .2s; }
.nav-link:hover { color: #86efac; }

.burger-menu {
  display: none;
  background: none;
  border: 1px solid #444;
  border-radius: 8px;
  width: 44px;
  height: 44px;
  padding: 10px;
  cursor: pointer;
}
.burger-menu span {
  display: block;
  width: 22px;
  height: 3px;
  margin: 4px 0;
  background: #fff;
  border-radius: 3px;
  transition: transform .25s, opacity .25s;
}
.burger-menu.active span:first-child { transform: translateY(7px) rotate(45deg); }
.burger-menu.active span:nth-child(2) { opacity: 0; }
.burger-menu.active span:last-child { transform: translateY(-7px) rotate(-45deg); }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #292929;
  color: #fff;
  border: 1px solid #525252;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s;
}
.theme-toggle:hover { background: #404040; }

.page-container { max-width: 1400px; width: 100%; margin: 0 auto; padding: 32px 24px 64px; }
.page-header { margin-bottom: 32px; text-align: center; }
.title { font-family: var(--font-pixel); font-size: clamp(20px, 3.5vw, 42px); line-height: 1.5; overflow-wrap: anywhere; }
.subtitle { margin-top: 12px; color: var(--muted-foreground); font-size: 13px; line-height: 1.8; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  gap: 24px;
  max-width: 1050px;
  width: 100%;
  margin: 0 auto;
}

.board-col { display: flex; flex-direction: column; align-items: center; width: 100%; min-width: 0; }

.board-wrapper {
  position: relative;
  aspect-ratio: 1;
  width: 100%;
  max-width: 500px;
  background: var(--board);
  border: 4px solid var(--primary);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 10px 25px rgba(0, 0, 0, .4);
}

.board {
  display: grid;
  grid-template: repeat(18, minmax(0, 1fr)) / repeat(18, minmax(0, 1fr));
  width: 100%;
  height: 100%;
}

.cell { position: relative; display: flex; justify-content: center; align-items: center; min-width: 0; min-height: 0; }
.snake-part { width: 90%; height: 90%; border-radius: 3px; }
.snake-part.head, .preview-dot.head { filter: brightness(.75); }
.food-emoji { font-size: clamp(12px, 2.5vw, 22px); line-height: 1; user-select: none; }

.missions-col { display: flex; flex-direction: column; gap: 12px; width: 100%; }

.mission-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 58px;
  padding: 12px;
  background: var(--mission);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-body);
  text-align: left;
  cursor: default;
  transition: transform .15s, border-color .15s, background .2s;
}
.mission-btn.done { background: var(--mission-done); border-color: var(--accent); cursor: pointer; }
.mission-btn.done:hover { transform: translateY(-2px); }
.mission-emoji { font-size: 24px; line-height: 1; flex-shrink: 0; }
.mission-tag { margin-bottom: 5px; color: var(--accent); font: 8px/1.7 var(--font-pixel); }
.mission-title { font-size: 12px; font-weight: 700; line-height: 1.6; overflow-wrap: anywhere; }

.dpad { display: grid; grid-template: repeat(2, 48px) / repeat(3, 48px); gap: 6px; margin-top: 16px; }
.dpad-empty { visibility: hidden; }
.dpad-btn {
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--muted);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 20px;
  cursor: pointer;
}
.dpad-btn:active { background: var(--border); }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 14px;
  padding: 20px;
  background: rgba(20, 20, 20, .96);
  color: #fff;
  text-align: center;
}
.overlay-title { font-family: var(--font-pixel); font-size: clamp(12px, 2vw, 17px); line-height: 1.8; }
.overlay-hint { color: var(--muted-foreground); font-size: 11px; line-height: 1.8; }

.snake-preview { display: flex; gap: 3px; margin: 4px 0; }
.preview-dot { width: 17px; height: 17px; border-radius: 3px; }
.palette-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 300px; }

.swatch {
  width: 32px;
  height: 32px;
  border: 2px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  transition: transform .15s, border-color .15s;
}
.swatch:hover { transform: scale(1.1); }
.swatch.selected { transform: scale(1.15); border-color: var(--accent); }

.hex-row { display: flex; justify-content: center; align-items: center; gap: 8px; }
.hex-label { color: var(--muted-foreground); font: 9px var(--font-pixel); }
#hex-input {
  width: 100px;
  padding: 8px;
  background: var(--muted);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: 4px;
  outline: none;
  font-size: 12px;
  text-align: center;
}
#hex-input:focus { border-color: var(--accent); }

.section-details, .section-skills { margin: 64px 0 40px; scroll-margin-top: 100px; }
.section-title { font-family: var(--font-pixel); font-size: clamp(14px, 2vw, 20px); line-height: 1.8; text-align: center; }
.section-subtitle { margin-top: 8px; color: var(--muted-foreground); font-size: 12px; line-height: 1.8; text-align: center; }

.details-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; margin-top: 24px; }
.detail-card {
  min-width: 0;
  padding: 18px;
  background: rgba(74, 29, 29, .4);
  border: 2px solid var(--border);
  border-radius: 8px;
}
.detail-card.unlocked { background: var(--card); border-color: var(--accent); }
.detail-card-head { display: flex; align-items: center; gap: 12px; }
.detail-card-desc { margin-top: 12px; color: var(--muted-foreground); font-size: 12px; line-height: 1.8; white-space: pre-line; overflow-wrap: anywhere; }

.skills-scroll { width: 100%; margin-top: 32px; padding-bottom: 16px; overflow-x: auto; }
.skills-table { display: flex; flex-direction: column; gap: 12px; min-width: 640px; }
.skills-header-row, .skills-data-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.1fr) repeat(5, minmax(62px, 1fr));
  align-items: center;
  gap: 8px;
}

.level-tag-wrapper { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.level-tag {
  padding: 5px 6px;
  background: var(--level-bg);
  color: var(--level-fg);
  border-radius: 4px;
  font: 7px var(--font-pixel);
  text-transform: uppercase;
}
.plumb-line { width: 1px; height: 16px; background: var(--border); }

.skill-banner-col { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.ribbon-banner {
  padding: 7px 14px 7px 10px;
  background: var(--ribbon-bg);
  color: var(--ribbon-fg);
  font: 8px var(--font-pixel);
  white-space: nowrap;
  clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 0 100%);
}
.skill-level-text { padding-right: 12px; color: var(--muted-foreground); font-size: 9px; letter-spacing: 1px; text-transform: uppercase; }

.skill-cell { position: relative; display: flex; justify-content: center; align-items: center; height: 44px; }
.grid-line { position: absolute; top: 0; bottom: 0; left: 50%; width: 1px; background: var(--border); transform: translateX(-50%); }
.empty-cell-mark { width: 12px; height: 12px; border: 1px dashed var(--border); border-radius: 2px; }

.pixel-creature { position: relative; z-index: 1; display: block; width: 24px; height: 20px; }
.pixel-creature.crab { background: var(--crab); }
.pixel-creature.fish { background: var(--fish); }
.pixel-creature::after { content: ""; position: absolute; left: 0; bottom: 0; width: 100%; height: 4px; background: rgba(0, 0, 0, .35); }
.pixel-creature .eye-white { position: absolute; top: 3px; right: 4px; width: 7px; height: 7px; background: #fff; }
.pixel-creature .eye-pupil { position: absolute; top: 5px; right: 6px; width: 3px; height: 3px; background: #000; }
.pixel-creature .speckle1, .pixel-creature .speckle2 { position: absolute; bottom: 5px; width: 3px; height: 3px; background: #fff; }
.pixel-creature .speckle1 { left: 4px; }
.pixel-creature .speckle2 { left: 9px; }
.creature-spark { position: absolute; top: -8px; right: -8px; color: var(--spark); font-size: 10px; line-height: 1; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, .78);
}

.modal-card {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 380px;
  max-height: calc(100vh - 40px);
  padding: 24px;
  overflow-y: auto;
  background: var(--card);
  color: var(--foreground);
  border: 4px solid var(--accent);
  border-radius: 8px;
  text-align: center;
  box-shadow: 0 15px 35px rgba(0, 0, 0, .6);
}
.victory-card { border-color: #fff; }

.modal-emoji { font-size: 56px; line-height: 1.2; }
.modal-tag { margin-top: 16px; color: var(--accent); font: 11px/1.8 var(--font-pixel); }
.modal-heading { margin-top: 10px; font-size: 14px; font-weight: 700; line-height: 1.8; }
.modal-box { margin-top: 16px; padding: 16px; background: var(--muted); border-radius: 6px; text-align: left; }
.modal-box-tag { color: var(--muted-foreground); font: 8px/1.8 var(--font-pixel); }
.modal-box-title { margin-top: 6px; font-size: 13px; font-weight: 700; }
.modal-box-desc { margin-top: 8px; color: var(--muted-foreground); font-size: 12px; line-height: 1.8; white-space: pre-line; }
.victory-stats { margin-top: 12px; color: var(--muted-foreground); font-size: 12px; line-height: 1.8; }
.victory-actions { display: flex; flex-direction: column; justify-content: center; gap: 10px; margin: 20px 0 12px; }

#fireworks-canvas { position: fixed; inset: 0; z-index: 5; width: 100%; height: 100%; pointer-events: none; }

@keyframes popAnim {
  0% { transform: scale(.6); opacity: 0; }
  75% { transform: scale(1.05); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.pop-anim { animation: popAnim .3s ease-out; }

body.light-mode {
  --background: #f5f5f5;
  --foreground: #171717;
  --card: #fff;
  --muted: #eee;
  --muted-foreground: #666;
  --border: #d4d4d4;
  --board: #fff;
  --mission: #fce7e7;
  --mission-done: #bbf7d0;
}
body.light-mode .navbar { background: #fff; color: #171717; box-shadow: 0 4px 16px rgba(0, 0, 0, .08); }
body.light-mode .navbar-logo, body.light-mode .nav-link { color: #171717; }
body.light-mode .nav-link:hover { color: #15803d; }
body.light-mode .burger-menu { border-color: #d4d4d4; }
body.light-mode .burger-menu span { background: #171717; }
body.light-mode .theme-toggle { background: #eee; color: #171717; border-color: #d4d4d4; }
body.light-mode .theme-toggle:hover { background: #e0e0e0; }
body.light-mode .overlay { background: rgba(255, 255, 255, .97); color: #171717; }
body.light-mode .btn-outline { border-color: #171717; color: #171717; }
body.light-mode .detail-card { background: #fff1f1; }
body.light-mode .detail-card.unlocked { background: #fff; }

@media (min-width: 640px) {
  .details-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .victory-actions { flex-direction: row; }
}

@media (min-width: 1024px) {
  .game-layout { grid-template-columns: 220px minmax(0, 1fr) 220px; }
  .dpad { display: none; }
}

@media (max-width: 1023px) {
  .order-center { order: 1; }
  .order-left { order: 2; }
  .order-right { order: 3; }
  .missions-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mission-btn { min-width: 0; }
}

@media (max-width: 768px) {
  .navbar { min-height: 64px; padding: 10px 5%; }
  .burger-menu { display: block; flex-shrink: 0; }
  .navbar-links {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 16px 5% 20px;
    background: #171717;
    box-shadow: 0 8px 16px rgba(0, 0, 0, .15);
  }
  .navbar-links.open { display: flex; }
  .navbar-links .nav-link { padding: 16px 8px; border-bottom: 1px solid #404040; }
  .navbar-links .theme-toggle { align-self: flex-start; margin-top: 16px; }
  body.light-mode .navbar-links { background: #fff; }
  body.light-mode .navbar-links .nav-link { border-bottom-color: #e5e5e5; }
  .page-container { padding: 24px 14px 48px; }
  .page-header { margin-bottom: 24px; }
  .board-wrapper { max-width: min(500px, 100%); }
  .section-details, .section-skills { margin-top: 48px; }
}

@media (max-width: 480px) {
  .navbar-logo { font-size: 12px; letter-spacing: 0; }
  .title { font-size: 19px; }
  .subtitle { font-size: 11px; }
  .missions-col { grid-template-columns: 1fr; }
  .overlay { gap: 10px; padding: 12px; }
  .overlay-title { font-size: 11px; }
  .swatch { width: 27px; height: 27px; }
  .preview-dot { width: 14px; height: 14px; }
  .section-title { font-size: 14px; }
  .section-subtitle { font-size: 10px; }
  .modal-card { padding: 18px; }
}
.mission-project-image 
{
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 8px;
  margin: 15px 0;
  border: 1px solid #444;
  transition: transform 0.3s ease;
}

.mission-project-image:hover 
{
  transform: scale(1.02);
}

.mission-project-image.hidden 
{
  display: none;
}

@media (max-width: 600px) 
{
  .mission-project-image {
    max-height: 180px;
  }
}
