/* Light Retro Video Game / Platformer Theme */

@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Atkinson+Hyperlegible+Mono:ital,wght@0,400;0,700;1,400;1,700&family=IBM+Plex+Mono:wght@400;500;600;700&display=swap');

:root {
  --bg-primary: #87CEEB; /* Retro Sky Blue */
  --bg-card: #ffffff; /* Classic white block */
  --bg-card-hover: #f0f0f0;
  --text-main: #000000;
  --text-muted: #444444;
  --primary: #E52521; /* Classic Mario Red */
  --primary-hover: #ff4040;
  --primary-light: #ffcccc;
  --accent-cyan: #049cd8; /* Platformer Blue */
  --accent-yellow: #f8e71c; /* Coin Gold */
  --border-color: #000000;
  --border-hover: #E52521;
  --shadow-sm: 4px 4px 0px #000000;
  --shadow-md: 6px 6px 0px #000000;
  --shadow-lg: 8px 8px 0px #000000;
  --font-display: "Press Start 2P", system-ui, sans-serif;
  --font-sans: "Atkinson Hyperlegible Mono", monospace;
  --font-data: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --grid-line: #ffffff;
  --navbar-bg: #E52521;
  --navbar-text: #ffffff;
  --table-head-bg: #f0f0f0;
}

[data-theme="dark"] {
  --bg-primary: #14213d;
  --bg-card: #1f2937;
  --bg-card-hover: #2b3648;
  --text-main: #f3f4f6;
  --text-muted: #cbd5e1;
  --primary: #ff6b6b;
  --primary-hover: #ff8787;
  --primary-light: #4a1f1f;
  --accent-cyan: #38bdf8;
  --accent-yellow: #fbbf24;
  --border-color: #000000;
  --border-hover: #ff6b6b;
  --shadow-sm: 4px 4px 0px #000000;
  --shadow-md: 6px 6px 0px #000000;
  --shadow-lg: 8px 8px 0px #000000;
  --grid-line: rgba(255, 255, 255, 0.08);
  --navbar-bg: #E52521;
  --navbar-text: #ffffff;
  --table-head-bg: #111827;
}

/* Base Styles */
body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 18px;
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: none;
  background-image: 
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 30px 30px;
  background-position: -1px -1px;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 400 !important;
  color: var(--text-main);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1.3;
}
h1 {
  font-size: 28px;
  line-height: 1.5;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: all 0.1s;
}
a:hover {
  color: var(--accent-cyan);
  text-decoration: underline;
  text-decoration-style: solid;
  text-decoration-thickness: 3px;
}

/* 8-bit Navbar */
.portal-navbar {
  background: var(--navbar-bg);
  border-bottom: 4px solid #000000;
  box-shadow: var(--shadow-sm);
}

.portal-navbar .navbar-brand {
  font-family: var(--font-display);
  font-weight: 400 !important;
  font-size: clamp(0.9rem, 1.35vw, 1.25rem);
  color: #ffffff;
  letter-spacing: 0.5px;
  line-height: 1.2;
  white-space: nowrap;
}

.portal-navbar .logo-accent {
  color: var(--accent-yellow);
}

.portal-navbar .logo-sub {
  color: #ffffff;
}

.portal-navbar .nav-link {
  font-family: var(--font-display);
  font-weight: 400 !important;
  font-size: clamp(10px, 0.82vw, 12px);
  color: #ffffff;
  border: 2px solid transparent;
  padding: 5px 7px;
  line-height: 1.2;
  white-space: nowrap;
}

.portal-navbar .dropdown-toggle,
.portal-navbar .dropdown-item,
.portal-navbar .dropdown-item-text {
  white-space: nowrap;
}

.portal-navbar .nav-link:hover,
.portal-navbar .nav-link.active {
  color: #000000;
  background: var(--accent-yellow);
  border: 2px solid #000000;
  box-shadow: 3px 3px 0px #000000;
  transform: translate(-2px, -2px);
}

.portal-navbar .theme-toggle-btn {
  background: transparent;
  cursor: pointer;
}

.portal-navbar .portal-user-link {
  color: #ffffff !important;
  font-family: var(--font-display);
  font-size: clamp(10px, 0.82vw, 12px);
}

.portal-navbar .navbar-toggler-icon {
  filter: invert(1);
}

