@import url('https://fonts.googleapis.com/css2?family=IM+Fell+English:ital@0;1&family=IM+Fell+DW+Pica+SC&family=Caveat:wght@400;600&display=swap');

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

body {
  background: #1a1611;
  overflow: hidden;
  font-family: 'IM Fell English', serif;
  color: #3a2f24;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
}

#gameCanvas { display: block; position: absolute; top: 0; left: 0; touch-action: none; }

#uiLayer {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none; z-index: 10;
}

/* ---------------------------------------------------------- */
/* TOOLBAR                                                     */
/* ---------------------------------------------------------- */

#toolbar {
  position: absolute; bottom: 24px; left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 6px;
  pointer-events: all;
  background: rgba(62, 48, 34, 0.85);
  border: 1px solid #5a4a38;
  border-radius: 8px;
  padding: 8px 14px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.tool-btn {
  width: 56px; height: 56px;
  border: 2px solid #5a4a38; border-radius: 6px;
  background: rgba(245, 235, 220, 0.08);
  color: #c4a882; font-size: 11px;
  font-family: 'IM Fell DW Pica SC', serif;
  cursor: pointer;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  transition: all 0.2s; position: relative;
}

.tool-btn svg { width: 22px; height: 22px; stroke: #c4a882; fill: none; stroke-width: 1.5; }
.tool-btn:hover { background: rgba(245, 235, 220, 0.15); border-color: #c4a882; }
.tool-btn.active { background: rgba(196, 168, 130, 0.25); border-color: #d4b896; color: #e8d5bc; }
.tool-btn.active svg { stroke: #e8d5bc; }
.tool-btn.measuring { background: rgba(196, 85, 61, 0.3); border-color: #c4553d; }
.tool-btn.measuring svg { stroke: #e8a090; }

.tool-key {
  position: absolute; top: -8px; right: -4px;
  background: #5a4a38; color: #c4a882;
  font-size: 9px; padding: 1px 4px;
  border-radius: 3px; font-family: monospace;
}

#audioSettingsBtn {
  font-size: 24px;
  font-family: system-ui, sans-serif; /* ⚙ renders as text glyph, not emoji */
  line-height: 1;
  color: #c4a882;
}

/* ---------------------------------------------------------- */
/* TITLE CARD                                                  */
/* ---------------------------------------------------------- */

#titleCard {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center; pointer-events: all;
  z-index: 100; animation: fadeIn 1.5s ease;
}

#titleCard h1 {
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: clamp(24px, 7vw, 52px); color: #3a2f24;
  letter-spacing: clamp(2px, 0.8vw, 6px); text-transform: uppercase;
  margin-bottom: 8px;
  text-shadow: 0 1px 0 rgba(255,255,255,0.15);
}

#titleCard p {
  font-family: 'IM Fell English', serif;
  font-style: italic; color: #6a5a48;
  font-size: 16px; margin-bottom: 32px;
}

#startBtn {
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: 18px; color: #e8d5bc;
  background: rgba(62, 48, 34, 0.8);
  border: 1px solid #5a4a38;
  padding: 12px 40px; border-radius: 6px;
  cursor: pointer; letter-spacing: 3px;
  transition: all 0.3s;
}
#startBtn:hover { background: rgba(82, 68, 54, 0.9); border-color: #c4a882; }
.tool-btn, #startBtn, #newMapBtn, #panelToggle { touch-action: manipulation; }

/* ---------------------------------------------------------- */
/* INFO PANEL (top-left)                                       */
/* ---------------------------------------------------------- */

#infoPanel {
  position: absolute; top: 16px; left: 16px;
  pointer-events: all; opacity: 0; transition: opacity 0.5s;
  background: rgba(62, 48, 34, 0.85);
  border: 1px solid #5a4a38;
  border-radius: 8px;
  padding: 14px 16px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  min-width: 220px;
}
#infoPanel.visible { opacity: 1; }

#islandName {
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: 20px; color: #c4a882; letter-spacing: 2px;
}

#panelSummary {
  display: none;
  font-family: 'IM Fell English', serif;
  font-style: italic; color: #8a9a6a; font-size: 24px; margin-top: 3px;
}

/* ---------------------------------------------------------- */
/* QUEST TRACKER                                               */
/* ---------------------------------------------------------- */

#questTracker {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(90, 74, 56, 0.3);
}

