/* CSS Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* Dark Mode Color Palette */
  --background: 222 47% 11%;
  --foreground: 213 31% 91%;
  --muted: 223 47% 11%;
  --muted-foreground: 215.4 16.3% 56.9%;
  --card: 224 71% 4%;
  --card-foreground: 213 31% 91%;
  --card-border: 215 27.9% 16.9%;
  --popover: 224 71% 4%;
  --popover-foreground: 215 20.2% 65.1%;
  --border: 216 34% 17%;
  --input: 216 34% 17%;
  --primary: 210 100% 63%;
  --primary-foreground: 222.2 47.4% 1.2%;
  --secondary: 222.2 47.4% 11.2%;
  --secondary-foreground: 210 40% 98%;
  --accent: 216 34% 17%;
  --accent-foreground: 210 40% 98%;
  --destructive: 0 63% 31%;
  --destructive-foreground: 210 40% 98%;
  --ring: 216 34% 17%;
  --radius: 0.5rem;
  
  /* Outcome Colors */
  --outcome-binding: 346 77% 50%;
  --outcome-binding-bg: 346 77% 8%;
  --outcome-binding-border: 346 77% 20%;
  --outcome-alternative: 189 85% 42%;
  --outcome-alternative-bg: 189 85% 8%;
  --outcome-alternative-border: 189 85% 20%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* App Container */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Header */
.app-header {
  background-color: hsl(var(--card));
  border-bottom: 1px solid hsl(var(--border));
  padding: 0.75rem 1.5rem;
  flex-shrink: 0;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.app-title {
  font-size: 1.125rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress-indicator {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.75rem;
  background-color: hsl(var(--accent));
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
}

#stepCount {
  font-weight: 600;
  color: hsl(var(--foreground));
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  background: transparent;
  color: hsl(var(--foreground));
  min-height: 2.25rem;
}

.btn:hover:not(:disabled) {
  background-color: hsl(var(--accent) / 0.8);
}

.btn:active:not(:disabled) {
  background-color: hsl(var(--accent) / 0.9);
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  border-color: hsl(var(--primary));
}

.btn-primary:hover:not(:disabled) {
  background-color: hsl(var(--primary) / 0.9);
}

.btn-primary:active:not(:disabled) {
  background-color: hsl(var(--primary) / 0.8);
}

.btn-secondary {
  background-color: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  border-color: hsl(var(--border));
}

.btn-ghost {
  background: transparent;
}

.btn-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: none;
  background: transparent;
  color: hsl(var(--foreground));
  cursor: pointer;
  border-radius: var(--radius);
  transition: all 0.15s ease;
}

.btn-close:hover {
  background-color: hsl(var(--accent));
}

.mobile-history-btn {
  display: none;
}

@media (max-width: 768px) {
  .mobile-history-btn {
    display: inline-flex;
  }
}

/* Main Content */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* History Panel */
.history-panel {
  width: 24rem;
  flex-shrink: 0;
  background-color: hsl(var(--card));
  border-right: 1px solid hsl(var(--border));
  display: flex;
  flex-direction: column;
}

.history-header {
  padding: 1.5rem;
  border-bottom: 1px solid hsl(var(--border));
}

.history-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.history-subtitle {
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
}

.history-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.empty-history {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  text-align: center;
  color: hsl(var(--muted-foreground));
}

.empty-icon {
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-history p {
  margin-bottom: 0.5rem;
}

.empty-subtitle {
  font-size: 0.875rem;
}

.history-list {
  padding: 1rem 0.5rem 1rem 1.5rem;
}

/* History Item */
.history-item {
  position: relative;
  padding-left: 1.5rem;
  margin-bottom: 1rem;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.history-item:hover {
  opacity: 1 !important;
}

.history-line {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background-color: hsl(var(--border));
}

.history-line.active {
  background-color: hsl(var(--primary));
}

.history-dot {
  position: absolute;
  left: 0;
  top: 0.75rem;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background-color: hsl(var(--border));
  transform: translateX(-0.1875rem);
}

.history-dot.active {
  background-color: hsl(var(--primary));
}

.history-card {
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--card-border));
  border-radius: var(--radius);
  padding: 1rem;
  transition: all 0.15s ease;
}

.history-card:hover {
  background-color: hsl(var(--accent) / 0.5);
  border-color: hsl(var(--border));
}

.history-card-content {
  display: flex;
  gap: 0.75rem;
}

.history-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.5rem;
  background-color: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  border-radius: calc(var(--radius) * 0.75);
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
  min-width: 2rem;
  height: 1.5rem;
}

.history-text {
  flex: 1;
  min-width: 0;
}