/* RAG Ask AI Navigation Button */
.btn-rag-nav {
  background: var(--accent-yellow);
  border: 4px solid #000000;
  color: #000000 !important;
  font-family: var(--font-display);
  font-weight: 400 !important;
  font-size: 13px;
  line-height: 1.4;
  text-transform: uppercase;
  border-radius: 0;
  box-shadow: 3px 3px 0px #000000;
}

.btn-rag-nav:hover {
  background: #ffffff;
  color: #000000 !important;
  box-shadow: 1px 1px 0px #000000;
  transform: translate(2px, 2px);
}

/* Retro Navbar Dropdowns */
.portal-navbar .dropdown-menu {
  background-color: #ffffff;
  border: 4px solid #000000 !important;
  border-radius: 0 !important;
  box-shadow: 4px 4px 0px #000000 !important;
  padding: 0 !important;
  margin-top: 4px !important;
}

.portal-navbar .dropdown-item {
  font-family: var(--font-display);
  font-size: 10px !important;
  padding: 8px 16px !important;
  color: #000000 !important;
  border-bottom: 2px solid #000000 !important;
  border-radius: 0 !important;
  text-align: left;
  transition: all 0.1s;
}

.portal-navbar .dropdown-item:last-child {
  border-bottom: none !important;
}

.portal-navbar .dropdown-item:hover,
.portal-navbar .dropdown-item:focus,
.portal-navbar .dropdown-item.active {
  background-color: var(--accent-yellow) !important;
  color: #000000 !important;
}

.portal-navbar .dropdown-divider {
  margin: 0 !important;
  border-top: 2px solid #000000 !important;
  opacity: 1 !important;
}

.portal-navbar .dropdown-item-text {
  font-family: var(--font-sans);
  font-size: 14px !important;
  padding: 8px 16px !important;
  background-color: #f0f0f0 !important;
  border-bottom: 2px solid #000000 !important;
  color: var(--text-muted) !important;
}

@media (max-width: 991.98px) {
  .portal-navbar .dropdown-menu {
    border-width: 2px !important;
    box-shadow: none !important;
    margin-top: 8px !important;
    background: rgba(255, 255, 255, 0.95);
  }
  .portal-navbar .dropdown-item {
    text-align: center !important;
    border-bottom-width: 1px !important;
  }
}


/* Hero Section style */
.portal-hero {
  background: #ffffff;
  border: 4px solid #000000;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
  border-radius: 0;
  padding: 3rem;
  margin-top: 2rem;
}
.portal-hero p {
  font-family: var(--font-sans);
  font-size: 18px;
  line-height: 1.8;
}

/* Cards & Lists */
.card {
  background-color: var(--bg-card);
  border: 4px solid #000000;
  border-radius: 0;
  box-shadow: var(--shadow-md);
  transition: all 0.1s;
}

.card:hover {
  background-color: var(--bg-card-hover);
  border-color: #000000;
  box-shadow: var(--shadow-lg);
  transform: translate(-2px, -2px);
}

.card-header {
  background-color: var(--table-head-bg);
  border-bottom: 4px solid #000000;
  font-family: var(--font-display);
  color: #000000;
  font-size: 1.5rem;
  padding: 1rem;
  text-transform: uppercase;
}

.card-body {
  padding: 1.5rem;
  color: var(--text-main);
}

.table {
  color: var(--text-main);
  background-color: var(--bg-card);
}

.table thead,
.table-light {
  background-color: var(--table-head-bg) !important;
  color: var(--text-main) !important;
}

.table td,
.table th {
  border-color: var(--border-color);
}

.text-muted {
  color: var(--text-muted) !important;
}

.modal-content {
  background-color: var(--bg-card);
  color: var(--text-main);
  border: 4px solid var(--border-color);
  border-radius: 0;
  box-shadow: var(--shadow-lg);
}

.modal-header,
.modal-footer {
  border-color: var(--border-color);
}

.form-control,
.form-select {
  background-color: var(--bg-card);
  color: var(--text-main);
  border: 2px solid var(--border-color);
  border-radius: 0;
}

.form-control:focus,
.form-select:focus {
  background-color: var(--bg-card-hover);
  color: var(--text-main);
  border-color: var(--accent-cyan);
  box-shadow: none;
}

.badge.bg-primary {
  background-color: var(--accent-cyan) !important;
  color: #000 !important;
  border: 2px solid #000;
  border-radius: 0;
}

footer.border-top {
  border-color: var(--border-color) !important;
  color: var(--text-muted);
}