.quest-item {
  font-family: 'IM Fell English', serif;
  font-size: 18px; color: #a89478;
  margin-top: 5px;
  display: flex; align-items: center; gap: 6px;
  transition: color 0.5s;
}
.quest-item.complete { color: #9aaa7a; }

.quest-check {
  display: inline-block; width: 12px; height: 12px;
  border: 1px solid #7a6a58; border-radius: 2px;
  flex-shrink: 0; position: relative;
  transition: border-color 0.5s, background 0.5s;
}
.quest-item.complete .quest-check {
  border-color: #9aaa7a;
  background: rgba(154, 170, 122, 0.2);
}
.quest-item.complete .quest-check::after {
  content: '✓'; position: absolute;
  top: -2px; left: 1px;
  font-size: 11px; color: #9aaa7a;
}

.quest-detail { font-size: 22px; color: #8a7a68; }
.quest-item.complete .quest-detail { color: #8a9a6a; }
#questMeasureDetail { font-size: 18px; }

/* ---------------------------------------------------------- */
/* NEW MAP BUTTON                                              */
/* ---------------------------------------------------------- */

#newMapBtn {
  display: none; margin-top: 12px;
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: 14px; color: #e8d5bc;
  background: rgba(62, 48, 34, 0.8);
  border: 1px solid #5a4a38;
  padding: 8px 20px; border-radius: 5px;
  cursor: pointer; letter-spacing: 2px;
  pointer-events: all;
  transition: all 0.3s; animation: fadeIn 1s ease;
}
#newMapBtn:hover { background: rgba(82, 68, 54, 0.9); border-color: #c4a882; }

/* ---------------------------------------------------------- */
/* PANEL HEADER + TOGGLE                                       */
/* ---------------------------------------------------------- */

#panelHeader {
  display: flex; align-items: center; gap: 8px;
}

#panelToggle {
  background: none; border: none;
  color: #8a7a68; font-size: 0;
  cursor: pointer; pointer-events: all;
  padding: 0; flex-shrink: 0; line-height: 1;
  transition: color 0.2s;
}
#panelToggle::before       { content: '▲'; font-size: 11px; }
#panelToggle:hover         { color: #c4a882; }

#infoPanel.collapsed #questTracker,
#infoPanel.collapsed #coordSection,
#infoPanel.collapsed #specimenSection,
#infoPanel.collapsed #newMapBtn { display: none; }
#infoPanel.collapsed #panelSummary { display: block; }
#infoPanel.collapsed #panelToggle::before { content: '▼'; }

/* ---------------------------------------------------------- */
/* MEASURE DISPLAY                                             */
/* ---------------------------------------------------------- */

#measureDisplay {
  position: absolute; bottom: 96px; left: 50%;
  transform: translateX(-50%);
  font-family: 'Caveat', cursive; font-size: 22px;
  color: #c4553d; text-align: center;
  pointer-events: none; opacity: 0;
  transition: opacity 0.3s; white-space: nowrap;
  text-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
#measureDisplay.visible { opacity: 1; }
#measureDisplay .label {
  font-family: 'IM Fell English', serif;
  font-size: 11px; color: #8a7a68;
  font-style: italic; display: block;
}

/* ---------------------------------------------------------- */
/* TOOL HINT                                                   */
/* ---------------------------------------------------------- */

#toolHint {
  position: absolute; bottom: 96px; left: 50%;
  transform: translateX(-50%);
  font-family: 'IM Fell English', serif;
  font-style: italic; color: #8a7a68; font-size: 26px;
  text-align: center; pointer-events: none;
  opacity: 0; transition: opacity 0.4s; white-space: nowrap;
}
#toolHint.visible { opacity: 1; }

/* ---------------------------------------------------------- */
/* COMPASS                                                     */
/* ---------------------------------------------------------- */

#zoomIndicator {
  position: absolute; top: 16px; right: 16px;
  width: 60px; text-align: center;
  font-family: 'Caveat', cursive;
  font-size: 13px; color: #6a5a48;
  pointer-events: none; opacity: 0; transition: opacity 0.5s;
}
#zoomIndicator.visible { opacity: 1; }

/* ---------------------------------------------------------- */
/* SPECIMEN SECTION (inside info panel)                        */
/* ---------------------------------------------------------- */

#specimenSection {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(90, 74, 56, 0.3);
}

#specimenPanel {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px;
}

.specimen-slot {
  width: 36px; height: 36px;
  border: 1px solid #5a4a38; border-radius: 4px;
  background: rgba(20, 14, 8, 0.3);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; opacity: 0.3; transition: opacity 0.5s;
}
.specimen-slot.collected { opacity: 1; background: rgba(20, 14, 8, 0.5); }

/* ---------------------------------------------------------- */
/* COORD SECTION (inside info panel)                           */
/* ---------------------------------------------------------- */

#coordSection {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(90, 74, 56, 0.3);
}

.coord-title {
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: 11px; color: #a89478;
  letter-spacing: 2px; margin-bottom: 6px;
  text-transform: uppercase;
}

.coord-row {
  font-family: 'Caveat', cursive;
  font-size: 18px; color: #c4a882;
  letter-spacing: 1px; line-height: 1.4;
}

