/* ============================================
   Comic Panel System
   ============================================ */

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

body.comic-body {
  background: #f0f0f0;
  font-family: 'Crimson Text', serif;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 100vh;
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 24px 0;
}

/* --- Main Layout: Inventory + Comic --- */

#comic-container {
  display: flex;
  gap: 16px;
  max-width: 1300px;
  width: 100%;
  align-items: flex-start;
  padding: 0 16px;
}

/* --- Inventory Sidebar --- */

.inventory-sidebar {
  width: 200px;
  min-width: 200px;
  background: #fff;
  border: 3px solid #000;
  border-radius: 4px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  position: sticky;
  top: 70px;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  z-index: 40;
}

.inventory-header {
  background: #222;
  color: #fff;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 2px;
  padding: 10px 12px;
  text-align: center;
  border-bottom: 2px solid #000;
}

.inventory-list {
  padding: 4px;
}

.inventory-empty {
  color: #999;
  font-size: 13px;
  font-style: italic;
  text-align: center;
  padding: 16px 8px;
}

.inventory-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-bottom: 1px solid #eee;
  transition: background 0.15s;
}

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

.inventory-item:hover {
  background: #f8f8f8;
}

.inventory-item img {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid #ddd;
}

.inventory-item-name {
  flex: 1;
  font-size: 13px;
  color: #333;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inventory-item-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.inv-btn {
  width: 28px;
  height: 28px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #f8f8f8;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  padding: 0;
}

.inv-btn:hover {
  background: #e8f4fd;
  border-color: #b3d9f2;
}

.inv-btn.inv-hand.selected {
  background: #d4edda;
  border-color: #28a745;
  box-shadow: 0 0 6px rgba(40,167,69,0.4);
}

/* --- Comic Grid --- */

.comic-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  flex: 1;
  min-width: 0;
  padding: 12px;
  background: #fff;
  border: 3px solid #000;
  border-radius: 4px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.comic-panel {
  position: relative;
  border: 3px solid #000;
  outline: 2px solid #fff;
  outline-offset: -5px;
  background: #fff;
  overflow: hidden;
  min-height: 200px;
  opacity: 0.4;
  transition: opacity 0.4s ease;
}

.comic-panel.active,
.comic-panel.completed {
  opacity: 1;
}

.panel-w1 { grid-column: span 1; }
.panel-w2 { grid-column: span 2; }
.panel-w3 { grid-column: span 3; }
.panel-w4 { grid-column: span 4; }

/* --- Panel Image --- */

.panel-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: filter 0.3s ease;
}

.panel-image.image-loading {
  animation: shimmer-load 1.5s ease-in-out infinite;
}

@keyframes shimmer-load {
  0%, 100% { filter: brightness(0.4); }
  50% { filter: brightness(0.6); }
}

/* --- Speech Bubbles --- */

.bubbles-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