/* Texts & Badges */
.text-gradient {
  background: none;
  -webkit-text-fill-color: initial;
  color: var(--primary);
}

/* Buttons */
.btn-primary, .btn-success, .btn-outline-primary, .btn {
  background: var(--accent-cyan);
  color: #ffffff;
  border: 4px solid #000000;
  font-family: var(--font-display);
  font-weight: 400 !important;
  font-size: 13px;
  line-height: 1.4;
  padding: 0.6rem 1.5rem;
  border-radius: 0;
  box-shadow: 4px 4px 0px #000000;
  text-transform: uppercase;
  transition: all 0.1s;
}

.btn-primary:hover, .btn-success:hover, .btn-outline-primary:hover, .btn:hover {
  background: #ffffff;
  color: #000000;
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0px #000000;
}

.btn-success {
  background: #00cc00;
}

.btn-outline-secondary {
  border: 4px solid #000000;
  color: #000000;
  background: #ffffff;
  font-family: var(--font-display);
  font-weight: 400 !important;
  font-size: 13px;
  line-height: 1.4;
  text-transform: uppercase;
  border-radius: 0;
  box-shadow: 4px 4px 0px #000000;
}

.btn-outline-secondary:hover {
  background: var(--accent-yellow);
  color: #000000;
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0px #000000;
}

/* Markdown Reader Custom Styling */
.rendered-markdown {
  font-size: 1.25rem;
  color: var(--text-main);
}

.rendered-markdown h1,
.rendered-markdown h2,
.rendered-markdown h3 {
  color: var(--text-main);
  margin-top: 2rem;
  margin-bottom: 1rem;
  line-height: 1.3;
}

.rendered-markdown h1 {
  font-size: 2.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 4px solid #000000;
}

.rendered-markdown h2 {
  font-size: 2.25rem;
}

.rendered-markdown h3 {
  font-size: 1.75rem;
}

.rendered-markdown p {
  margin-bottom: 1.25rem;
}

/* Styled Code blocks */
.rendered-markdown pre {
  background: #e0e0e0; 
  color: #000000;
  border: 4px solid #000000;
  padding: 1.25rem;
  border-radius: 0;
  overflow-x: auto;
  margin: 1.5rem 0;
  font-family: var(--font-sans);
  line-height: 1.3;
  box-shadow: inset 4px 4px 0px rgba(0,0,0,0.1);
}

.rendered-markdown code {
  font-family: var(--font-sans);
  font-size: 1em;
  color: #000000;
  background-color: var(--accent-yellow);
  padding: 0.2rem 0.4rem;
  border: 2px solid #000;
}

.rendered-markdown pre code {
  background-color: transparent;
  padding: 0;
  color: #000000;
  border: none;
}

/* Custom Table in Markdown */
.table-responsive {
  border-radius: 0;
  overflow: hidden;
  border: 4px solid #000000;
  margin: 1.5rem 0;
  background: #ffffff;
  box-shadow: var(--shadow-sm);
}

.table {
  margin-bottom: 0;
  color: var(--text-main);
}

.table th {
  background-color: var(--primary);
  color: #ffffff;
  font-weight: 400;
  font-family: var(--font-display);
  border-bottom: 4px solid #000000;
}

.table td {
  vertical-align: middle;
  border-color: #000000;
}

/* Custom Checkbox/Checklists */
.rendered-markdown input[type="checkbox"] {
  width: 1.5em;
  height: 1.5em;
  margin-right: 0.5em;
  accent-color: var(--accent-cyan);
  border: 3px solid #000000;
  background-color: #ffffff;
  border-radius: 0;
  vertical-align: -0.2em;
}

/* Alert modifications */
.alert-info {
  background-color: #ffffff;
  border: 4px solid var(--accent-cyan);
  color: #000000;
  border-radius: 0;
  box-shadow: 4px 4px 0px var(--accent-cyan);
}

/* Custom Visual Block Diagrams */
.system-flow {
  background: #ffffff;
  border: 4px solid #000000;
  border-radius: 0;
  font-family: var(--font-sans);
  box-shadow: var(--shadow-md);
}

.flow-node {
  background: #f0f0f0;
  border: 4px solid #000000;
  border-radius: 0;
  box-shadow: 4px 4px 0px #000000;
  transition: all 0.1s;
}

.flow-node:hover {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0px #000000;
  background: #ffffff;
}

