* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  background:
    radial-gradient(ellipse 140% 70% at 50% 118%, rgba(28, 73, 126, 0.95) 0%, rgba(13, 32, 53, 0.82) 28%, rgba(6, 14, 26, 0.4) 52%, rgba(0, 0, 0, 0) 68%),
    linear-gradient(180deg, #000 0%, #010308 38%, #030812 68%, #06101d 100%);
  background-attachment: fixed;
  color: #e8eef5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 1400px; margin: 0 auto; padding: 32px 20px 60px; }
header { margin-bottom: 28px; text-align: center; }
header h1 { font-size: 32px; font-weight: 500; letter-spacing: 0.02em; margin-bottom: 6px; }
header p { color: #8a95a3; font-size: 14px; }

.controls {
  display: flex; gap: 10px; margin: 0 auto 20px;
  max-width: 640px; flex-wrap: wrap; justify-content: center;
}
.controls input[type="text"] {
  flex: 1; min-width: 220px;
  background: #141a22; border: 1px solid #2a3340; color: #e8eef5;
  padding: 12px 16px; border-radius: 8px; font-size: 16px;
  outline: none; transition: border-color 0.15s;
}
.controls input[type="text"]:focus { border-color: #4a9eff; }
.controls button, .action-bar button {
  background: #2563eb; border: 1px solid #2563eb; color: #fff;
  padding: 12px 20px; border-radius: 8px; font-size: 14px;
  font-weight: 500; cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.controls button:hover, .action-bar button:hover { background: #1d4fd6; border-color: #1d4fd6; }
.controls button.secondary, .action-bar button.secondary { background: #1b2430; border-color: #2a3340; color: #e8eef5; }
.controls button.secondary:hover, .action-bar button.secondary:hover { background: #232d3b; border-color: #3a4556; }
.controls button:disabled, .action-bar button:disabled { opacity: 0.4; cursor: not-allowed; }
.controls button.active, .action-bar button.active { background: #f5a623; border-color: #f5a623; color: #0a0e14; }

.action-bar {
  display: flex; gap: 10px; margin: 0 auto 20px;
  max-width: 880px; flex-wrap: wrap; justify-content: center;
}

.legend { text-align: center; color: #6b7685; font-size: 12px; margin-bottom: 20px; padding: 0 16px; }

/* Tiles view */
.letters { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.letter { position: relative; width: 160px; flex-shrink: 0; }
.letter.space { width: 40px; }
.letter .tile {
  position: relative; aspect-ratio: 5/12;
  background: #141a22; border: 1px solid #2a3340;
  border-radius: 8px; overflow: hidden; transition: border-color 0.2s;
  cursor: pointer;
}
.letter.locked .tile { border-color: #f5a623; box-shadow: 0 0 0 1px #f5a623; }
.letter .tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.letter .tile:hover img { filter: brightness(1.08); }
.letter .placeholder {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: 72px; font-weight: 300; color: #4a5668;
  background: linear-gradient(135deg, #141a22 0%, #1b2430 50%, #0f1620 100%);
}
.letter .lock-btn, .letter .reroll-btn, .letter .info-btn {
  position: absolute; width: 30px; height: 30px; border-radius: 50%;
  background: rgba(0,0,0,0.65); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: #fff; transition: all 0.15s; padding: 0; z-index: 2;
}
.letter .lock-btn { top: 8px; right: 8px; }
.letter .reroll-btn { top: 8px; left: 8px; opacity: 0; }
.letter .info-btn { bottom: 8px; right: 8px; opacity: 0; }
.letter:hover .reroll-btn, .letter:hover .info-btn { opacity: 1; }
.letter.locked .reroll-btn { opacity: 0; pointer-events: none; }
.letter .lock-btn:hover, .letter .info-btn:hover { background: rgba(0,0,0,0.85); transform: scale(1.08); }
.letter.locked .lock-btn { background: #f5a623; color: #0a0e14; }
.letter .lock-btn svg, .letter .reroll-btn svg, .letter .info-btn svg { width: 15px; height: 15px; }
.letter .reroll-btn:hover { background: rgba(0,0,0,0.85); transform: scale(1.08) rotate(90deg); }

.letter .caption { margin-top: 8px; text-align: center; min-height: 32px; }
.letter .letter-label { font-size: 13px; font-weight: 500; color: #e8eef5; letter-spacing: 0.05em; }
.letter .location { font-size: 11px; color: #6b7685; margin-top: 2px; line-height: 1.3; padding: 0 4px; }
.letter .no-image-note { font-size: 10px; color: #6b7685; font-style: italic; margin-top: 2px; }

.empty { text-align: center; padding: 60px 20px; color: #6b7685; font-size: 15px; }

/* Map view */
.map-container {
  display: none; background: #050810; border: 1px solid #1a2230;
  border-radius: 12px; overflow: hidden; margin: 0 auto;
  max-width: 1200px; position: relative;
}
body.map-mode .map-container { display: block; }
body.map-mode .letters { display: none; }
.map-stats {
  display: flex; gap: 24px; padding: 16px 20px;
  border-bottom: 1px solid #1a2230; flex-wrap: wrap;
  justify-content: center; font-size: 12px;
}
.map-stat { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.map-stat .label { color: #6b7685; text-transform: uppercase; letter-spacing: 0.1em; font-size: 10px; }
.map-stat .value { color: #e8eef5; font-size: 15px; font-weight: 500; }
.map-svg-wrap { position: relative; padding: 20px; }
#mapSvg { display: block; width: 100%; height: auto; background: #030610; border-radius: 4px; }
#mapSvg .land { fill: #0f1822; stroke: #1a2634; stroke-width: 0.5; }
#mapSvg .graticule { fill: none; stroke: #0f1620; stroke-width: 0.3; }
#mapSvg .equator { fill: none; stroke: #1f2a3a; stroke-width: 0.5; stroke-dasharray: 2,3; }
#mapSvg .path-line {
  fill: none; stroke: #f5a623; stroke-width: 1.5;
  stroke-dasharray: 4,3; opacity: 0.7;
}
#mapSvg .pin-outer { fill: #2563eb; stroke: #0a0e14; stroke-width: 1.5; cursor: pointer; }
#mapSvg .pin-outer:hover { fill: #4a9eff; }
#mapSvg .pin-text { fill: #fff; font-size: 9px; font-weight: 600; pointer-events: none; text-anchor: middle; dominant-baseline: central; font-family: -apple-system, sans-serif; }
.map-tooltip {
  position: absolute; pointer-events: none;
  background: rgba(10,14,20,0.95); color: #e8eef5;
  padding: 6px 10px; border: 1px solid #2a3340; border-radius: 6px;
  font-size: 12px; opacity: 0; transition: opacity 0.15s;
  z-index: 10; white-space: nowrap;
  transform: translate(-50%, -120%);
}
.map-tooltip.show { opacity: 1; }
.map-tooltip .t-letter { color: #f5a623; font-weight: 600; margin-right: 6px; }
.map-fallback {
  padding: 60px 30px; text-align: center; color: #6b7685;
  font-size: 13px; line-height: 1.6;
}

.footer-note { text-align: center; margin-top: 40px; color: #4a5463; font-size: 12px; line-height: 1.6; padding: 0 16px; }
.footer-note a { color: #6b8aad; text-decoration: none; }
.footer-note a:hover { text-decoration: underline; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.85); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  z-index: 100; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.modal {
  background: #0f1620; border: 1px solid #2a3340; border-radius: 12px;
  max-width: 900px; width: 100%; max-height: 90vh; overflow: hidden;
  display: flex; flex-direction: row; transform: scale(0.96); transition: transform 0.2s;
}
.modal-backdrop.open .modal { transform: scale(1); }
.modal-img {
  width: 320px; flex-shrink: 0; background: #000; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.modal-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.modal-body {
  padding: 32px 28px; overflow-y: auto; flex: 1; position: relative;
  display: flex; flex-direction: column; gap: 14px;
}
.modal-close {
  position: absolute; top: 12px; right: 12px;
  width: 32px; height: 32px; border-radius: 50%;
  background: #1b2430; border: 1px solid #2a3340;
  color: #e8eef5; cursor: pointer; display: flex;
  align-items: center; justify-content: center; font-size: 18px; line-height: 1;
}
.modal-close:hover { background: #232d3b; }
.modal-letter { font-size: 72px; font-weight: 300; line-height: 1; color: #e8eef5; letter-spacing: 0.02em; }
.modal-location { font-size: 22px; font-weight: 500; color: #e8eef5; }
.modal-meta { font-size: 13px; color: #8a95a3; line-height: 1.7; }
.modal-meta div { display: flex; gap: 10px; }
.modal-meta span:first-child { color: #6b7685; min-width: 95px; flex-shrink: 0; }
.modal-desc { font-size: 14px; color: #b4bec9; line-height: 1.65; margin-top: 4px; }
.modal-link {
  margin-top: auto; padding-top: 12px;
  color: #6b8aad; font-size: 13px; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
}
.modal-link:hover { color: #8aaed0; }

/* Poster mode */
body.poster-mode .no-poster { display: none; }
body.poster-mode .poster-view { display: flex; }
.poster-view {
  display: none; min-height: 100vh; flex-direction: column;
  padding: 40px 30px; background: #000;
}
.poster-bar {
  display: flex; gap: 10px; justify-content: center; margin-bottom: 30px;
  flex-wrap: wrap; align-items: center;
}
.poster-bar button {
  background: #1b2430; border: 1px solid #2a3340; color: #e8eef5;
  padding: 10px 20px; border-radius: 8px; font-size: 13px;
  font-weight: 500; cursor: pointer; transition: all 0.15s;
}
.poster-bar button:hover { background: #232d3b; }
.poster-bar button.primary { background: #2563eb; border-color: #2563eb; }
.poster-bar button:disabled { opacity: 0.5; cursor: wait; }
.poster-status {
  min-height: 18px; color: #8a95a3; font-size: 12px;
  flex-basis: 100%; text-align: center;
}
.poster-status.error { color: #f8b4b4; }
.poster-canvas {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 32px; max-width: 1600px;
  margin: 0 auto; width: 100%;
}
.poster-letters { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.poster-letters .p-letter { width: 180px; aspect-ratio: 5/12; overflow: hidden; border-radius: 2px; background: #000; }
.poster-letters .p-letter.space { width: 40px; background: transparent; }
.poster-letters .p-letter img { width: 100%; height: 100%; object-fit: cover; display: block; }
.poster-letters .p-letter .ph {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: 80px; color: #3a4556; background: linear-gradient(135deg, #0a0e14, #1b2430);
}
.poster-title {
  text-align: center; color: #fff; font-family: Georgia, "Times New Roman", serif;
  letter-spacing: 0.1em; line-height: 1.2;
}
.poster-title .p-name { font-size: 42px; font-weight: 400; text-transform: uppercase; letter-spacing: 0.3em; margin-bottom: 14px; }
.poster-title .p-sub { font-size: 14px; color: #8a95a3; letter-spacing: 0.25em; text-transform: uppercase; font-family: -apple-system, sans-serif; }
.poster-title .p-tag { font-size: 11px; color: #4a5463; letter-spacing: 0.15em; margin-top: 8px; font-family: -apple-system, sans-serif; }

@media (max-width: 700px) {
  .modal { flex-direction: column; max-height: 92vh; }
  .modal-img { width: 100%; height: 220px; }
  .modal-body { padding: 20px 18px; }
  .modal-letter { font-size: 48px; }
  .modal-location { font-size: 18px; }
  .letter { width: 108px; }
  .letter.space { width: 24px; }
  header h1 { font-size: 24px; }
  .letter .letter-label { font-size: 12px; }
  .letter .location { font-size: 10px; }
  .letter .placeholder { font-size: 56px; }
  .poster-letters .p-letter { width: 100px; }
  .poster-letters .p-letter.space { width: 24px; }
  .poster-title .p-name { font-size: 24px; letter-spacing: 0.2em; }
  .poster-title .p-sub { font-size: 11px; }
}

@media print {
  body { background: #000 !important; }
  .no-poster, .poster-bar, .modal-backdrop { display: none !important; }
  .poster-view { display: flex !important; padding: 20px; }
  .poster-letters .p-letter { width: 120px; }
  @page { size: landscape; margin: 10mm; }
}