.history-question {
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-choice {
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Decision Panel */
.decision-panel {
  flex: 1;
  overflow-y: auto;
  background-color: hsl(var(--background));
}

.decision-scroll {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.decision-card {
  width: 100%;
  max-width: 42rem;
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--card-border));
  border-radius: calc(var(--radius) * 1.5);
  padding: 2rem;
}

.decision-question {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  line-height: 1.4;
  white-space: pre-line;
}

.decision-choices {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.choice-btn {
  width: 100%;
  padding: 1rem 1.25rem;
  background-color: hsl(var(--secondary));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  color: hsl(var(--foreground));
}

.choice-btn:hover {
  background-color: hsl(var(--accent) / 0.8);
  border-color: hsl(var(--primary) / 0.5);
  transform: translateY(-1px);
}

.choice-btn:active {
  background-color: hsl(var(--accent));
  transform: translateY(0);
}

/* Outcome Card */
.outcome-card {
  width: 100%;
  max-width: 42rem;
  border-radius: calc(var(--radius) * 1.5);
  padding: 2rem;
  border: 2px solid;
}

.outcome-card.binding {
  background-color: hsl(var(--outcome-binding-bg));
  border-color: hsl(var(--outcome-binding-border));
}

.outcome-card.alternative {
  background-color: hsl(var(--outcome-alternative-bg));
  border-color: hsl(var(--outcome-alternative-border));
}

.outcome-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.375rem 0.75rem;
  border-radius: calc(var(--radius) * 0.75);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
}

.outcome-badge.binding {
  background-color: hsl(var(--outcome-binding) / 0.15);
  color: hsl(var(--outcome-binding));
}

.outcome-badge.alternative {
  background-color: hsl(var(--outcome-alternative) / 0.15);
  color: hsl(var(--outcome-alternative));
}

.outcome-title {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  line-height: 1.3;
}

.outcome-card.binding .outcome-title {
  color: hsl(var(--outcome-binding));
}

.outcome-card.alternative .outcome-title {
  color: hsl(var(--outcome-alternative));
}

.outcome-text {
  font-size: 1rem;
  line-height: 1.7;
  white-space: pre-line;
  color: hsl(var(--foreground));
}

/* Glossary Term Tooltip */
.glossary-term {
  display: inline;
  color: hsl(var(--primary));
  border-bottom: 1px dotted hsl(var(--primary));
  cursor: help;
  position: relative;
}

.glossary-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-0.5rem);
  background-color: hsl(var(--popover));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 0.75rem;
  max-width: 16rem;
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.2);
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  white-space: normal;
}

.glossary-term:hover .glossary-tooltip {
  opacity: 1;
}

.tooltip-term {
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 0.25rem;
  color: hsl(var(--foreground));
}

.tooltip-definition {
  font-size: 0.8125rem;
  line-height: 1.5;
  color: hsl(var(--muted-foreground));
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(2px);
}

.modal-content {
  position: relative;
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) * 1.5);
  box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.5);
  width: 90vw;
  max-width: 48rem;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem;
  border-bottom: 1px solid hsl(var(--border));
}

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.search-box {
  position: relative;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid hsl(var(--border));
}

.search-icon {
  position: absolute;
  left: 2rem;
  top: 50%;
  transform: translateY(-50%);
  color: hsl(var(--muted-foreground));
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 0.5rem 0.75rem 0.5rem 2.25rem;
  background-color: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  color: hsl(var(--foreground));
  font-size: 0.875rem;
}

.search-box input:focus {
  outline: none;
  border-color: hsl(var(--primary));
}

.glossary-table-container {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

.glossary-table {
  width: 100%;
  border-collapse: collapse;
}

.glossary-table thead {
  position: sticky;
  top: 0;
  background-color: hsl(var(--card));
  z-index: 10;
}

.glossary-table th {
  text-align: left;
  padding: 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: hsl(var(--muted-foreground));
  border-bottom: 1px solid hsl(var(--border));
}

.glossary-table td {
  padding: 1rem 0.75rem;
  border-bottom: 1px solid hsl(var(--border));
  vertical-align: top;
}

.glossary-table td:first-child {
  font-weight: 500;
  width: 35%;
}

.glossary-table td:last-child {
  color: hsl(var(--muted-foreground));
  font-size: 0.9375rem;
}

.glossary-table tr:last-child td {
  border-bottom: none;
}

.glossary-table tbody tr {
  transition: background-color 0.15s ease;
}

.glossary-table tbody tr:hover {
  background-color: hsl(var(--accent) / 0.3);
}

/* Mobile Drawer */
.mobile-drawer {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: none;
}

.mobile-drawer.active {
  display: block;
}

.drawer-overlay {
  position: absolute;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(2px);
}

.drawer-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 85vh;
  background-color: hsl(var(--card));
  border-top-left-radius: calc(var(--radius) * 2);
  border-top-right-radius: calc(var(--radius) * 2);
  display: flex;
  flex-direction: column;
  animation: drawerUp 0.3s ease;
}

@keyframes drawerUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem;
  border-bottom: 1px solid hsl(var(--border));
}

.drawer-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
}

.drawer-scroll {
  flex: 1;
  overflow-y: auto;
}

/* Responsive */
@media (max-width: 768px) {
  .desktop-only {
    display: none !important;
  }

  .app-title {
    font-size: 1rem;
  }

  .decision-card,
  .outcome-card {
    padding: 1.5rem;
  }

  .decision-question {
    font-size: 1.25rem;
  }

  .outcome-title {
    font-size: 1.5rem;
  }

  .modal-content {
    width: 95vw;
    max-height: 90vh;
  }
}

@media (max-width: 480px) {
  .header-content {
    flex-wrap: wrap;
  }

  .header-left {
    flex: 1 1 100%;
    margin-bottom: 0.5rem;
  }

  .decision-scroll {
    padding: 1rem;
  }

  .btn {
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
  }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: hsl(var(--background));
}

::-webkit-scrollbar-thumb {
  background: hsl(var(--border));
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: hsl(var(--muted-foreground) / 0.5);
}