/* Specific Node Type Borders & Highlights */
.flow-node-input { border-left: 8px solid var(--accent-cyan) !important; }
.flow-node-processor { border-left: 8px solid var(--primary) !important; }
.flow-node-core { border-left: 8px solid var(--accent-yellow) !important; }
.flow-node-storage { border-left: 8px solid #000000 !important; }
.flow-node-downstream { border-left: 8px solid #ff9900 !important; }
.flow-node-output { border-left: 8px solid #00cc00 !important; }

/* Node Icons */
.node-icon-bg {
  width: 36px;
  height: 36px;
  border-radius: 0;
  background: #ffffff;
  color: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  border: 2px solid #000000;
}

/* Flow Connectors */
.flow-connector {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.flow-arrow-text {
  font-size: 1.2rem;
  font-weight: 400;
  padding: 0.2rem 0.5rem;
  background: #ffffff;
  border: 2px solid #000000;
  color: #000000;
}

.flow-arrow-icon {
  font-size: 1.5rem;
  color: #000000;
}

/* Mobile Responsiveness Overrides */
@media (max-width: 991.98px) {
  main.content-wrapper {
    padding-top: 1.5rem !important;
    padding-bottom: 2rem !important;
  }
}

@media (max-width: 768px) {
  html {
    -webkit-text-size-adjust: 100%;
  }

  body {
    font-size: 15px;
    line-height: 1.5;
    overflow-x: hidden;
  }

  h1 {
    font-size: 18px !important;
    word-break: break-word;
  }
  h2 {
    font-size: 15px !important;
  }
  h3 {
    font-size: 13px !important;
  }

  /* Navbar */
  .portal-navbar .navbar-brand {
    font-size: 0.95rem !important;
    max-width: calc(100vw - 4rem);
    white-space: nowrap;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .portal-navbar .navbar-toggler {
    border: 2px solid #000 !important;
    background: var(--accent-yellow);
    padding: 0.35rem 0.55rem;
  }
  .portal-navbar .navbar-toggler-icon {
    filter: invert(1);
    width: 1.25em;
    height: 1.25em;
  }
  .portal-navbar .navbar-collapse {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.15);
    border: 2px solid #000;
  }
  .portal-navbar .nav-link {
    font-size: 11px !important;
    padding: 8px 10px !important;
    margin: 2px 0 !important;
    text-align: center;
    width: 100%;
    white-space: nowrap;
  }
  .portal-navbar .dropdown-menu {
    width: 100%;
    text-align: center;
  }

  /* Layout */
  main.content-wrapper {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }

  .portal-hero {
    padding: 1.25rem !important;
    margin-top: 0.5rem !important;
  }
  .portal-hero .btn,
  .portal-hero .d-flex.gap-3 .btn {
    width: 100%;
    margin-bottom: 0.5rem;
  }
  .portal-hero .d-flex.gap-3 {
    flex-direction: column;
    gap: 0.5rem !important;
  }

  .card-header {
    font-size: 1rem !important;
    padding: 0.75rem !important;
  }
  .card-body {
    padding: 0.75rem !important;
  }
  .display-5 {
    font-size: 1.4rem !important;
  }
  .lead {
    font-size: 0.95rem !important;
  }

  /* Markdown reader */
  .rendered-markdown {
    font-size: 1rem;
    overflow-wrap: anywhere;
  }
  .rendered-markdown h1 {
    font-size: 1.5rem !important;
  }
  .rendered-markdown h2 {
    font-size: 1.25rem !important;
  }
  .rendered-markdown h3 {
    font-size: 1.1rem !important;
  }
  .rendered-markdown pre {
    padding: 0.75rem;
    font-size: 0.85rem;
  }

  /* Day reader action buttons */
  .day-actions .btn {
    width: 100%;
    margin-bottom: 0.35rem;
  }

  /* Flow diagrams */
  .system-flow {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Buttons – touch-friendly minimum */
  .btn {
    min-height: 44px;
  }
  .btn-sm {
    min-height: 38px;
  }

  /* Arcade page */
  .arcade-stats-bar {
    width: 100%;
    justify-content: center;
  }
  #stickerBoard {
    height: 260px !important;
  }
}

@media (max-width: 576px) {
  body {
    font-size: 14px;
  }
  .portal-navbar .navbar-brand {
    font-size: 0.8rem !important;
  }
  .display-5 {
    font-size: 1.2rem !important;
  }
}

/* ── Game Shell (shared arcade frame) ── */
.game-shell-container {
  margin-bottom: 2rem !important;
}

body.game-fullscreen-page,
body:has(.game-shell-container) {
  background: #000;
  overflow: hidden;
}

body.game-fullscreen-page .portal-navbar,
body.game-fullscreen-page footer,
body:has(.game-shell-container) .portal-navbar,
body:has(.game-shell-container) footer {
  display: none !important;
}

body.game-fullscreen-page main.content-wrapper,
main.content-wrapper:has(.game-shell-container) {
  width: 100vw;
  max-width: none !important;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 !important;
  padding: 0 !important;
}

body.game-fullscreen-page main.content-wrapper > .game-shell-container,
main.content-wrapper:has(.game-shell-container) > .game-shell-container {
  width: 100vw;
}

.game-shell-container {
  position: fixed;
  inset: 0;
  z-index: 1050;
  width: 100vw;
  height: 100vh;
  height: 100svh;
  margin: 0 !important;
  padding: 0 !important;
  background: #000;
  overflow: hidden;
}

.game-shell-container > .col-12 {
  width: 100%;
  max-width: none !important;
  height: 100%;
  padding: 0 !important;
  display: flex;
  flex-direction: column;
}

.game-shell-header {
  display: none !important;
}

.game-shell-container .card {
  width: 100%;
  height: 100%;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
}

.game-shell-close {
  position: fixed;
  top: max(0.65rem, env(safe-area-inset-top));
  right: max(0.65rem, env(safe-area-inset-right));
  z-index: 1120;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  text-decoration: none;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.38);
}

.game-shell-close:hover,
.game-shell-close:focus {
  color: #000;
  background: #fff;
  outline: none;
}

.game-console {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  background: #000;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}

.game-console:not(:has(.shell-touch-controls)) {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.game-hud-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  flex-shrink: 0;
  border-bottom: 2px solid #333;
  gap: 0.5rem;
}

.game-hud-top > div {
  flex: 1 1 0;
  min-width: 0;
}

.game-hud-top .h4,
.game-hud-top .h5 {
  font-size: clamp(0.9rem, 3vw, 1.25rem) !important;
  margin-bottom: 0 !important;
  overflow-wrap: anywhere;
}

.game-canvas-area {
  background: #000;
  width: 100%;
  aspect-ratio: auto;
  height: auto;
  max-height: none;
  min-height: 0;
  position: relative;
  overflow: hidden;
  flex: 1 1 auto;
}

.game-canvas-area > canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  touch-action: none;
  box-sizing: border-box;
}

.game-hud-bottom {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.35rem 0.5rem;
  padding-bottom: max(0.35rem, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.92);
  flex-shrink: 0;
  border-top: 2px solid #333;
  position: relative;
  z-index: 30;
}

.game-instructions-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 20 !important;
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: rgba(4, 8, 20, 0.96);
  padding: 0.75rem;
  padding-top: max(0.75rem, env(safe-area-inset-top));
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  overflow: hidden;
}

.game-instructions-overlay .game-start-panel,
#startScreenOverlay .game-start-panel {
  margin: auto 0;
  width: 100%;
  max-width: min(760px, 100%);
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#startScreenOverlay:not(.game-instructions-overlay) {
  overflow: hidden !important;
  padding: 0.75rem;
  padding-top: max(0.75rem, env(safe-area-inset-top));
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
}

.game-instructions-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
  font-family: var(--font-sans);
}

