/* ==========================================================================
   Pocket Mentor - Warm Editorial Paper & Antique Brass Theme (100dvh Single-Screen)
   Palette: Warm Linen Paper (#F6F3EC), Deep Slate Ink (#1C2430), Antique Brass (#A9814B),
   Earthy Sage (#4B7266), Terracotta Rust (#A6503B), and Warm Cream Line (#E3DDD0).
   Typography: Fraunces (Headings), Inter (Body), IBM Plex Mono (Data & Code).
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  /* Warm Paper & Inks */
  --ink: #1C2430;
  --ink-soft: #2B3542;
  --paper: #F6F3EC;
  --paper-raised: #FFFFFF;
  --brass: #A9814B;
  --brass-soft: #D9C6A0;
  --slate: #5B6472;
  --slate-soft: #889098;
  --sage: #4B7266;
  --rust: #A6503B;
  --line: #E3DDD0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(28,36,48,0.06), 0 8px 24px rgba(28,36,48,0.05);
}

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

html, body {
  height: 100%;
  height: 100dvh;
  background-color: var(--paper);
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden; /* Single-window fit */
}

::selection {
  background: var(--brass-soft);
  color: var(--ink);
}

h1, h2, h3, .font-serif-heading {
  font-family: 'Fraunces', Georgia, serif;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.font-mono-data {
  font-family: 'IBM Plex Mono', monospace;
}

/* ================= APP SHELL (100dvh Laptop/Tablet Viewport) ================= */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  max-width: 100vw;
  overflow: hidden;
}

/* Header */
.app-header {
  height: 64px;
  flex-shrink: 0;
  background: var(--paper-raised);
  border-bottom: 1px solid var(--line);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 50;
}