.speech-bubble {
  position: absolute;
  background: #fff;
  color: #111;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 14px;
  line-height: 1.4;
  max-width: 70%;
  min-width: 60px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  pointer-events: auto;
  cursor: pointer;
  z-index: 2;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.speech-bubble.hidden {
  opacity: 0;
  transform: scale(0.8);
  pointer-events: none;
}

.speech-bubble.bubble-faded {
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.speech-bubble::after {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
}

/* --- Bubble Positions (wide panels) --- */

.bubble-top-left {
  top: 8%;
  left: 5%;
  max-width: 42%;
  background: #e8f4fd;
  border: 2px solid #b3d9f2;
}

.bubble-top-left::after {
  bottom: -10px;
  left: 20px;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 10px solid #e8f4fd;
}

.bubble-top-right {
  top: 8%;
  right: 5%;
  max-width: 42%;
  background: #fde8e8;
  border: 2px solid #f2b3b3;
}

.bubble-top-right::after {
  bottom: -10px;
  right: 20px;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 10px solid #fde8e8;
}

.bubble-bottom {
  bottom: 8%;
  left: 50%;
  transform: translateX(-50%);
  max-width: 80%;
  background: #fffde8;
  border: 2px solid #f2ecb3;
  font-style: italic;
  text-align: center;
  border-radius: 6px;
}

.bubble-bottom::after {
  display: none;
}

.bubble-bottom.hidden {
  transform: translateX(-50%) scale(0.8);
}

/* --- Spieler-Antwort Bubble (mittig rechts) --- */

.bubble-player {
  top: 50%;
  right: 5%;
  transform: translateY(-50%);
  max-width: 40%;
  background: #e8fde8;
  border: 2px solid #82c782;
  font-weight: 500;
}

.bubble-player.hidden {
  transform: translateY(-50%) scale(0.8);
}

.bubble-player::after {
  top: 50%;
  right: -10px;
  margin-top: -6px;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 10px solid #e8fde8;
}

.bubble-player-stacked {
  background: #e8fde8;
  border: 2px solid #82c782;
  font-weight: 500;
}

.bubble-player-stacked::after {
  bottom: -10px;
  right: 15px;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 10px solid #e8fde8;
}

/* --- Bubble Positions (narrow panels, stacked) --- */

.bubble-stacked {
  position: relative;
  margin: 6px 8px;
  max-width: calc(100% - 16px);
  width: calc(100% - 16px);
}

.bubble-narrator {
  background: #fffde8;
  border: 2px solid #f2ecb3;
  font-style: italic;
  border-radius: 6px;
}

.bubble-narrator::after {
  display: none;
}

.bubble-person-left {
  background: #e8f4fd;
  border: 2px solid #b3d9f2;
}

.bubble-person-left::after {
  top: -10px;
  left: 15px;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 10px solid #e8f4fd;
}

.bubble-person-right {
  background: #fde8e8;
  border: 2px solid #f2b3b3;
}

.bubble-person-right::after {
  bottom: -10px;
  right: 15px;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 10px solid #fde8e8;
}

.comic-panel.panel-w1 .bubbles-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 4px 0;
}

/* --- Bubble Text --- */

.bubble-text {
  display: inline;
}

.bubble-label {
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: block;
  margin-bottom: 3px;
  opacity: 0.6;
}

/* --- Dialog Choices --- */

.dialog-choices {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: #fff;
  border: 2px solid #000;
  border-radius: 8px;
  padding: 12px;
  min-width: 180px;
  max-width: 60%;
  z-index: 20;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  animation: choices-slide-in 0.3s ease;
}

.panel-w1 .dialog-choices {
  right: 5px;
  left: 5px;
  max-width: calc(100% - 10px);
  min-width: 0;
  top: auto;
  bottom: 10px;
  transform: none;
}

.dialog-choices-title {
  font-family: 'Courier New', monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #888;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid #eee;
}

.dialog-choice-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: #f8f8f8;
  color: #222;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 6px;
  font-family: 'Crimson Text', serif;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.dialog-choice-btn:last-child {
  margin-bottom: 0;
}

.dialog-choice-btn:hover {
  background: #e8f4fd;
  border-color: #b3d9f2;
  transform: translateX(3px);
}

.dialog-choices-fade-out {
  animation: choices-fade-out 0.3s ease forwards;
}

@keyframes choices-slide-in {
  from { opacity: 0; transform: translateY(-50%) translateX(10px); }
  to { opacity: 1; transform: translateY(-50%); }
}

@keyframes choices-fade-out {
  to { opacity: 0; transform: translateY(-50%) translateX(10px); }
}

/* --- Item Markers in Panels --- */

.item-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  cursor: pointer;
  z-index: 5;
  text-align: center;
  transition: transform 0.2s ease, filter 0.2s;
}

.item-marker:hover {
  transform: translate(-50%, -50%) scale(1.15);
  filter: drop-shadow(0 0 8px rgba(212,165,116,0.8));
}

.item-marker img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 4px;
  border: 2px solid #000;
  outline: 1px solid #fff;
  outline-offset: -3px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.item-marker-label {
  display: block;
  font-size: 10px;
  font-family: 'Courier New', monospace;
  color: #fff;
  background: rgba(0,0,0,0.7);
  padding: 2px 6px;
  border-radius: 3px;
  margin-top: 2px;
  white-space: nowrap;
}

/* Interactable (not pickupable) items */
.item-marker.interactable img {
  border-color: rgba(212,165,116,0.8);
}

/* Use-mode: highlight interactables */
body.use-mode .item-marker.interactable {
  animation: use-target-pulse 1s ease-in-out infinite;
}