.game-instructions-grid section {
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid #555;
  border-radius: 8px;
  padding: 0.9rem;
}

.game-instructions-grid h6 {
  color: var(--primary);
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: 0.65rem;
}

.game-instructions-grid ol {
  color: #f8f9fa;
  margin: 0;
  padding-left: 1.2rem;
}

.game-control-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.game-control-tags kbd {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  padding: 0.3rem 0.55rem;
  border: 2px solid #ffffff;
  border-radius: 6px;
  background: #111827;
  color: #ffffff;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  box-shadow: inset 0 -2px 0 rgba(255, 255, 255, 0.18);
}

.game-touch-note {
  color: #dbeafe;
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

.game-setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 52px;
  padding: 0.75rem;
  border-bottom: 1px solid #444;
  color: #fff;
  font-family: var(--font-sans);
  font-size: 1rem;
}

.game-setting-row input {
  width: 48px;
  height: 28px;
}

.game-setting-block {
  padding: 0.85rem 0.75rem 0.25rem;
  color: #fff;
  font-family: var(--font-sans);
  text-align: left;
}

.game-setting-block-title {
  color: var(--primary);
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: 0.6rem;
  font-size: 0.9rem;
}

.shell-touch-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(68px, 1fr));
  gap: 0.4rem;
  padding: 0.4rem 0.5rem;
  padding-bottom: max(0.4rem, env(safe-area-inset-bottom));
  background: #111;
  border-top: 2px solid #333;
  flex-shrink: 0;
  max-height: 120px;
  overflow: hidden;
}

