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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #fff;
  color: #1a1a2e;
  min-height: 100vh;
  overflow: hidden;
}

.screen { min-height: 100vh; }
.hidden { display: none !important; }

.lang-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 40px 20px;
  background: #fff;
}

.logo { margin-bottom: 16px; }

.lang-container h1 {
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -1px;
  margin-bottom: 4px;
}

.subtitle { color: #999; font-size: 1.1rem; margin-bottom: 40px; }

.lang-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  max-width: 700px;
  width: 100%;
}

.lang-card {
  background: #fff;
  border: 2px solid #eee;
  border-radius: 12px;
  padding: 16px 20px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
}

.lang-card:hover {
  border-color: #1a1a2e;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}

.lang-card .lang-name { font-weight: 600; font-size: 1rem; margin-bottom: 2px; }
.lang-card .lang-code { color: #aaa; font-size: 0.8rem; text-transform: uppercase; }

#library-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
}

#hud {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 10;
  pointer-events: none;
}

#hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  pointer-events: auto;
}

.hud-left { display: flex; align-items: center; gap: 10px; color: #1a1a2e; }
.hud-title { font-weight: 700; font-size: 1.1rem; color: #1a1a2e; }

.hud-center { flex: 1; display: flex; justify-content: center; pointer-events: auto; }

#search-container {
  position: relative;
  width: 300px;
  max-width: 40vw;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(0,0,0,0.3);
  pointer-events: none;
}

#search-input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 8px;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(8px);
  font-size: 0.85rem;
  color: #1a1a2e;
  outline: none;
  font-family: inherit;
}

#search-input:focus {
  border-color: rgba(0,0,0,0.2);
  background: rgba(255,255,255,0.95);
}

#search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 8px;
  overflow: hidden;
  display: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}

.search-item {
  padding: 10px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  border-bottom: 1px solid rgba(0,0,0,0.04);
  color: #1a1a2e;
}

.search-item:last-child { border-bottom: none; }

.search-item:hover { background: rgba(0,0,0,0.03); }

.hud-right { display: flex; align-items: center; gap: 14px; }
  border-radius: 6px;
  backdrop-filter: blur(8px);
  border: 1px solid rgba(0,0,0,0.08);
}

.hud-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.8);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: #1a1a2e;
  pointer-events: auto;
  transition: all 0.15s;
}

.hud-btn:hover { background: rgba(255,255,255,0.95); }

#hud-crosshair {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: rgba(0,0,0,0.25);
  font-size: 24px;
  font-weight: 300;
  display: none;
  transition: color 0.15s, transform 0.15s;
}

#hud-crosshair.hud-crosshair-book {
  color: rgba(0,0,0,0.7);
  transform: translate(-50%, -50%) scale(1.4);
}

#hud-hint {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(0,0,0,0.45);
  font-size: 0.85rem;
  background: rgba(255,255,255,0.85);
  padding: 8px 20px;
  border-radius: 8px;
  backdrop-filter: blur(8px);
  pointer-events: auto;
  border: 1px solid rgba(0,0,0,0.06);
}

#wiki-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 50;
  background: rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}

#wiki-overlay.hidden { display: none !important; }

#wiki-book {
  perspective: 1200px;
  animation: bookAppear 0.4s ease-out;
}

@keyframes bookAppear {
  0% { opacity: 0; transform: scale(0.3) translateY(40px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

#wiki-book-cover {
  display: flex;
  width: 70vw;
  max-width: 900px;
  height: 75vh;
  max-height: 700px;
  transform: rotateY(-2deg);
  transform-style: preserve-3d;
}

#wiki-book-spine {
  width: 20px;
  background: #e0e0e0;
  border-radius: 4px 0 0 4px;
  box-shadow: inset -2px 0 4px rgba(0,0,0,0.08);
  flex-shrink: 0;
}

#wiki-book-page {
  flex: 1;
  background: #fff;
  border-radius: 0 6px 6px 0;
  box-shadow: 4px 4px 20px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.04);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#wiki-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #fafafa;
  border-bottom: 1px solid #eee;
  flex-shrink: 0;
}

#wiki-title {
  font-weight: 600;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  margin-right: 12px;
}

#wiki-close {
  background: none;
  border: none;
  cursor: pointer;
  color: #1a1a2e;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  flex-shrink: 0;
  transition: background 0.15s;
}

#wiki-close:hover { background: #f0f0f0; }

#wiki-iframe { flex: 1; border: none; width: 100%; }

#loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 100;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.loading-logo { animation: pulse 1.5s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.95); }
}

.loading-text { color: #1a1a2e; font-size: 1rem; font-weight: 500; }

.loading-bar {
  width: 200px;
  height: 4px;
  background: #eee;
  border-radius: 2px;
  overflow: hidden;
}

.loading-fill {
  height: 100%;
  width: 0%;
  background: #1a1a2e;
  border-radius: 2px;
  transition: width 0.3s;
}

.book-label {
  position: absolute;
  background: rgba(255,255,255,0.92);
  color: #1a1a2e;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.8rem;
  pointer-events: none;
  white-space: nowrap;
  backdrop-filter: blur(4px);
  z-index: 15;
  display: none;
  border: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

#settings-panel {
  position: absolute;
  top: 56px;
  right: 20px;
  width: 280px;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  pointer-events: auto;
  z-index: 20;
  overflow: hidden;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  font-weight: 600;
  font-size: 0.9rem;
}

.settings-header button {
  background: none;
  border: none;
  cursor: pointer;
  color: #1a1a2e;
  padding: 2px;
  border-radius: 4px;
  display: flex;
}

.settings-header button:hover { background: rgba(0,0,0,0.05); }

.settings-body { padding: 12px 16px; display: flex; flex-direction: column; gap: 14px; }

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: #1a1a2e;
}

.settings-slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-val {
  font-size: 0.8rem;
  font-weight: 600;
  min-width: 28px;
  text-align: right;
  color: #666;
}

.settings-slider-row input[type="range"] {
  width: 100px;
  accent-color: #1a1a2e;
}

.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  display: inline-block;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #ccc;
  border-radius: 22px;
  transition: 0.2s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}

.toggle input:checked + .toggle-slider { background: #1a1a2e; }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

@media (max-width: 600px) {
  .hud-title { display: none; }
  .lang-grid { grid-template-columns: repeat(2, 1fr); }
  .lang-container h1 { font-size: 2rem; }
  #hud-hint { font-size: 0.75rem; padding: 6px 14px; }
}
