/* ============================================================
   DUNGEON MASTER - Dark Fantasy Theme
   ============================================================ */

:root {
  --bg: #0a0e17;
  --bg-2: #111827;
  --bg-3: #1a2233;
  --bg-card: #1e293b;
  --border: #2a3a5c;
  --text: #e2e8f0;
  --text-dim: #8892a4;
  --text-muted: #5a6478;
  --accent: #f59e0b;
  --accent-dim: #92400e;
  --hp: #ef4444;
  --mp: #3b82f6;
  --xp: #8b5cf6;
  --success: #22c55e;
  --danger: #ef4444;
  --gold: #fbbf24;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
}

/* ============================================================
   LAYOUT
   ============================================================ */

#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

/* Sidebar */
.sidebar {
  width: 220px;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-brand {
  padding: 1.5rem 1rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand .mdi-dice-d20 {
  font-size: 2rem;
  color: var(--accent);
}

.sidebar-brand h2 {
  font-size: 1.1rem;
  margin-top: 0.3rem;
  color: var(--text);
  line-height: 1.2;
}

.sidebar-nav {
  flex: 1;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-item {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.95rem;
  text-align: left;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.nav-item:hover {
  background: var(--bg-3);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.nav-item .mdi {
  font-size: 1.2rem;
}

.sidebar-footer {
  padding: 1rem;
  text-align: center;
  border-top: 1px solid var(--border);
}

#dice-anim {
  font-size: 1.5rem;
  color: var(--text-muted);
  animation: pulse 3s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* Main */
.main-content {
  flex: 1;
  overflow-y: auto;
  position: relative;
  min-height: 0;
}

.view {
  display: none;
  height: 100%;
}

.view.active {
  display: flex;
}

/* ============================================================
   START SCREEN
   ============================================================ */

.start-screen {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: radial-gradient(ellipse at center, #1a2233 0%, #0a0e17 70%);
}

.start-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  max-width: 500px;
  width: 100%;
  box-shadow: var(--shadow);
}

.start-icon {
  font-size: 3rem;
  text-align: center;
  margin-bottom: 0.5rem;
}

.start-card h1 {
  text-align: center;
  color: var(--accent);
  font-size: 1.8rem;
  margin-bottom: 0.25rem;
}

.subtitle {
  text-align: center;
  color: var(--text-dim);
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

.form-group {
  margin-bottom: 1.2rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.7rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.form-group textarea {
  resize: vertical;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #d97706);
  color: #000;
  border: none;
  padding: 0.7rem 1.5rem;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.btn-large {
  width: 100%;
  justify-content: center;
  padding: 1rem;
  font-size: 1.1rem;
}

.session-list {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.session-list h3 {
  color: var(--text-dim);
  margin-bottom: 0.8rem;
}

.session-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: background 0.2s;
}

.session-item:hover {
  background: var(--bg-3);
}

/* ============================================================
   GAME VIEW
   ============================================================ */

.game-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Scene Image */
.scene-image {
  height: 200px;
  min-height: 200px;
  background: var(--bg-2);
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}

.scene-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scene-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 0.5rem;
}

.scene-placeholder .mdi {
  font-size: 3rem;
}

/* Status Bar */
.status-bar {
  display: flex;
  gap: 0;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  padding: 0.4rem 0.8rem;
  flex-shrink: 0;
}

.stat {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  border-right: 1px solid var(--border);
}

.stat:last-child { border-right: none; }

.stat .mdi { font-size: 1rem; }

.stat .mdi-heart { color: var(--hp); }
.stat .mdi-star-four-points { color: var(--mp); }
.stat .mdi-arrow-up-bold-circle { color: var(--xp); }
.stat .mdi-map-marker { color: var(--accent); }
.stat .mdi-counter { color: var(--text-dim); }

/* Story Area */
.story-area {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.5rem;
  background: var(--bg);
}

.story-content {
  max-width: 700px;
  margin: 0 auto;
  line-height: 1.7;
}

.story-content p {
  margin-bottom: 0.8rem;
}

.story-content .gm-text {
  font-size: 1.05rem;
  color: var(--text);
}

.story-content .gm-text em {
  color: var(--accent);
  font-style: italic;
}

.story-content .npc-dialog {
  color: var(--gold);
  font-style: italic;
  padding: 0.3rem 0.8rem;
  border-left: 3px solid var(--gold);
  margin: 0.5rem 0;
}

.story-content .player-action {
  color: var(--text-dim);
  font-size: 0.9rem;
  padding: 0.3rem 0.8rem;
  border-left: 3px solid var(--text-muted);
  margin: 0.5rem 0;
}

.story-content .dice-result-text {
  color: var(--accent);
  font-weight: bold;
  padding: 0.3rem 0;
}

.story-entry {
  margin-bottom: 1rem;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Quick Actions */
.quick-actions {
  display: flex;
  gap: 0.4rem;
  padding: 0.5rem 1.5rem;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.quick-actions button {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.quick-actions button:hover {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
}

/* Options */
.options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 1.5rem;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.option-btn {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.option-btn:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* Action Input */
.action-area {
  flex-shrink: 0;
}

.action-input {
  display: flex;
  gap: 0.5rem;
  padding: 0.8rem 1.5rem;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
}

.action-input input {
  flex: 1;
  padding: 0.7rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
}

.action-input input:focus {
  outline: none;
  border-color: var(--accent);
}

.action-input input::placeholder {
  color: var(--text-muted);
}

.action-input button {
  background: var(--accent);
  border: none;
  color: #000;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.action-input button:hover {
  background: #d97706;
}

/* ============================================================
   INVENTORY / CHARACTER PANELS
   ============================================================ */

.panel {
  padding: 2rem;
  width: 100%;
  max-width: 700px;
  margin: 0 auto;
}

.panel h2 {
  color: var(--accent);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.7rem;
}

.item-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem;
  text-align: center;
}

.item-card .item-icon {
  font-size: 1.5rem;
  margin-bottom: 0.3rem;
}

.item-card .item-name {
  font-size: 0.9rem;
  font-weight: 600;
}

.item-card .item-qty {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.item-card .item-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

.skills-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.5rem;
}

.skill-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.7rem;
}

.skill-card .skill-name {
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
}

.skill-card .skill-value {
  color: var(--accent);
  font-weight: bold;
}

.skill-card .skill-bar {
  height: 4px;
  background: var(--bg);
  border-radius: 2px;
  margin-top: 0.3rem;
  overflow: hidden;
}

.skill-card .skill-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}

/* Character Sheet */
.char-sheet {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.char-sheet .sheet-row {
  display: flex;
  justify-content: space-between;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border);
}

.char-sheet .sheet-row:last-child {
  border-bottom: none;
}

.char-sheet .sheet-label {
  color: var(--text-dim);
}

.char-sheet .sheet-value {
  font-weight: 600;
}

/* ============================================================
   DICE MODAL
   ============================================================ */

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  text-align: center;
  min-width: 250px;
  box-shadow: var(--shadow);
}

.dice-icon {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.dice-number {
  font-size: 4rem;
  font-weight: bold;
  color: var(--accent);
  animation: diceRoll 0.5s ease;
}

@keyframes diceRoll {
  0% { transform: rotate(-180deg) scale(0); opacity: 0; }
  100% { transform: rotate(0) scale(1); opacity: 1; }
}

.dice-label {
  font-size: 1.1rem;
  color: var(--text-dim);
  margin: 0.5rem 0 1.5rem;
}

/* ============================================================
   TYPING INDICATOR
   ============================================================ */

.typing-indicator {
  display: flex;
  gap: 0.3rem;
  align-items: center;
  padding: 0.5rem 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.6); }
  40% { transform: scale(1); }
}

/* ============================================================
   GLOBAL OVERFLOW PROTECTION
   ============================================================ */

* {
  word-break: break-word;
  overflow-wrap: break-word;
  -webkit-hyphens: auto;
  hyphens: auto;
}

img, video, canvas, svg {
  max-width: 100%;
  height: auto;
}

/* ============================================================
   RESPONSIVE – SMARTPHONE FIRST
   ============================================================ */

/* Phone (< 600px) */
@media (max-width: 600px) {
  /* ── Layout: Sidebar wird Bottom-Nav ── */
  #app {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    border-right: none;
    border-top: 1px solid var(--border);
    order: 2;
    flex-shrink: 0;
  }

  .sidebar-brand {
    display: none;
  }

  .sidebar-nav {
    flex-direction: row;
    justify-content: space-around;
    padding: 0.25rem;
  }

  .nav-item {
    flex: 1;
    justify-content: center;
    padding: 0.5rem 0.25rem;
    font-size: 0.7rem;
    border-radius: 6px;
  }

  .nav-item span:not(.mdi) {
    display: none;
  }

  .nav-item .mdi {
    font-size: 1.3rem;
  }

  .sidebar-footer {
    display: none;
  }

  .main-content {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
  }

  /* ── Scene ── */
  .scene-image {
    height: 130px;
    min-height: 130px;
  }

  .scene-placeholder .mdi {
    font-size: 2rem;
  }
  .scene-placeholder p {
    font-size: 0.7rem !important;
  }

  /* ── Status Bar: kompakt ── */
  .status-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.3rem 0.4rem;
    gap: 0;
    scrollbar-width: none;
  }
  .status-bar::-webkit-scrollbar { display: none; }

  .stat {
    flex-shrink: 0;
    padding: 0.2rem 0.4rem;
    font-size: 0.7rem;
    border-right: 1px solid var(--border);
  }
  .stat:last-child { border-right: none; }

  .stat .mdi { font-size: 0.85rem; }

  /* ── Story Area ── */
  .story-area {
    padding: 0.5rem 0.75rem;
    -webkit-overflow-scrolling: touch;
  }
  
  .game-container {
    height: 100%;
    min-height: 0;
  }

  .story-content {
    max-width: 100%;
    line-height: 1.5;
  }

  .story-content .gm-text {
    font-size: 0.95rem;
  }

  .story-content p {
    margin-bottom: 0.5rem;
  }

  .story-content .npc-dialog {
    padding: 0.3rem 0.5rem;
    margin: 0.3rem 0;
    font-size: 0.9rem;
  }

  .story-content .player-action {
    padding: 0.2rem 0.5rem;
    margin: 0.3rem 0;
    font-size: 0.85rem;
  }

  .story-entry {
    margin-bottom: 0.6rem;
  }

  /* ── Quick Actions ── */
  .quick-actions {
    padding: 0.4rem 0.5rem;
    gap: 0.3rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .quick-actions::-webkit-scrollbar { display: none; }

  .quick-actions button {
    width: 36px;
    min-width: 36px;
    height: 36px;
    font-size: 1rem;
  }

  /* ── Options ── */
  .options {
    padding: 0.4rem 0.5rem;
    gap: 0.35rem;
    flex-direction: column;
  }

  .option-btn {
    width: 100%;
    text-align: left;
    padding: 0.6rem 0.8rem;
    font-size: 0.85rem;
    border-radius: 8px;
    white-space: normal;
    word-break: break-word;
    line-height: 1.3;
  }

  /* ── Action Input ── */
  .action-input {
    padding: 0.4rem 0.5rem;
    gap: 0.4rem;
  }

  .action-input input {
    padding: 0.6rem 0.7rem;
    font-size: 0.9rem;
    min-width: 0;
  }

  .action-input button {
    width: 40px;
    min-width: 40px;
    height: 40px;
    font-size: 1.1rem;
  }

  /* ── Panels ── */
  .panel {
    padding: 1rem;
  }

  .panel h2 {
    font-size: 1.1rem;
  }

  .item-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }

  .item-card {
    padding: 0.6rem;
  }

  .item-card .item-name {
    font-size: 0.8rem;
  }

  .skills-grid {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }

  .skill-card {
    padding: 0.5rem;
  }

  .char-sheet {
    padding: 1rem;
  }
  .char-sheet .sheet-row {
    padding: 0.5rem 0;
    font-size: 0.9rem;
  }

  /* ── Dice Modal ── */
  .modal-content {
    padding: 1.5rem;
    min-width: unset;
    width: 85%;
    max-width: 300px;
  }

  .dice-number {
    font-size: 3rem;
  }

  /* ── Start Screen ── */
  .start-screen {
    padding: 1rem;
  }

  .start-card {
    padding: 1.5rem;
  }

  .start-card h1 {
    font-size: 1.4rem;
  }

  .form-group input,
  .form-group select,
  .form-group textarea {
    font-size: 0.9rem;
    padding: 0.6rem 0.8rem;
  }

  .session-item {
    padding: 0.5rem;
    font-size: 0.85rem;
    flex-wrap: wrap;
    gap: 0.3rem;
  }
}

/* Tablet (600-900px) */
@media (min-width: 601px) and (max-width: 900px) {
  .sidebar {
    width: 60px;
  }

  .sidebar-brand h2,
  .nav-item span:not(.mdi) {
    display: none;
  }

  .nav-item {
    justify-content: center;
    padding: 0.7rem;
  }

  .scene-image {
    height: 160px;
    min-height: 160px;
  }

  .story-area {
    padding: 0.8rem 1rem;
  }

  .story-content .gm-text {
    font-size: 1rem;
  }

  .story-content {
    max-width: 100%;
  }

  .option-btn {
    font-size: 0.85rem;
    padding: 0.4rem 0.8rem;
  }

  .status-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .status-bar::-webkit-scrollbar { display: none; }

  .panel {
    padding: 1.5rem;
  }

  .item-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }
}