body.use-mode .comic-panel {
  cursor: crosshair;
}

@keyframes use-target-pulse {
  0%, 100% { filter: drop-shadow(0 0 4px rgba(40,167,69,0.4)); }
  50% { filter: drop-shadow(0 0 12px rgba(40,167,69,0.9)); }
}

/* Pickup animation */
.item-marker.pickup-anim {
  animation: item-pickup 0.5s ease forwards;
  pointer-events: none;
}

@keyframes item-reveal {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.3); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes item-pickup {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  50% { transform: translate(-50%, -80%) scale(1.3); opacity: 0.8; }
  100% { transform: translate(-150%, -200%) scale(0.3); opacity: 0; }
}

/* --- Detail View (Eye/Examine) --- */

.detail-view-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: detail-fade-in 0.3s ease;
}

.detail-view-panel {
  position: relative;
  width: 700px;
  max-width: 90vw;
  height: 450px;
  max-height: 80vh;
  background: #fff;
  border: 4px solid #000;
  outline: 3px solid #fff;
  outline-offset: -7px;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
}

.detail-view-panel .panel-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail-back-arrow {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  z-index: 110;
  transition: background 0.2s, transform 0.2s;
}

.detail-back-arrow:hover {
  background: rgba(212,165,116,0.9);
  transform: scale(1.1);
}

.detail-view-fade-out {
  animation: detail-fade-out 0.3s ease forwards;
}

@keyframes detail-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes detail-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* Use-mode feedback toast */
.use-mode-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #222;
  color: #fff;
  padding: 8px 20px;
  border-radius: 20px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  z-index: 200;
  animation: toast-in 0.3s ease;
}

.use-mode-toast.toast-error {
  background: #c0392b;
}

.use-mode-toast.toast-out {
  animation: toast-out 0.3s ease forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%); }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateX(-50%) translateY(10px); }
}

/* --- Panel Arrow (next panel) --- */

.panel-arrow {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  z-index: 10;
  pointer-events: auto;
  transition: background 0.2s, transform 0.2s;
  animation: pulse-arrow 1.5s ease-in-out infinite;
}

.panel-arrow:hover {
  background: rgba(212, 165, 116, 0.9);
  transform: scale(1.15);
}

.panel-arrow.hidden {
  display: none;
}

@keyframes pulse-arrow {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* --- Next Page Arrow (gruener Pfeil) --- */

.next-page-arrow {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  background: #28a745;
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  z-index: 10;
  pointer-events: auto;
  transition: background 0.2s, transform 0.2s;
  animation: pulse-next-page 1.5s ease-in-out infinite;
  box-shadow: 0 2px 8px rgba(40, 167, 69, 0.5);
}

.next-page-arrow:hover {
  background: #218838;
  transform: scale(1.2);
  box-shadow: 0 2px 12px rgba(40, 167, 69, 0.7);
}

@keyframes pulse-next-page {
  0%, 100% { transform: scale(1); box-shadow: 0 2px 8px rgba(40,167,69,0.5); }
  50% { transform: scale(1.1); box-shadow: 0 2px 14px rgba(40,167,69,0.7); }
}

/* --- Ende-Marker (Button) --- */

.end-marker {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0,0,0,0.6);
  color: #888;
  padding: 4px 14px;
  border-radius: 12px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  z-index: 10;
}

.end-marker-btn {
  cursor: pointer;
  background: #d4a574;
  color: #000;
  font-weight: bold;
  padding: 6px 18px;
  font-size: 14px;
  transition: background 0.2s, transform 0.2s;
  animation: pulse-arrow 1.5s ease-in-out infinite;
}

.end-marker-btn:hover {
  background: #e8c89e;
  transform: scale(1.1);
}

/* --- Ende-Overlay --- */

.end-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: detail-fade-in 0.3s ease;
}

.end-overlay-fade-out {
  animation: detail-fade-out 0.3s ease forwards;
}

.end-overlay-box {
  background: #fff;
  border: 3px solid #000;
  border-radius: 8px;
  padding: 32px;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
  text-align: center;
}

.end-overlay-title {
  font-family: 'Crimson Text', serif;
  font-size: 24px;
  color: #222;
  margin-bottom: 8px;
}