/* Main Viewport Container */
.app-main {
  flex: 1;
  min-height: 0; /* Crucial for nested scroll */
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.app-main::-webkit-scrollbar {
  width: 6px;
}
.app-main::-webkit-scrollbar-thumb {
  background-color: var(--line);
  border-radius: 9999px;
}

.view-panel {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

/* For Single-Window Chat/Role-Play Views */
.single-window-pane {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 112px);
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.chat-scroll-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

/* ================= HEADER & STATUS LAMP ================= */
.status-lamp {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 9999px;
  background: var(--paper);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: all 0.2s ease;
}
.status-lamp:hover {
  border-color: var(--brass);
}

.lamp-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.lamp-dot.online {
  background-color: #4CAF6D;
  box-shadow: 0 0 6px rgba(76,175,109,0.7);
  animation: connGlow 2.2s infinite ease-in-out;
}
.lamp-dot.offline {
  background-color: #C0473A;
  box-shadow: 0 0 6px rgba(192,71,58,0.5);
}
.lamp-dot.testing {
  background-color: #D8A73D;
  animation: connPulse 1s infinite ease-in-out;
}

@keyframes connPulse { 0%,100%{opacity:0.4;} 50%{opacity:1;} }
@keyframes connGlow { 0%,100%{box-shadow:0 0 4px rgba(76,175,109,0.5);} 50%{box-shadow:0 0 8px rgba(76,175,109,0.9);} }

/* ================= CARDS & SURFACES ================= */
.mentor-card {
  background-color: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.situation-card {
  background-color: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  box-shadow: var(--shadow);
}
.situation-card:hover {
  border-color: var(--brass);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(169, 129, 75, 0.12);
}

/* ================= BUTTONS ================= */
.btn-primary {
  background-color: var(--ink);
  color: var(--paper);
  font-weight: 600;
  font-size: 13.5px;
  padding: 9px 18px;
  border-radius: 8px;
  border: 1px solid var(--ink);
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-primary:hover {
  background-color: var(--ink-soft);
}
.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-brass {
  background-color: var(--brass);
  color: #ffffff;
  font-weight: 600;
  font-size: 13.5px;
  padding: 9px 18px;
  border-radius: 8px;
  border: 1px solid var(--brass);
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-brass:hover {
  background-color: #96703f;
}

.btn-secondary, .btn-ghost {
  background-color: transparent;
  color: var(--slate);
  font-weight: 600;
  font-size: 13.5px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-secondary:hover, .btn-ghost:hover {
  border-color: var(--slate-soft);
  color: var(--ink);
  background-color: var(--paper-raised);
}

.nav-tab {
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  color: var(--slate);
  border-radius: 6px;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.nav-tab:hover {
  color: var(--ink);
  background-color: var(--paper);
}
.nav-tab.active {
  color: var(--ink);
  background-color: var(--paper);
  font-weight: 700;
  border: 1px solid var(--line);
}

.filter-pill {
  padding: 5px 12px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 9999px;
  border: 1px solid var(--line);
  background: var(--paper-raised);
  color: var(--slate);
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.filter-pill:hover {
  color: var(--ink);
  border-color: var(--brass);
}
.filter-pill.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

/* Tactile Mobile Touch Feedback (BL-074) */
.btn-primary, .btn-brass, .btn-ghost, .situation-card, .mentor-card, .mobile-nav-item, .nav-tab {
  -webkit-tap-highlight-color: transparent;
}

.situation-card:active, .mentor-card:active {
  transform: scale(0.985);
  transition: transform 0.08s ease;
}

.btn-primary:active, .btn-brass:active, .btn-ghost:active, .filter-pill:active {
  transform: scale(0.96);
  transition: transform 0.08s ease;
}

/* Hide scrollbar utility */
.no-scrollbar::-webkit-scrollbar {
  display: none;
}
.no-scrollbar {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

/* ================= FORMS & INPUTS ================= */
.form-input, .form-textarea, .form-select {
  width: 100%;
  background-color: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--brass);
  box-shadow: 0 0 0 3px rgba(169, 129, 75, 0.15);
  background-color: var(--paper-raised);
}
.form-textarea::placeholder, .form-input::placeholder {
  color: var(--slate-soft);
  font-style: italic;
}

/* ================= CHAT & ROLE-PLAY BUBBLES ================= */
.chat-bubble-mentor {
  background-color: var(--paper-raised);
  color: var(--ink);
  border: 1px solid var(--line);
  border-left: 3px solid var(--brass);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.chat-bubble-user {
  background-color: var(--ink);
  color: var(--paper);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.chat-bubble-user .font-mono-data {
  color: var(--brass-soft);
}

.bubble-roleplay-counterparty {
  background-color: #fdfaf3;
  color: var(--ink);
  border: 1px solid #eadbc8;
  border-left: 3px solid var(--brass);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

/* ================= TABLES & REPORTS ================= */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 13px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
th {
  background-color: var(--paper);
  color: var(--ink-soft);
  font-weight: 700;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 2px solid var(--line);
}
td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background-color: #faf8f3; }

/* ================= MODALS ================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(28, 36, 48, 0.45);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-content {
  background-color: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 26px;
  width: 100%;
  max-width: 540px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  max-height: 90dvh;
  overflow-y: auto;
}

/* ================= MOBILE BOTTOM NAVIGATION BAR (BL-068) ================= */
.mobile-bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(52px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(255, 255, 255, 0.98);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: center;
  justify-items: center;
  padding-left: 4px;
  padding-right: 4px;
  z-index: 50;
  box-shadow: 0 -2px 12px rgba(28, 36, 48, 0.08);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  width: 100%;
  box-sizing: border-box;
}

.mobile-nav-item {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  width: 100% !important;
  height: 100% !important;
  padding: 3px 1px !important;
  color: var(--slate-soft);
  text-align: center;
  background: transparent;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.15s ease;
  border-radius: 8px;
  box-sizing: border-box;
  text-decoration: none;
}

.mobile-nav-item:active {
  transform: scale(0.94);
}

.mobile-nav-item.active {
  color: var(--brass-rich);
  background: rgba(169, 129, 75, 0.08);
}

.mobile-nav-icon {
  font-size: 15px !important;
  line-height: 1 !important;
  margin-bottom: 2px !important;
  display: block !important;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
  text-align: center;
}

.mobile-nav-item.active .mobile-nav-icon {
  transform: scale(1.15);
}

.mobile-nav-label {
  font-size: 9.5px !important;
  font-weight: 600 !important;
  line-height: 1.1 !important;
  letter-spacing: -0.01em;
  text-align: center;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block !important;
}

.mobile-nav-item.active .mobile-nav-label {
  font-weight: 700 !important;
  color: var(--brass-rich);
}

/* ================= RESPONSIVE ADAPTIVE BREAKPOINTS ================= */
@media (max-width: 768px) {
  .app-header { 
    padding: 0 12px; 
    height: 50px;
  }
  .app-main { 
    padding: 10px 10px calc(66px + env(safe-area-inset-bottom, 0px)) 10px !important; /* Space for bottom nav */
  }
  .single-window-pane { 
    height: calc(100dvh - 116px); 
  }
  .status-lamp {
    padding: 4px 6px;
    gap: 0;
  }
  .status-lamp #status-lamp-text {
    display: none;
  }
}

/* Phone Portrait Micro-Optimization (< 480px) */
@media (max-width: 480px) {
  .app-header {
    height: 46px;
    padding: 0 8px;
  }
  .app-main {
    padding: 8px 8px calc(62px + env(safe-area-inset-bottom, 0px)) 8px !important;
  }
  .mobile-bottom-bar {
    height: calc(50px + env(safe-area-inset-bottom, 0px));
    padding-left: 2px;
    padding-right: 2px;
  }
  .mobile-nav-item {
    padding: 2px 1px !important;
  }
  .mobile-nav-icon {
    font-size: 14px !important;
    margin-bottom: 1px !important;
  }
  .mobile-nav-label {
    font-size: 9px !important;
  }
  .single-window-pane {
    height: calc(100dvh - 106px);
  }
  .mentor-card {
    padding: 12px !important;
    border-radius: 10px !important;
  }
  .chat-bubble-mentor, .chat-bubble-user, .bubble-roleplay-counterparty {
    padding: 12px !important;
    font-size: 12.5px !important;
  }
}

/* ================= DICE ROLLING ANIMATION (BL-084) ================= */
@keyframes diceRoll {
  0% {
    transform: rotate(0deg) scale(1);
  }
  30% {
    transform: rotate(180deg) scale(1.4) translateY(-3px);
  }
  70% {
    transform: rotate(540deg) scale(1.25) translateY(2px);
  }
  100% {
    transform: rotate(720deg) scale(1) translateY(0);
  }
}

.dice-rolling {
  display: inline-block !important;
  animation: diceRoll 0.65s cubic-bezier(0.34, 1.56, 0.64, 1) forwards !important;
}

@keyframes sparkSpin {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.35); }
  100% { transform: rotate(360deg) scale(1); }
}

.spark-spinning {
  display: inline-block !important;
  animation: sparkSpin 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards !important;
}

@media print {
  body { background: #ffffff !important; color: #000000 !important; overflow: visible !important; }
  .app-container { height: auto !important; overflow: visible !important; }
  header, nav, button, .status-lamp, .modal-backdrop, .mobile-bottom-bar { display: none !important; }
  .mentor-card, .chat-bubble-mentor, .chat-bubble-user { border: 1px solid #d1d5db !important; box-shadow: none !important; }
}
