:root{
  --night: #0c1420;
  --night-deep: #070c14;
  --emerald: #2ee6a6;
  --emerald-dim: #1a8f68;
  --amber: #f4d35e;
  --violet: #6f5bb0;
  --violet-bright: #9d8df1;
  --bone: #eef2f0;
  --bone-dim: #a9b4b8;
  --panel: rgba(12, 20, 32, 0.9);
  --font-display: 'Cormorant Garamond', serif;
  --font-body: 'Spectral', serif;
  --font-mono: 'JetBrains Mono', monospace;
}

*{box-sizing:border-box; margin:0; padding:0;}

html,body{
  width:100%; height:100%;
  background:var(--night-deep);
  color:var(--bone);
  font-family:var(--font-body);
  overflow:hidden;
  -webkit-font-smoothing:antialiased;
}

.hidden{ display:none !important; }

.screen{
  position:fixed; inset:0;
  width:100%; height:100%;
}

/* ============ START SCREEN ============ */

#start-screen{
  display:flex; align-items:center; justify-content:center;
  background:
    radial-gradient(ellipse at 50% 20%, rgba(46,230,166,0.07), transparent 55%),
    linear-gradient(180deg, #0a1220 0%, #070c14 70%, #050810 100%);
  overflow-y:auto;
  padding:1rem 0;
}

.stars-bg{
  position:absolute; inset:0;
  background-image:
    radial-gradient(1px 1px at 10% 20%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1px 1px at 30% 60%, rgba(255,255,255,0.35), transparent),
    radial-gradient(1.5px 1.5px at 70% 15%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1px 1px at 85% 40%, rgba(255,255,255,0.3), transparent),
    radial-gradient(1px 1px at 50% 80%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1.5px 1.5px at 90% 75%, rgba(255,255,255,0.35), transparent),
    radial-gradient(1px 1px at 15% 85%, rgba(255,255,255,0.3), transparent);
  animation: twinkle 6s ease-in-out infinite;
  opacity:0.7;
}
@keyframes twinkle{ 0%,100%{opacity:0.5;} 50%{opacity:0.9;} }

.start-inner{
  position:relative;
  text-align:center;
  padding:1.5rem 2rem;
  max-width:560px;
  margin:0 auto;
}

.eyebrow{
  font-family:var(--font-mono);
  font-size:0.78rem;
  letter-spacing:0.35em;
  text-transform:uppercase;
  color:var(--emerald);
  margin-bottom:0.75rem;
  margin-right:-0.35em; /* letter-spacing adds trailing space after the last
                           character, which text-align:center counts as part
                           of the box — this pulls the visible glyphs back to
                           true center instead of skewing them off-axis */
  opacity:0.85;
}

.title{
  font-family:var(--font-display);
  font-weight:600;
  font-size:3.8rem;
  letter-spacing:0.08em;
  line-height:1;
  color:var(--bone);
  text-shadow: 0 0 40px rgba(46,230,166,0.35), 0 0 80px rgba(46,230,166,0.12);
  margin-bottom:0.75rem;
  margin-right:-0.08em; /* same letter-spacing centering correction as above */
}

.subtitle{
  font-family:var(--font-display);
  font-style:italic;
  font-weight:500;
  font-size:1.1rem;
  color:var(--bone-dim);
  line-height:1.45;
  max-width:420px;
  margin:0 auto 1.5rem;
}

.customize{
  margin-bottom:1.3rem;
}

.customize-label, .section-label{
  font-family:var(--font-mono);
  font-size:0.72rem;
  letter-spacing:0.2em;
  text-transform:uppercase;
  color:var(--bone-dim);
  margin-bottom:0.7rem;
}

.swatches{
  display:flex; gap:0.85rem; justify-content:center;
  margin-bottom:0.85rem;
}

.swatch{
  width:34px; height:34px;
  border-radius:50%;
  border:2px solid transparent;
  background:var(--swatch);
  cursor:pointer;
  box-shadow:0 0 0 rgba(0,0,0,0);
  transition:transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.swatch:hover{ transform:translateY(-2px) scale(1.08); }
.swatch.active{
  border-color:var(--bone);
  box-shadow:0 0 16px var(--swatch);
}

.preview-wrap{
  display:flex; justify-content:center;
}
#preview-canvas{
  width:76px; height:76px;
  filter:drop-shadow(0 0 12px rgba(46,230,166,0.25));
}

