/* ═══════════════════════════════════════════════
   style.css – GridWorld Application Styles
   ═══════════════════════════════════════════════ */

/* ── Tokens ─────────────────────────────────── */
:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1e2530;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-glow: rgba(88, 166, 255, 0.20);
  --green: #3fb950;
  --green-bg: rgba(63, 185, 80, 0.18);
  --red: #f85149;
  --red-bg: rgba(248, 81, 73, 0.18);
  --gray: #6e7681;
  --gray-bg: rgba(110, 118, 129, 0.25);
  --yellow: #e3b341;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
  --transition: 0.18s ease;
}

/* ── Reset ───────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── App wrapper ─────────────────────────────── */
.app-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────── */
.app-header {
  background: linear-gradient(135deg, #0d1117 0%, #161b22 100%);
  border-bottom: 1px solid var(--border);
  padding: 1.2rem 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.header-content {
  display: flex;
  align-items: center;
  gap: 1.2rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -.5px;
}

.logo-icon {
  font-size: 1.6rem;
}

.accent {
  color: var(--accent);
}

.subtitle {
  color: var(--text-muted);
  font-size: .85rem;
  margin-left: auto;
}

/* ── Main layout ─────────────────────────────── */
.main-layout {
  display: flex;
  flex: 1;
  gap: 1.5rem;
  padding: 1.5rem 2rem;
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}

/* ── Control Panel ───────────────────────────── */
.control-panel {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .7rem;
}

.section-title {
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: .1rem;
}

/* ── Form controls ───────────────────────────── */
.field-label {
  font-size: .82rem;
  color: var(--text-muted);
  font-weight: 500;
}

.select-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: .5rem .7rem;
  font-size: .9rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color var(--transition);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .7rem center;
  padding-right: 2rem;
}

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

/* ── Buttons ─────────────────────────────────── */
.btn {
  width: 100%;
  padding: .55rem 1rem;
  border: none;
  border-radius: 7px;
  font-family: inherit;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: .01em;
}

.btn-primary {
  background: var(--accent);
  color: #0d1117;
}

.btn-primary:hover {
  background: #79b8ff;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-accent {
  background: linear-gradient(135deg, #a855f7, #6366f1);
  color: #fff;
}

.btn-accent:hover {
  opacity: .9;
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(168, 85, 247, .3);
}

.btn:disabled {
  opacity: .4;
  cursor: not-allowed;
  transform: none !important;
}

.btn-optimal {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #0d1117;
}

.btn-optimal:hover {
  opacity: .9;
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(245, 158, 11, .35);
}

/* ── Hint text ──────────────────────────────────── */
.hint-text {
  font-size: .75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ── Optimal cell glow ──────────────────────────── */
.grid-cell.optimal {
  box-shadow: inset 0 0 0 2px rgba(245, 158, 11, 0.6), 0 0 8px rgba(245, 158, 11, 0.25);
}

/* ── Optimal path trail ─────────────────────────── */
.grid-cell.on-path {
  box-shadow: inset 0 0 0 2px rgba(6, 182, 212, 0.7), 0 0 12px rgba(6, 182, 212, 0.35) !important;
  animation: pathPulse 0.4s ease var(--path-delay, 0s) both;
}

.grid-cell.on-path:not(.start):not(.goal) {
  background: rgba(6, 182, 212, 0.25) !important;
}

@keyframes pathPulse {
  0% {
    box-shadow: none;
  }

  50% {
    box-shadow: inset 0 0 0 2px rgba(6, 182, 212, 0.9), 0 0 16px rgba(6, 182, 212, 0.5);
  }

  100% {
    box-shadow: inset 0 0 0 2px rgba(6, 182, 212, 0.7), 0 0 12px rgba(6, 182, 212, 0.35);
  }
}

/* ── Legend ──────────────────────────────────── */
.legend {
  display: flex;
  align-items: center;
  gap: .55rem;
  font-size: .83rem;
  color: var(--text-muted);
}

.legend-dot {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  flex-shrink: 0;
}

.legend-dot.start {
  background: var(--green);
}

.legend-dot.goal {
  background: var(--red);
}

.legend-dot.obstacle {
  background: var(--gray);
}

.legend-dot.empty {
  background: var(--surface-2);
  border: 1px solid var(--border);
}

/* ── Toggle switch ───────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

.toggle-label {
  font-size: .82rem;
  color: var(--text-muted);
}

.switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: var(--transition);
}

.slider::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  top: 3px;
  left: 3px;
  transition: var(--transition);
}

.switch input:checked+.slider {
  background: var(--accent);
}

.switch input:checked+.slider::before {
  transform: translateX(16px);
}

/* ── Info grid ───────────────────────────────── */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
}

.info-item {
  background: var(--surface-2);
  border-radius: 7px;
  padding: .6rem .5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .15rem;
}

.info-num {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
}

.info-lbl {
  font-size: .72rem;
  color: var(--text-muted);
}

/* ── Grid Area ───────────────────────────────── */
.grid-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

/* placeholder */
.grid-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  min-height: 400px;
}

.placeholder-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .8rem;
  color: var(--text-muted);
}

.ph-icon {
  font-size: 3rem;
  opacity: .4;
}

.placeholder-text p {
  font-size: .95rem;
}

/* ── Actual grid table ───────────────────────── */
#grid-container table {
  border-collapse: collapse;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.grid-cell {
  width: 70px;
  height: 70px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  position: relative;
  transition: background var(--transition), transform var(--transition);
  user-select: none;
}

.grid-cell:hover {
  background: var(--surface-2);
  transform: scale(1.04);
  z-index: 1;
}

.grid-cell.start {
  background: var(--green-bg);
  border-color: var(--green);
}

.grid-cell.goal {
  background: var(--red-bg);
  border-color: var(--red);
}

.grid-cell.obstacle {
  background: var(--gray-bg);
  border-color: var(--gray);
  cursor: not-allowed;
}

/* Label badge in top-left */
.cell-label {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .05em;
  opacity: .8;
}

.start .cell-label {
  color: var(--green);
}

.goal .cell-label {
  color: var(--red);
}

.obstacle .cell-label {
  color: var(--gray);
}

/* Policy arrow – centred */
.cell-arrow {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  transition: opacity var(--transition);
  pointer-events: none;
}

/* V(s) value – bottom-right */
.cell-value {
  position: absolute;
  bottom: 4px;
  right: 5px;
  font-size: .6rem;
  font-weight: 600;
  color: var(--yellow);
  transition: opacity var(--transition);
  pointer-events: none;
}

/* ── Status bar ──────────────────────────────── */
.status-bar {
  display: flex;
  align-items: center;
  gap: .7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .65rem 1.1rem;
  width: 100%;
  max-width: 700px;
  font-size: .9rem;
  animation: fadeSlide .3s ease;
}

@keyframes fadeSlide {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#status-text {
  font-weight: 500;
}

/* ── Scrollbar styling ───────────────────────── */
::-webkit-scrollbar {
  width: 6px;
}

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

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