.coord-row .digit {
  display: inline-block; min-width: 11px;
  text-align: center; transition: color 0.5s, text-shadow 0.5s;
}
.coord-row .digit.hidden  { color: #5a4a38; }
.coord-row .digit.revealed {
  color: #e8d5bc;
  text-shadow: 0 0 8px rgba(196, 168, 130, 0.4);
}
.coord-row .digit.fresh {
  color: #c4a882;
  animation: digitReveal 1.2s ease;
}

.coord-progress {
  margin-top: 8px;
  font-family: 'IM Fell English', serif;
  font-style: italic; font-size: 11px; color: #8a7a68;
}
.coord-progress-bar {
  height: 3px; background: #3a3025;
  border-radius: 2px; margin-top: 4px; overflow: hidden;
}
.coord-progress-fill {
  height: 100%; background: #4a7a9a;
  border-radius: 2px; transition: width 0.8s ease; width: 0%;
}

/* ---------------------------------------------------------- */
/* SEXTANT FEEDBACK TOAST                                      */
/* ---------------------------------------------------------- */

#sextantFeedback {
  position: absolute; bottom: 160px; left: 50%;
  transform: translateX(-50%);
  font-family: 'IM Fell English', serif; font-style: italic;
  font-size: 26px; color: #8a7a68;
  pointer-events: none; opacity: 0; transition: opacity 0.4s;
  text-align: center; white-space: nowrap;
}
#sextantFeedback.visible { opacity: 1; }
#sextantFeedback.success { color: #4a7a9a; }

/* ---------------------------------------------------------- */
/* LANDMARK DISCOVERY TOAST                                    */
/* ---------------------------------------------------------- */

#landmarkToast {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: 24px; color: #c4a882;
  letter-spacing: 3px; text-align: center;
  pointer-events: none; opacity: 0; transition: opacity 0.6s;
  text-shadow: 0 2px 12px rgba(0,0,0,0.3);
}
#landmarkToast .sub {
  font-family: 'IM Fell English', serif;
  font-size: 14px; font-style: italic;
  color: #8a7a68; letter-spacing: 1px; margin-top: 4px;
}
#landmarkToast.visible { opacity: 1; }

/* ---------------------------------------------------------- */
/* KEYFRAME ANIMATIONS                                         */
/* ---------------------------------------------------------- */

@keyframes fadeIn {
  from { opacity: 0; transform: translate(-50%, -48%); }
  to   { opacity: 1; transform: translate(-50%, -50%); }
}

@keyframes digitReveal {
  0%   { color: #4a7a9a; text-shadow: 0 0 16px rgba(74,122,154,0.8); transform: scale(1.3); }
  50%  { text-shadow: 0 0 12px rgba(74,122,154,0.5); }
  100% { color: #e8d5bc; text-shadow: 0 0 8px rgba(196,168,130,0.4); transform: scale(1); }
}

@keyframes detailPulse {
  0%   { transform: scale(1);    color: inherit; }
  30%  { transform: scale(1.25); color: #c4a882; }
  100% { transform: scale(1);    color: inherit; }
}

.quest-detail.pulse {
  display: inline-block;
  animation: detailPulse 0.5s ease-out forwards;
}

/* ---------------------------------------------------------- */
/* QUEST COMPLETE TOAST                                        */
/* ---------------------------------------------------------- */

#questCompleteToast {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translateX(-50%);
  background: rgba(90, 120, 80, 0.92);
  color: #f5f0e8;
  font-family: 'IM Fell English', serif;
  font-size: 22px;
  padding: 14px 28px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.2);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s;
  z-index: 200;
  text-align: center;
  white-space: nowrap;
}
#questCompleteToast.visible { opacity: 1; }

/* ---------------------------------------------------------- */
/* DEBUG PANEL                                                 */
/* ---------------------------------------------------------- */

#debugGear {
  position: fixed;
  bottom: 12px;
  right: 12px;
  background: none;
  border: none;
  font-size: 20px;
  opacity: 0.2;
  cursor: pointer;
  color: #3a2f24;
  transition: opacity 0.2s;
  z-index: 9999;
  padding: 4px;
}
#debugGear:hover { opacity: 0.7; }

#debugPanel {
  display: none;
  position: fixed;
  bottom: 44px;
  right: 12px;
  background: rgba(40, 30, 20, 0.92);
  border-radius: 6px;
  padding: 8px;
  z-index: 9999;
  flex-direction: column;
  gap: 5px;
}
#debugPanel.visible { display: flex; }

#debugPanel button {
  background: rgba(245, 235, 220, 0.12);
  border: 1px solid rgba(245, 235, 220, 0.25);
  color: #e8d5bc;
  padding: 5px 10px;
  border-radius: 4px;
  font: 20px 'Caveat', cursive;
  cursor: pointer;
  white-space: nowrap;
}
#debugPanel button:hover { background: rgba(245, 235, 220, 0.22); }