.continue-hint{
  font-family:var(--font-mono);
  font-size:0.72rem;
  letter-spacing:0.06em;
  color:var(--emerald);
  opacity:0;
  min-height:1.3em;
  margin-bottom:0.7rem;
  transition:opacity 0.3s ease;
}
.continue-hint.visible{ opacity:0.85; }

.reset-data-btn{
  margin-top:1.2rem;
  font-family:var(--font-mono);
  font-size:0.68rem;
  letter-spacing:0.14em;
  text-transform:uppercase;
  color:#e05a5a;
  background:transparent;
  border:1px solid rgba(224,90,90,0.4);
  padding:0.55rem 1.1rem;
  border-radius:2px;
  cursor:pointer;
  transition:background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.reset-data-btn:hover{
  background:rgba(224,90,90,0.14);
  color:#ff7a7a;
  border-color:#ff7a7a;
}

.begin-btn{
  font-family:var(--font-mono);
  font-size:0.92rem;
  letter-spacing:0.18em;
  text-transform:uppercase;
  color:var(--night-deep);
  background:var(--emerald);
  border:none;
  padding:0.85rem 2.6rem;
  border-radius:2px;
  cursor:pointer;
  transition:transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  box-shadow:0 0 0 rgba(46,230,166,0);
}
.begin-btn:hover{
  background:#3ff5b8;
  transform:translateY(-2px);
  box-shadow:0 6px 24px rgba(46,230,166,0.3);
}
.begin-btn:active{ transform:translateY(0); }

.controls-hint{
  display:grid;
  grid-template-columns:repeat(2, auto);
  justify-content:center;
  gap:0.4rem 2rem;
  margin-top:1.4rem;
  font-family:var(--font-mono);
  font-size:0.72rem;
  color:var(--bone-dim);
  opacity:0.6;
  text-align:left;
}
.controls-hint em{
  font-style:normal;
  color:var(--emerald);
  opacity:0.9;
}

/* ============ GAME SCREEN ============ */

#game-screen{
  background:var(--night-deep);
}

#game-canvas{
  display:block;
  width:100%; height:100%;
}

.hud{
  position:absolute; top:1.4rem; left:1.4rem;
  display:flex; align-items:center; gap:1rem;
  font-family:var(--font-mono);
  pointer-events:none;
  user-select:none;
}

.hud-item{
  display:flex; align-items:center; gap:0.45rem;
  background:rgba(7,12,20,0.55);
  border:1px solid rgba(46,230,166,0.25);
  padding:0.4rem 0.75rem;
  border-radius:2px;
  backdrop-filter:blur(6px);
  font-size:0.85rem;
  color:var(--bone);
}

.hud-hint{
  font-size:0.68rem;
  color:var(--bone-dim);
  opacity:0.55;
  letter-spacing:0.05em;
}

.mute-btn{
  pointer-events:auto; /* .hud disables clicks for its passive readouts — this button opts back in */
  display:flex; align-items:center; justify-content:center;
  width:32px; height:32px;
  background:rgba(7,12,20,0.55);
  border:1px solid rgba(46,230,166,0.25);
  border-radius:2px;
  backdrop-filter:blur(6px);
  font-size:0.95rem;
  line-height:1;
  cursor:pointer;
  color:var(--bone);
  transition:border-color 0.2s ease, background 0.2s ease;
}
.mute-btn:hover{
  border-color:var(--emerald);
  background:rgba(46,230,166,0.12);
}

.ambient-text{
  position:absolute;
  bottom:12%;
  left:50%;
  transform:translateX(-50%);
  font-family:var(--font-display);
  font-style:italic;
  font-size:1.3rem;
  color:var(--bone);
  text-shadow:0 0 20px rgba(0,0,0,0.8), 0 0 10px rgba(46,230,166,0.15);
  opacity:0;
  transition:opacity 1.8s ease;
  pointer-events:none;
  text-align:center;
  max-width:70%;
}
.ambient-text.visible{ opacity:0.92; }

.side-panel{
  position:absolute;
  top:50%;
  left:1.4rem;
  transform:translateY(-50%);
  display:flex;
  flex-direction:column;
  gap:0.7rem;
  align-items:stretch;
}

.controls-map{
  display:flex;
  flex-direction:column;
  gap:0.55rem;
  background:rgba(7,12,20,0.5);
  border:1px solid rgba(238,242,240,0.12);
  border-radius:3px;
  padding:0.9rem 1rem;
  backdrop-filter:blur(6px);
  pointer-events:none;
  user-select:none;
}