.shell-touch-controls--hint {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  color: #f8f9fa;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  text-align: center;
}

.shell-touch-btn {
  min-width: 48px;
  min-height: 54px;
  border: 2px solid #ffffff;
  border-radius: 8px;
  background: #1d4ed8;
  color: #ffffff;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  font-family: var(--font-sans);
  touch-action: manipulation;
}

.shell-touch-btn:hover {
  background: #2563eb;
}

.shell-touch-btn:active {
  transform: translateY(2px);
  background: #0f766e;
}

.shell-touch-btn strong {
  font-size: 1.15rem;
  line-height: 1;
}

.shell-touch-btn span {
  font-size: 0.72rem;
  line-height: 1;
}

.game-hud-bottom .btn {
  box-shadow: none;
  max-width: 100%;
  min-height: 36px;
}

.game-shell-header {
  gap: 0.5rem;
}

.game-start-panel {
  border: 4px solid var(--primary);
  max-width: 500px;
  width: calc(100% - 1.5rem);
  max-height: calc(100% - 1.5rem);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.game-start-panel::-webkit-scrollbar,
#startScreenOverlay::-webkit-scrollbar {
  display: none;
}

.game-overlay-panel {
  padding: 1rem;
  width: calc(100% - 1.5rem);
  max-width: 420px;
  text-align: center;
}

.game-overlay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  width: 100%;
}

.game-overlay-actions .btn {
  flex: 1 1 auto;
  min-width: 120px;
}

/* Game shell polish animations */
.gs-score-popup {
  position: absolute;
  font-family: var(--font-display);
  font-size: clamp(1rem, 4vw, 1.8rem);
  font-weight: 900;
  color: #FFD700;
  text-shadow: 2px 2px 0 #000, -1px -1px 0 #000;
  pointer-events: none;
  z-index: 15;
  animation: gs-float-up 0.9s ease-out forwards;
}
@keyframes gs-float-up {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(-60px) scale(1.5); opacity: 0; }
}
.gs-particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 15;
  animation: gs-burst 0.6s ease-out forwards;
}
@keyframes gs-burst {
  0% { transform: translate(0,0) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}
@keyframes gs-shake {
  0%, 100% { transform: translate(0,0); }
  20% { transform: translate(-4px, 2px); }
  40% { transform: translate(4px, -2px); }
  60% { transform: translate(-3px, 3px); }
  80% { transform: translate(3px, -1px); }
}
.gs-countdown-text {
  font-family: var(--font-display);
  font-size: clamp(3rem, 18vw, 6rem);
  font-weight: 900;
  color: #fff;
  text-shadow: 4px 4px 0 #000;
}
.gs-countdown-pop {
  animation: gs-count-pop 0.6s ease-out;
}
@keyframes gs-count-pop {
  0% { transform: scale(2); opacity: 0; }
  50% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.9); opacity: 1; }
}
@keyframes gs-pulse {
  0% { transform: scale(1); }
  100% { transform: scale(1.08); }
}

