:root {
  --ink: #e8f0fa;
  --muted: #8eaccb;
  --gold: #e6c36a;
  --panel: rgba(6, 14, 28, 0.92);
  --edge: rgba(140, 180, 224, 0.28);
  --sea: #071422;
  --danger: #e2c2c2;
  --sans: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --serif: "Iowan Old Style", Palatino, Georgia, serif;
  --panel-w: 312px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--sea); color: var(--ink); font-family: var(--sans); }
body { overflow: hidden; }

#canvas-container { position: fixed; inset: 0; }
#canvas-container canvas { display: block; width: 100%; height: 100%; }

#title {
  position: fixed;
  z-index: 5;
  top: 18px;
  left: var(--panel-w);
  right: 20px;
  margin: 0;
  text-align: center;
  pointer-events: none;
}
#title h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.65);
}
.eyebrow {
  margin: 0 0 2px;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #d7e7f8;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.75);
}

#panel {
  position: fixed;
  z-index: 6;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  width: var(--panel-w);
  padding: 22px 16px 16px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(8, 18, 34, 0.98), rgba(6, 12, 24, 0.98));
  border-right: 1px solid var(--edge);
}
#island-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(150, 186, 230, 0.35) transparent;
}
#panel-header {
  margin: 0 0 14px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #b9d2ee;
}
#progress-bar {
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
}
#progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2c7eb6, var(--gold));
  transition: width 0.45s ease;
}
#progress-text {
  margin: 8px 0 0;
  text-align: right;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
#progress-hint {
  min-height: 2.6em;
  margin: 4px 0 14px;
  font-size: 13px;
  line-height: 1.4;
  color: #c9daec;
}

.island-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  margin: 0 0 6px;
  padding: 8px 10px;
  border: 1px solid rgba(150, 186, 230, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  color: #6f90b0;
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.island-btn.unlocked {
  color: var(--ink);
  background: rgba(36, 86, 146, 0.2);
  border-color: rgba(120, 186, 240, 0.32);
}
.island-btn .btn-icon { width: 1.1em; color: var(--gold); text-align: center; }
.island-btn .btn-name { flex: 1; }
.island-btn .btn-num { font-size: 11px; color: #8aa5c0; }
.island-btn:hover { border-color: rgba(180, 210, 240, 0.45); }

button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.panel-actions {
  display: grid;
  flex: none;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--edge);
}
.panel-actions button {
  min-height: 44px;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}
#restore-next-btn {
  color: #1c1506;
  background: linear-gradient(180deg, #f3d898, #d7ae4a);
  border: 1px solid #f6e4b0;
}
#restore-next-btn:disabled {
  color: #8d7a46;
  background: rgba(230, 195, 106, 0.14);
  border-color: rgba(230, 195, 106, 0.28);
  cursor: default;
}
#restore-all-btn {
  color: var(--gold);
  background: transparent;
  border: 1px solid rgba(230, 195, 106, 0.45);
}
#share-btn {
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--edge);
}
#reset-btn {
  color: var(--danger);
  background: transparent;
  border: 1px solid rgba(226, 194, 194, 0.3);
  font-weight: 550;
}
.panel-actions button:hover:not(:disabled) { filter: brightness(1.08); }

#detail-panel {
  position: fixed;
  z-index: 7;
  top: 78px;
  right: 16px;
  width: min(300px, calc(100vw - var(--panel-w) - 36px));
  max-height: calc(100vh - 140px);
  overflow: auto;
  padding: 16px 16px 14px;
  border: 1px solid var(--edge);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}
#detail-panel h2 {
  margin: 0 36px 6px 0;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--gold);
}
.terrain-tag {
  display: inline-block;
  margin: 0 0 10px;
  padding: 2px 8px;
  border-radius: 99px;
  background: rgba(120, 168, 220, 0.14);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
#detail-desc {
  margin: 0 0 8px;
  color: #c5d6e8;
  font-size: 13px;
  line-height: 1.45;
}
.location-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-top: 1px solid rgba(150, 186, 230, 0.12);
  color: #e4eef8;
  font-size: 13px;
}
.loc-icon { width: 8px; height: 8px; flex: none; border-radius: 50%; }
.loc-icon.town { background: #4a9eff; }
.loc-icon.castle { background: #ffd700; }
.loc-icon.dungeon { background: #ff5555; }
.loc-icon.shrine { background: #ffffff; }
.loc-icon.volcano { background: #ff6633; }
.loc-icon.village { background: #66cc66; }
.loc-icon.abbey { background: #cc99ff; }
.loc-icon.camp { background: #88cc44; }
.loc-icon.casino { background: #ff66cc; }
#detail-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
#detail-close:hover { color: white; background: rgba(255, 255, 255, 0.06); }

#controls-hint {
  position: fixed;
  z-index: 5;
  right: 0;
  bottom: 14px;
  left: var(--panel-w);
  margin: 0;
  color: rgba(236, 244, 255, 0.78);
  font-size: 12px;
  letter-spacing: 0.01em;
  text-align: center;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.85);
  pointer-events: none;
}

#panel-toggle { display: none; }
.hint-short { display: none; }

#boot {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(ellipse at center, #12304e 0%, var(--sea) 70%);
  text-align: center;
}
#boot[hidden] { display: none; }
#boot p {
  margin: 0;
  max-width: 22em;
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1.35;
  color: var(--gold);
}
#boot a { color: var(--ink); }

.island-label {
  color: white;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  text-shadow: 0 0 6px rgba(0, 30, 70, 0.9), 0 1px 2px rgba(0, 0, 0, 0.95);
  pointer-events: none;
}
.location-marker {
  display: flex;
  align-items: center;
  gap: 4px;
  pointer-events: none;
}
.location-marker .dot {
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: 50%;
  box-shadow: 0 0 4px currentColor;
}
.location-marker .label-text {
  color: rgba(226, 236, 255, 0.9);
  font-size: 10px;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.95);
}

@media (max-width: 720px) {
  #title { top: 10px; right: 8px; left: 8px; }
  #title h1 { font-size: 18px; letter-spacing: 0.08em; }
  .eyebrow { font-size: 10px; letter-spacing: 0.12em; }
  #controls-hint {
    right: 12px;
    bottom: 64px;
    left: 12px;
    font-size: 11px;
  }
  #panel-toggle {
    position: fixed;
    z-index: 8;
    right: 10px;
    bottom: 10px;
    left: 10px;
    display: block;
    height: 44px;
    border: 1px solid var(--edge);
    border-radius: 10px;
    background: rgba(6, 14, 28, 0.95);
    color: var(--gold);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
  }
  .hint-full { display: none; }
  .hint-short { display: inline; }
  #panel {
    top: auto;
    right: 10px;
    bottom: 62px;
    left: 10px;
    width: auto;
    max-height: 54vh;
    padding: 12px;
    border: 1px solid var(--edge);
    border-right: 1px solid var(--edge);
    border-radius: 12px;
  }
  #panel:not(.open) { display: none; }
  #panel.open ~ #controls-hint { visibility: hidden; }
  #detail-panel {
    top: auto;
    right: 10px;
    bottom: 62px;
    left: 10px;
    width: auto;
    max-height: 42vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  #progress-fill { transition: none; }
}