.save-game-btn{
  font-family:var(--font-mono);
  font-size:0.68rem;
  letter-spacing:0.1em;
  text-transform:uppercase;
  color:var(--bone);
  background:rgba(46,230,166,0.1);
  border:1px solid rgba(46,230,166,0.35);
  padding:0.6rem 0.8rem;
  border-radius:3px;
  cursor:pointer;
  backdrop-filter:blur(6px);
  transition:background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}
.save-game-btn:hover{
  background:rgba(46,230,166,0.2);
  border-color:var(--emerald);
}
.save-game-btn:active{ transform:scale(0.96); }
.save-game-btn.saved-flash{ animation:savedFlash 0.7s ease; }
@keyframes savedFlash{
  0%{ background:rgba(46,230,166,0.55); border-color:var(--emerald); }
  100%{ background:rgba(46,230,166,0.1); }
}

.controls-map-title{
  font-family:var(--font-mono);
  font-size:0.62rem;
  letter-spacing:0.24em;
  text-transform:uppercase;
  color:var(--emerald);
  opacity:0.8;
  margin-bottom:0.2rem;
}

.controls-map-row{
  display:flex;
  align-items:center;
  gap:0.4rem;
}

.key{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:20px;
  height:20px;
  padding:0 0.4rem;
  border:1px solid rgba(238,242,240,0.25);
  border-radius:3px;
  background:rgba(238,242,240,0.06);
  font-family:var(--font-mono);
  font-size:0.65rem;
  color:var(--bone);
}
.key.wide{ min-width:52px; }

.action{
  font-family:var(--font-mono);
  font-size:0.7rem;
  color:var(--bone-dim);
  margin-left:0.15rem;
}

@media (max-width:560px){
  .side-panel{ left:0.6rem; }
  .controls-map{
    padding:0.7rem 0.8rem;
    gap:0.4rem;
  }
  .controls-map-title{ font-size:0.55rem; }
  .key{ font-size:0.58rem; height:18px; }
  .action{ font-size:0.6rem; }
  .save-game-btn{ font-size:0.6rem; padding:0.5rem 0.65rem; }
}

.menu-return-btn{
  position:absolute; bottom:1.4rem; left:1.4rem;
  width:36px; height:36px;
  border-radius:50%;
  border:1px solid rgba(238,242,240,0.2);
  background:rgba(7,12,20,0.5);
  color:var(--bone-dim);
  font-size:1rem;
  cursor:pointer;
  backdrop-filter:blur(6px);
  transition:border-color 0.2s ease, color 0.2s ease;
}
.menu-return-btn:hover{
  border-color:var(--emerald);
  color:var(--emerald);
}

/* ============ INVENTORY / CRAFTING PANEL ============ */

.inventory-panel{
  position:absolute; top:0; right:0;
  width:min(380px, 92vw);
  height:100%;
  background:var(--panel);
  border-left:1px solid rgba(46,230,166,0.2);
  backdrop-filter:blur(10px);
  padding:2rem 1.6rem;
  overflow-y:auto;
  animation:slideIn 0.35s ease;
}
@keyframes slideIn{
  from{ transform:translateX(100%); opacity:0; }
  to{ transform:translateX(0); opacity:1; }
}

.inventory-header{
  display:flex; align-items:center; justify-content:space-between;
  margin-bottom:1.6rem;
  border-bottom:1px solid rgba(238,242,240,0.1);
  padding-bottom:1rem;
}
.inventory-header h2{
  font-family:var(--font-display);
  font-weight:500;
  font-size:1.5rem;
  letter-spacing:0.03em;
}
#close-inventory{
  background:none; border:none;
  color:var(--bone-dim);
  font-size:1.4rem;
  cursor:pointer;
  line-height:1;
  transition:color 0.2s ease;
}
#close-inventory:hover{ color:var(--emerald); }

.pack-section{ margin-bottom:1.8rem; }
.crafting-section{ margin-bottom:1.6rem; }

.slot-grid{
  display:grid;
  grid-template-columns:repeat(5, 1fr);
  gap:0.5rem;
}