/* ---------------------------------------------------------- */
/* COMPLETION OVERLAY                                          */
/* ---------------------------------------------------------- */

#completionOverlay {
  position: absolute; inset: 0;
  background: rgba(30, 22, 14, 0.82);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.8s;
  z-index: 200;
}
#completionOverlay.visible { opacity: 1; pointer-events: all; }

#completionCard {
  background: #f5ebdc;
  border: 2px solid #3a2f24; border-radius: 4px;
  padding: 32px 40px; text-align: center; max-width: 380px;
  font-family: 'IM Fell DW Pica', serif;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}
#completionHeading {
  font-size: 26px; color: #3a2f24;
  text-transform: uppercase; letter-spacing: 4px;
  margin-bottom: 4px;
}
#completionIslandName {
  font-size: 16px; color: #6a5a48;
  font-style: italic; margin-bottom: 20px;
}
#completionStats {
  font-size: 13px; color: #5a4a38;
  line-height: 1.9; margin-bottom: 20px;
  text-align: left;
}
#completionNewBtn {
  font-family: 'IM Fell English', serif;
  font-size: 14px; letter-spacing: 2px;
  color: #f5ebdc; background: #3a2f24;
  border: 1px solid #5a4a38; border-radius: 3px;
  padding: 10px 24px; cursor: pointer;
  transition: background 0.2s;
  touch-action: manipulation;
}
#completionNewBtn:hover { background: #5a4a38; }

/* ---------------------------------------------------------- */
/* AUDIO SETTINGS MODAL                                        */
/* ---------------------------------------------------------- */

#audioModal {
  position: absolute; inset: 0;
  background: rgba(20, 14, 8, 0.72);
  display: flex; align-items: center; justify-content: center;
  z-index: 300;
  pointer-events: none; opacity: 0;
  transition: opacity 0.25s;
}
#audioModal.visible { pointer-events: all; opacity: 1; }

.modal-card {
  background: rgba(50, 38, 26, 0.97);
  border: 1px solid #5a4a38;
  border-radius: 8px;
  padding: 24px 28px;
  min-width: 260px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-title {
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: 14px; color: #c4a882;
  letter-spacing: 3px; text-transform: uppercase;
  text-align: center; margin-bottom: 16px;
}

.modal-mute-btn {
  width: 100%; padding: 9px;
  font-family: 'IM Fell English', serif;
  font-size: 14px; color: #e8d5bc;
  background: rgba(245, 235, 220, 0.08);
  border: 1px solid #5a4a38; border-radius: 5px;
  cursor: pointer; margin-bottom: 16px;
  transition: background 0.2s, color 0.2s;
}
.modal-mute-btn:hover { background: rgba(245, 235, 220, 0.15); }
.modal-mute-btn.muted { color: #7a6a58; border-color: #3a2f24; }

.modal-sliders {
  display: flex; flex-direction: column; gap: 10px;
  margin-bottom: 16px;
}
.modal-sliders label {
  font-family: 'IM Fell English', serif;
  font-size: 12px; color: #a89478;
  display: flex; justify-content: space-between;
  align-items: center; gap: 10px;
}
.modal-sliders input[type="range"] {
  flex: 1; accent-color: #c4a882; cursor: pointer;
}

#audioModalClose {
  width: 100%; padding: 8px;
  font-family: 'IM Fell DW Pica SC', serif;
  font-size: 12px; letter-spacing: 2px;
  color: #6a5a48; background: none;
  border: 1px solid #3a3025; border-radius: 5px;
  cursor: pointer; transition: all 0.2s;
}
#audioModalClose:hover { border-color: #5a4a38; color: #c4a882; }

/* ---------------------------------------------------------- */
/* MOBILE — max-width: 600px                                   */
/* ---------------------------------------------------------- */

@media (max-width: 600px) {
  /* Toolbar: shrink to fit 320px screens, preserve safe-area */
  #toolbar {
    gap: 4px;
    padding: 6px 10px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    bottom: 16px;
  }
  .tool-btn { width: 48px; height: 48px; font-size: 10px; gap: 2px; }
  .tool-btn svg { width: 20px; height: 20px; }
  .tool-key { display: none; }


  /* Info panel: compact on narrow screens */
  #infoPanel { min-width: 0; max-width: calc(100vw - 100px); padding: 10px 12px; }
  .coord-row { font-size: 15px; }
  .specimen-slot { width: 32px; height: 32px; font-size: 17px; }

  /* Measure display and tool hint: clear taller toolbar */
  #measureDisplay, #toolHint { bottom: 110px; }
}