@media (max-width: 768px) {
  main.content-wrapper:has(.game-shell-container) {
    padding: 0 !important;
  }
  .game-shell-container {
    padding-left: 0;
    padding-right: 0;
    margin-bottom: 0 !important;
  }
  .game-shell-container .card {
    border-width: 0 !important;
    margin-bottom: 0 !important;
  }
  .game-canvas-area {
    aspect-ratio: auto;
    height: auto;
    max-height: none;
    min-height: 0;
  }
  .game-hud-top {
    padding: 0.35rem 0.45rem;
    font-size: 0.75rem;
    gap: 0.25rem;
  }
  .game-hud-top .small {
    font-size: 0.58rem !important;
  }
  .game-hud-bottom {
    min-height: 40px;
    padding: 0.25rem 0.4rem;
    padding-bottom: max(0.25rem, env(safe-area-inset-bottom));
  }
  .shell-touch-controls {
    max-height: 108px;
    grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
  }
  .shell-touch-btn {
    min-height: 48px;
  }
  .game-hud-bottom .btn {
    font-size: 0.72rem;
    min-height: 36px;
    padding: 0.3rem 0.85rem !important;
  }
  .game-start-panel {
    padding: 0.85rem !important;
    width: 100%;
    max-height: 100%;
  }
  .game-instructions-grid {
    grid-template-columns: 1fr;
    gap: 0.65rem;
  }
  .game-control-tags kbd {
    min-height: 30px;
    font-size: 0.8rem;
  }
  .game-start-panel h2 {
    font-size: 0.95rem !important;
    margin-bottom: 0.65rem !important;
  }
  .game-start-panel p,
  .game-start-panel li {
    font-size: 0.76rem;
    line-height: 1.35;
  }
  .game-start-panel .mb-4 {
    margin-bottom: 0.65rem !important;
  }
  .game-start-panel .btn-group {
    flex-direction: column;
  }
  .game-start-panel .btn-group .btn {
    border-radius: 0 !important;
    width: 100%;
  }
  .game-start-panel #shellStartBtn {
    padding-top: 0.75rem !important;
    padding-bottom: 0.75rem !important;
  }
  .game-overlay-actions {
    flex-direction: column;
  }
  .game-overlay-actions .btn {
    width: 100%;
  }
  #starRatingContainer .fs-1 {
    font-size: 1.75rem !important;
  }
}

/* iPad & phone portrait – fit game + config without page scroll */
@media (max-width: 1024px) and (orientation: portrait) {
  body.game-fullscreen-page,
  body:has(.game-shell-container) {
    overflow: hidden;
    height: 100vh;
    height: 100svh;
  }

  .game-shell-container {
    height: 100svh;
    max-height: 100svh;
  }

  .game-console {
    height: 100%;
    max-height: 100svh;
  }

  .game-canvas-area {
    min-height: 0;
    overflow: hidden;
  }

  .game-instructions-overlay,
  #startScreenOverlay {
    align-items: stretch;
  }

  .game-start-panel {
    max-height: 100%;
  }

  .shell-touch-controls {
    max-height: 100px;
  }

  .math-shell .game-canvas-area {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .math-shell .math-container {
    min-height: 0;
    height: auto;
  }
}

/* Safe area for notched phones */
@supports (padding: max(0px)) {
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .portal-navbar.sticky-top {
    padding-top: env(safe-area-inset-top);
  }
  footer {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
}

/* Math arcade responsive overrides */
@media (max-width: 768px) {
  .math-game-wrapper {
    aspect-ratio: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    height: auto !important;
  }
  .math-container {
    min-height: 0;
    height: 100%;
  }
  .problem-container {
    padding: 12px !important;
    font-size: 1.25rem !important;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .digit-cell {
    width: 32px !important;
    height: 42px !important;
    font-size: 1rem !important;
    margin: 0 1px !important;
  }
  .carry-cell {
    width: 32px !important;
    height: 24px !important;
    font-size: 0.75rem !important;
    margin: 0 1px !important;
  }
  .operator-cell {
    width: 28px !important;
    font-size: 1.25rem !important;
  }
  .math-bottom-bar {
    padding: 10px 10px 12px !important;
  }
  .numpad {
    max-width: 100%;
    gap: 6px;
  }
  .numpad button {
    padding: 12px 0;
    font-size: 1rem;
    min-height: 44px;
  }
  .math-top-bar {
    padding: 8px 12px;
    font-size: 0.75rem;
  }
}

@media (max-width: 400px) {
  .digit-cell {
    width: 26px !important;
    height: 36px !important;
    font-size: 0.85rem !important;
  }
  .carry-cell {
    width: 26px !important;
  }
  .operator-cell {
    width: 22px !important;
  }
}

/* Kid city adventure */
@media (max-width: 768px) {
  .kid-city-wrapper {
    aspect-ratio: auto !important;
    max-height: none !important;
    height: clamp(280px, calc(100vh - 335px), 520px) !important;
    height: clamp(280px, calc(100svh - 335px), 520px) !important;
    min-height: 0 !important;
  }
  .kc-mobile-controls {
    display: flex !important;
  }
}