.slot, .crafting-result{
  position:relative;
  aspect-ratio:1;
  background:rgba(238,242,240,0.04);
  border:1px solid rgba(238,242,240,0.14);
  border-radius:4px;
  cursor:pointer;
  display:flex; align-items:center; justify-content:center;
  transition:border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  user-select:none;
  -webkit-user-select:none;
}
.slot:hover{ border-color:rgba(46,230,166,0.45); background:rgba(46,230,166,0.06); }
.slot.selected{
  border-color:var(--emerald);
  box-shadow:0 0 0 1px var(--emerald) inset, 0 0 12px rgba(46,230,166,0.45);
}
.slot.drag-target{
  border-color:var(--violet-bright);
  background:rgba(157,141,241,0.12);
}
.slot canvas{ width:74%; height:74%; pointer-events:none; }

.slot-count{
  position:absolute; bottom:2px; right:4px;
  font-family:var(--font-mono); font-size:0.6rem;
  color:var(--bone);
  text-shadow:0 1px 2px rgba(0,0,0,0.9);
  pointer-events:none;
}

.crafting-row{
  display:flex;
  align-items:center;
  gap:0.8rem;
  margin-bottom:0.7rem;
}

.crafting-grid{
  display:grid;
  grid-template-columns:repeat(3, 1fr);
  gap:0.4rem;
  width:132px;
}

.crafting-arrow{
  font-family:var(--font-mono);
  color:var(--bone-dim);
  font-size:1.1rem;
  opacity:0.6;
  flex-shrink:0;
}

.crafting-result{
  width:48px; height:48px;
  flex-shrink:0;
  border-style:dashed;
}
.crafting-result canvas{ width:78%; height:78%; }
.crafting-result.ready{
  border-style:solid;
  border-color:var(--violet-bright);
  cursor:pointer;
  animation:resultPulse 1.6s ease-in-out infinite;
}
@keyframes resultPulse{
  0%,100%{ box-shadow:0 0 8px rgba(157,141,241,0.35); }
  50%{ box-shadow:0 0 22px rgba(157,141,241,0.75); }
}

.crafting-hint{
  font-family:var(--font-mono);
  font-size:0.66rem;
  letter-spacing:0.03em;
  color:var(--bone-dim);
  opacity:0.75;
  line-height:1.5;
}

.inv-tip{
  font-family:var(--font-mono);
  font-size:0.62rem;
  letter-spacing:0.02em;
  color:var(--bone-dim);
  opacity:0.65;
  line-height:1.5;
  margin-top:0.6rem;
}
.inv-tip b{ color:var(--emerald); font-weight:600; }

.inv-footnote{
  font-family:var(--font-display);
  font-style:italic;
  font-size:0.9rem;
  color:var(--bone-dim);
  opacity:0.6;
  margin-top:1.6rem;
  line-height:1.5;
}

@media (max-width:560px){
  .title{ font-size:2.7rem; }
  .subtitle{ font-size:0.95rem; }
  .controls-hint{ grid-template-columns:1fr; gap:0.32rem; text-align:center; }
  .inventory-panel{ padding:1.6rem 1.1rem; }
}

@media (prefers-reduced-motion: reduce){
  .stars-bg{ animation:none; }
  .begin-btn, .swatch{ transition:none; }
  .crafting-result.ready{ animation:none; }
}

@media (prefers-reduced-motion: reduce){
  .stars-bg{ animation:none; }
  .begin-btn, .swatch{ transition:none; }
  .crafting-result.ready{ animation:none; }
}

::selection{ background:var(--emerald); color:var(--night-deep); }

/* ==============================================
   Firefox (Standard CSS)
   ============================================== */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--emerald-dim) var(--night-deep);
}

/* ==============================================
   Chrome, Edge, Safari, and Electron (WebKit)
   ============================================== */

/* 1. Width and height of the scrollbar */
::-webkit-scrollbar {
  width: 14px; /* Vertical scrollbar width */
  height: 14px; /* Horizontal scrollbar height */
}

/* 2. The track (background) of the scrollbar */
::-webkit-scrollbar-track {
  background: var(--night-deep);
  /* Optional: adds a subtle border to blend with the app background */
  border-left: 1px solid var(--night); 
}

/* 3. The draggable handle (thumb) */
::-webkit-scrollbar-thumb {
  background-color: var(--emerald-dim);
  border-radius: 10px;
  /* The border acts as "padding" around the thumb since WebKit doesn't support margin on scrollbars */
  border: 3px solid var(--night-deep); 
  /* Smooth transition for hover */
  transition: background-color 0.3s ease; 
}

/* 4. Hover state for the thumb */
::-webkit-scrollbar-thumb:hover {
  background-color: var(--emerald);
}

/* 5. The corner where vertical and horizontal scrollbars meet */
::-webkit-scrollbar-corner {
  background: var(--night-deep);
}
