/* Cozy Adventures RPG Layout & Theme additions */

:root {
  --chat-bg: var(--color-surface);
  --chat-user-bg: var(--color-surface-container);
  --chat-asst-bg: var(--color-surface-container-low);
  --chat-ooc-bg: rgba(234, 179, 8, 0.08);
  --chat-ooc-border: rgba(234, 179, 8, 0.3);
  --dice-card-bg: var(--color-surface-container-high);
  --dice-border: var(--color-outline-variant);
  --hp-green: #10b981;
  --hp-yellow: #f59e0b;
  --hp-red: #ef4444;
}

body {
  margin: 0;
  padding: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--font-sans, system-ui, -apple-system, sans-serif);
  background-color: var(--color-surface-dim, #121212);
  color: var(--color-on-surface, #e2e8f0);
}

/* Header Tweaks */
.site-header-centered {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1.25rem;
  background-color: var(--color-surface-container-lowest, #1e1e1e);
  border-bottom: 1px solid var(--color-outline-variant, #333);
  height: 60px;
  box-sizing: border-box;
  z-index: 10;
}

.header-leading, .header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.app-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin: 0;
  color: var(--color-primary, #6366f1);
}

.version-badges {
  display: flex;
  gap: 0.35rem;
  margin-top: 2px;
}

.version-badge {
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 9999px;
  background-color: var(--color-surface-container-high, #2d2d2d);
  color: var(--color-on-surface-variant, #94a3b8);
  font-family: monospace;
  font-weight: 600;
}

.version-badge-label {
  color: var(--color-primary, #818cf8);
  font-weight: 700;
  margin-right: 2px;
}

/* Main Split View */
.app-container {
  display: flex;
  flex: 1;
  height: calc(100vh - 60px);
  overflow: hidden;
}

/* Left / Center Story Chat Column */
.story-column {
  flex: 1;
  min-width: 50%;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  position: relative;
  background-color: var(--color-surface, #18181b);
  overflow: hidden;
}

/* Panel Resizer */
.panel-resizer {
  width: 8px;
  background-color: var(--color-surface-container-highest, #2e2e36);
  border-left: 1px solid var(--color-outline-variant, #3f3f46);
  border-right: 1px solid var(--color-outline-variant, #3f3f46);
  cursor: col-resize;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: background-color 0.15s ease;
  z-index: 10;
}

.panel-resizer:hover, .panel-resizer.is-resizing {
  background-color: var(--color-primary, #6366f1);
}

.resizer-handle-line {
  width: 2px;
  height: 36px;
  background-color: var(--color-outline-variant, #71717a);
  border-radius: 9999px;
  pointer-events: none;
}

.panel-resizer:hover .resizer-handle-line, .panel-resizer.is-resizing .resizer-handle-line {
  background-color: #fff;
}

/* Right Side Panel */
.panel-column {
  width: var(--panel-width, 420px);
  min-width: 280px;
  max-width: 50%;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  background-color: var(--color-surface-container-lowest, #1e1e24);
  overflow: hidden;
}

.story-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  scroll-behavior: smooth;
}

/* History Expand Banner */
.history-banner {
  display: flex;
  justify-content: center;
  margin-bottom: 0.5rem;
}

.btn-history-expand {
  background: var(--color-surface-container-high, #27272a);
  border: 1px dashed var(--color-outline-variant, #3f3f46);
  color: var(--color-on-surface-variant, #a1a1aa);
  border-radius: 9999px;
  padding: 0.4rem 1rem;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-history-expand:hover {
  background: var(--color-surface-container-highest, #3f3f46);
  color: var(--color-on-surface, #f4f4f5);
  border-color: var(--color-primary, #6366f1);
}

/* Message Styles */
.msg-card {
  border-radius: 12px;
  padding: 1rem 1.25rem;
  line-height: 1.65;
  font-size: 0.95rem;
  max-width: 90%;
  position: relative;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.msg-assistant {
  align-self: flex-start;
  background-color: var(--chat-asst-bg, #27272a);
  border: 1px solid var(--color-outline-variant, #3f3f46);
  border-left: 4px solid var(--color-primary, #6366f1);
}

.msg-user {
  align-self: flex-end;
  background-color: var(--chat-user-bg, #312e81);
  color: #fff;
  border: 1px solid #4338ca;
}

.msg-user.ooc {
  background-color: var(--chat-ooc-bg);
  border: 1px dashed var(--chat-ooc-border);
  color: #fde047;
}

.msg-system {
  align-self: center;
  background-color: var(--color-surface-container-high, #27272a);
  border: 1px solid var(--dice-border, #52525b);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  max-width: 95%;
}

.msg-header {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--color-on-surface-variant, #a1a1aa);
}

.msg-body {
  white-space: pre-wrap;
  word-break: break-word;
}

/* Dice Roll Cards inside messages */
.mechanics-block {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.dice-result-card {
  background-color: var(--dice-card-bg, #1e1e24);
  border: 1px solid var(--dice-border, #3f3f46);
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
}

.dice-badge {
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  font-family: monospace;
}

.dice-success {
  background-color: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border: 1px solid #059669;
}

.dice-fail {
  background-color: rgba(239, 68, 68, 0.2);
  color: #f87171;
  border: 1px solid #dc2626;
}

/* Chat Input Bar */
.story-input-container {
  flex-shrink: 0;
  padding: 0.75rem 1.25rem;
  background-color: var(--color-surface-container-lowest, #18181b);
  border-top: 1px solid var(--color-outline-variant, #27272a);
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  z-index: 5;
}

.input-box {
  flex: 1;
  position: relative;
}

.chat-textarea {
  width: 100%;
  min-height: 44px;
  max-height: 120px;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--color-outline, #3f3f46);
  background-color: var(--color-surface-container-high, #27272a);
  color: var(--color-on-surface, #f4f4f5);
  font-family: inherit;
  font-size: 0.95rem;
  resize: none;
  box-sizing: border-box;
}

.chat-textarea:focus {
  outline: none;
  border-color: var(--color-primary, #6366f1);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.25);
}

.input-hint {
  font-size: 0.75rem;
  color: var(--color-on-surface-variant, #71717a);
  margin-top: 4px;
}

/* Right Side Panel */
.panel-header {
  padding: 0.5rem;
  border-bottom: 1px solid var(--color-outline-variant, #27272a);
}

.tabs-centered {
  display: flex;
  gap: 0.25rem;
  justify-content: center;
  overflow-x: auto;
}

.tab-btn {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--color-on-surface-variant, #a1a1aa);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.tab-btn:hover {
  background-color: var(--color-surface-container-high, #27272a);
  color: var(--color-on-surface, #f4f4f5);
}

.tab-btn.active {
  background-color: var(--color-primary, #6366f1);
  color: #fff;
}

.panel-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem;
}

/* Character Card */
.char-card {
  background-color: var(--color-surface-container-low, #27272a);
  border: 1px solid var(--color-outline-variant, #3f3f46);
  border-radius: 10px;
  padding: 0.85rem;
  margin-bottom: 1rem;
}

.char-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.char-name {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.char-role-badge {
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  background-color: var(--color-primary-container, #4338ca);
  color: var(--color-on-primary-container, #e0e7ff);
}

.char-meta {
  font-size: 0.78rem;
  color: var(--color-on-surface-variant, #a1a1aa);
  margin-bottom: 0.5rem;
}

/* HP Bar */
.hp-container {
  margin: 0.5rem 0;
}

.hp-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 3px;
}

.hp-track {
  width: 100%;
  height: 8px;
  background-color: #3f3f46;
  border-radius: 9999px;
  overflow: hidden;
}

.hp-fill {
  height: 100%;
  border-radius: 9999px;
  transition: width 0.3s ease, background-color 0.3s ease;
}

/* Quick stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  margin: 0.5rem 0;
  text-align: center;
}

.stat-box {
  background-color: var(--color-surface-container-high, #1e1e24);
  border-radius: 6px;
  padding: 4px 2px;
  font-size: 0.7rem;
}

.stat-name {
  font-weight: 700;
  color: var(--color-on-surface-variant, #71717a);
}

.stat-val {
  font-weight: 600;
  color: var(--color-on-surface, #f4f4f5);
}

/* Spell Slots pills */
.spell-slots {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.4rem;
  font-size: 0.75rem;
}

.slot-circle {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--color-primary, #6366f1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 10px;
}

.slot-circle.filled {
  background-color: var(--color-primary, #6366f1);
  color: white;
}

/* Locations & Nodes */
.location-card {
  background-color: var(--color-surface-container-low, #27272a);
  border: 1px solid var(--color-outline-variant, #3f3f46);
  border-radius: 8px;
  padding: 0.85rem;
  margin-bottom: 0.75rem;
}

.location-title {
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  justify-content: space-between;
}

.danger-badge {
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 700;
}

.danger-Sicuro { background-color: rgba(16, 185, 129, 0.2); color: #34d399; }
.danger-Neutrale { background-color: rgba(59, 130, 246, 0.2); color: #60a5fa; }
.danger-Pericoloso { background-color: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.danger-Ostile { background-color: rgba(239, 68, 68, 0.2); color: #f87171; }

/* Currency Counter */
.currency-bar {
  display: flex;
  gap: 0.75rem;
  background-color: var(--color-surface-container-high, #1e1e24);
  padding: 0.6rem 0.85rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.coin-gp { color: #facc15; }
.coin-sp { color: #cbd5e1; }
.coin-cp { color: #d97706; }

/* Buttons & Controls */
.btn-primary {
  background-color: var(--color-primary, #6366f1);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: opacity 0.15s ease;
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--color-outline-variant, #3f3f46);
  border-radius: 8px;
  padding: 0.45rem;
  cursor: pointer;
  color: var(--color-on-surface, #f4f4f5);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background-color: var(--color-surface-container-high, #27272a);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}

.modal-content {
  background-color: var(--color-surface-container, #27272a);
  border: 1px solid var(--color-outline, #52525b);
  border-radius: 12px;
  width: 90%;
  max-width: 580px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.5rem;
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}

/* Mobile responsive collapse */
@media (max-width: 860px) {
  .app-container {
    flex-direction: column;
  }
  .panel-column {
    width: 100%;
    max-width: 100%;
    height: 40vh;
    border-top: 1px solid var(--color-outline-variant);
  }
}