.end-overlay-subtitle {
  color: #888;
  font-size: 14px;
  margin-bottom: 20px;
  font-family: 'Courier New', monospace;
}

.end-overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.end-overlay-btn {
  display: block;
  width: 100%;
  padding: 12px 16px;
  background: #f8f8f8;
  color: #222;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-family: 'Crimson Text', serif;
  font-size: 15px;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}

.end-overlay-btn:hover {
  background: #e8f4fd;
  border-color: #b3d9f2;
  transform: translateX(3px);
}

.end-overlay-story-btn {
  background: #f0f8f0;
  border-color: #c3e6c3;
}

.end-overlay-story-btn:hover {
  background: #d4edda;
  border-color: #28a745;
}

.end-overlay-stories {
  border-top: 1px solid #eee;
  padding-top: 16px;
}

.end-overlay-stories-title {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #888;
  margin-bottom: 10px;
}

.end-overlay-loading,
.end-overlay-hint {
  color: #999;
  font-size: 13px;
  font-style: italic;
}

/* --- Storyflow Choice Buttons --- */

.storyflow-choices {
  grid-column: 1 / -1;
  background: #fff;
  border: 2px solid #000;
  border-radius: 4px;
  padding: 20px 24px;
  text-align: center;
  animation: choices-slide-in 0.3s ease;
}

.storyflow-choices-title {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #888;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid #eee;
}

.storyflow-choices-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 400px;
  margin: 0 auto;
}

.storyflow-choice-btn {
  display: block;
  width: 100%;
  padding: 12px 16px;
  background: #f8f8f8;
  color: #222;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-family: 'Crimson Text', serif;
  font-size: 15px;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}

.storyflow-choice-btn:hover {
  background: #e8f4fd;
  border-color: #b3d9f2;
  transform: translateX(3px);
}

.storyflow-choice-locked {
  opacity: 0.5;
  cursor: not-allowed;
  background: #f0f0f0;
  color: #999;
  border-color: #ddd;
}

.storyflow-choice-locked:hover {
  background: #f0f0f0;
  border-color: #ddd;
  transform: none;
}

/* --- Mobile: Inventar einklappbar --- */

@media (max-width: 768px) {
  #comic-container {
    flex-direction: column;
  }

  .inventory-sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    width: 100%;
    min-width: 0;
    max-height: 50vh;
    z-index: 60;
    border-radius: 12px 12px 0 0;
    border-bottom: none;
    transform: translateY(calc(100% - 42px));
    transition: transform 0.3s ease;
  }

  .inventory-sidebar.inventory-open {
    transform: translateY(0);
  }

  .inventory-header {
    cursor: pointer;
    border-radius: 12px 12px 0 0;
    position: relative;
  }

  .inventory-header::after {
    content: '\25B2';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 10px;
  }

  .inventory-sidebar.inventory-open .inventory-header::after {
    content: '\25BC';
  }

  .comic-grid {
    margin-bottom: 50px;
  }
}

/* --- Layout Demo Page --- */

body.demo-body {
  background: #0c1123;
  color: #f5f0e8;
  font-family: 'Courier New', monospace;
  margin: 0;
  padding: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.demo-header {
  padding: 16px 24px;
  background: #151a30;
  border-bottom: 2px solid #2a2f45;
  flex-shrink: 0;
}

.demo-header h1 {
  font-size: 20px;
  color: #d4a574;
  margin-bottom: 12px;
}

.layout-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.layout-btn {
  background: #1e2440;
  color: #a09880;
  border: 1px solid #3a3f55;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  transition: all 0.2s;
}

.layout-btn:hover {
  background: #2a3050;
  color: #d4a574;
  border-color: #d4a574;
}

.layout-btn.active {
  background: #d4a574;
  color: #0c1123;
  border-color: #d4a574;
  font-weight: bold;
}

.demo-iframe-container {
  flex: 1;
  padding: 8px;
  min-height: 0;
}

.demo-iframe-container iframe {
  width: 100%;
  height: 100%;
  border: 2px solid #2a2f45;
  border-radius: 8px;
  background: #f0f0f0;
}

.back-link {
  color: #a09880;
  text-decoration: none;
  font-size: 13px;
  margin-right: 16px;
}

.back-link:hover {
  color: #d4a574;
}

.demo-top-bar {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}
