body {
  font-family: sans-serif;
  text-align: center;
  background: #f0f8ff;
  margin: 0;
  padding: 20px;
}

h1 {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  margin: 20px 0;
}

h1 .logo {
  width: 60px;
  height: 60px;
}

/* Language flags */
.lang-flags .flag {
  border: 2px solid transparent;
  background: none;
  padding: 2px 6px;
  border-radius: 8px;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}
.lang-flags .flag:hover {
  border-color: rgba(0,0,0,0.25);
}
.lang-flags .flag.active {
  border-color: rgba(0,0,0,0.6);
  background: #eef5ff;
}

#grid {
  display: grid;
  grid-template-columns: repeat(5, 80px);
  grid-template-rows: repeat(5, 80px);
  gap: 2px;
  justify-content: center;
  margin-top: 20px;
}

.cell {
  width: 80px;
  height: 80px;
  background: #fff;
  border: 1px solid #aaa;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.goal {
  background: #bdfcc9;
}

.guinea-pig {
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.guinea-pig svg {
  width: 60px;
  height: 60px;
}

#controls {
  margin-top: 20px;
}

button {
  margin: 5px;
  padding: 10px 15px;
  font-size: 16px;
  border: none;
  border-radius: 5px;
  background: #4CAF50;
  color: white;
  cursor: pointer;
  transition: all 0.3s;
}

button:hover {
  background: #45a049;
  transform: scale(1.05);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: #ccc;
}

button:disabled:hover {
  transform: none;
}

#program {
  margin-top: 15px;
  font-family: monospace;
  font-size: 14px;
}

/* Sidebar for program commands */
#playArea {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 20px;
  margin-top: 20px;
}

#programSidebar {
  width: 180px;
  background: #ffffffcc;
  backdrop-filter: blur(3px);
  border: 1px solid #ccc;
  border-radius: 10px;
  padding: 10px 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  text-align: left;
  display: flex;
  flex-direction: column;
  box-sizing: border-box; /* make explicit height include padding + border */
  overflow: auto; /* prevent content from forcing extra height */
  margin-top: 20px; /* requested spacing from the top */
}

#programSidebar.full-height {
  height: 100%;
}

#programList {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-content: flex-start;
}

#programSidebar::before {
  content: 'Program';
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  color: #222;
}

#programList {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cmd-item {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  border: 2px solid #888;
  border-radius: 8px;
  background: #fafafa;
  cursor: default;
  transition: background 0.25s, transform 0.25s, border-color 0.25s;
}

.cmd-item.active {
  background: #ffe78a;
  border-color: #e69500;
  transform: scale(1.08);
  box-shadow: 0 0 6px rgba(230,149,0,0.6);
}

.cmd-item:last-child:not(.active) {
  box-shadow: 0 0 3px rgba(0,0,0,0.15);
}

/* Dev solution sidebar */
#solutionSidebar {
  width: 180px;
  background: #ffffffcc;
  backdrop-filter: blur(3px);
  border: 1px solid #ccc;
  border-radius: 10px;
  padding: 10px 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  text-align: left;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  overflow: auto;
  margin-top: 20px;
}

#levelInfo {
  margin: 15px;
  font-size: 18px;
  font-weight: bold;
  color: #333;
}

#levelButtons {
  margin: 10px;
}

#levelButtons button {
  background: #2196F3;
}

#levelButtons button:hover {
  background: #0b7dda;
}

/* Tier selector */
.tiers {
  margin: 10px 0;
  display: flex;
  gap: 8px;
  justify-content: center;
}
.tier-btn {
  background: #9c27b0;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
}
.tier-btn.active {
  background: #6a0080;
}

.levels {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.levels button {
  min-width: 90px;
}

.obstacle {
  background: #555 !important;
}

.flower {
  background: #ffebcd;
}

/* Special tiles styling */
.tile-double {
  background: #d1eaff;
  border: 2px solid #2196F3;
  font-size: 26px;
}
.tile-skip {
  background: #ffe2d1;
  border: 2px solid #ff7043;
  font-size: 26px;
}
.tile-turn {
  background: #e6ffd6;
  border: 2px solid #66bb6a;
  font-size: 26px;
}

.explosion {
  animation: explode 0.6s ease-out;
  font-size: 40px;
}

@keyframes explode {
  0% {
    transform: scale(0.5);
    opacity: 1;
  }
  50% {
    transform: scale(1.5) rotate(180deg);
    opacity: 0.8;
  }
  100% {
    transform: scale(2) rotate(360deg);
    opacity: 0;
  }
}

.shake {
  animation: shake 0.3s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px) rotate(-5deg); }
  75% { transform: translateX(10px) rotate(5deg); }
}

/* ===== TUTORIAL MODAL ===== */

.tutorial-btn {
  background: #ff9800;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 20px;
  cursor: pointer;
  margin-left: 10px;
  transition: all 0.3s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}

.tutorial-btn:hover {
  background: #f57c00;
  transform: scale(1.1);
}

.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0,0,0,0.6);
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
}

.modal-content {
  background-color: #fff;
  border-radius: 15px;
  padding: 30px;
  max-width: 700px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    transform: translateY(-50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.close-btn {
  position: absolute;
  right: 20px;
  top: 20px;
  font-size: 32px;
  font-weight: bold;
  color: #999;
  cursor: pointer;
  transition: color 0.2s;
  line-height: 1;
}

.close-btn:hover {
  color: #333;
}

.modal-content h2 {
  margin-top: 0;
  color: #333;
  font-size: 28px;
  margin-bottom: 20px;
  text-align: center;
}

.tutorial-section {
  margin-bottom: 25px;
  padding-bottom: 20px;
  border-bottom: 1px solid #eee;
}

.tutorial-section:last-of-type {
  border-bottom: none;
}

.tutorial-section h3 {
  color: #4CAF50;
  font-size: 20px;
  margin-bottom: 15px;
  margin-top: 0;
}

.tutorial-section p {
  color: #555;
  line-height: 1.6;
  margin: 10px 0;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 15px;
  margin-top: 15px;
}

.control-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #f5f5f5;
  border-radius: 10px;
  border: 2px solid #e0e0e0;
}

.control-icon {
  font-size: 32px;
  min-width: 40px;
  text-align: center;
}

.control-desc strong {
  display: block;
  color: #333;
  margin-bottom: 4px;
  font-size: 15px;
}

.control-desc p {
  margin: 0;
  font-size: 13px;
  color: #666;
}

.tiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 15px;
}

.tile-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #fff8e1;
  border-radius: 10px;
  border: 2px solid #ffd54f;
}

.tile-icon {
  font-size: 28px;
  min-width: 36px;
  text-align: center;
}

.tile-desc strong {
  display: block;
  color: #333;
  margin-bottom: 4px;
  font-size: 14px;
}

.tile-desc p {
  margin: 0;
  font-size: 12px;
  color: #666;
}

.steps-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 15px;
}

.step-item {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 12px;
  background: #e3f2fd;
  border-radius: 10px;
  border-left: 4px solid #2196F3;
}

.step-number {
  background: #2196F3;
  color: white;
  font-weight: bold;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.step-item p {
  margin: 0;
  color: #333;
  font-size: 14px;
}

.tips-list {
  list-style: none;
  padding: 0;
  margin: 15px 0 0 0;
}

.tips-list li {
  padding: 10px;
  margin-bottom: 8px;
  background: #fff3e0;
  border-radius: 8px;
  border-left: 4px solid #ff9800;
  color: #333;
  font-size: 14px;
  line-height: 1.5;
}

.close-tutorial-btn {
  width: 100%;
  margin-top: 20px;
  padding: 12px;
  background: #4CAF50;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.3s;
}

.close-tutorial-btn:hover {
  background: #45a049;
}

/* ===== RESPONSIVE DESIGN ===== */

/* Tablets (portrait and landscape) */
@media screen and (max-width: 1024px) {
  body {
    padding: 15px;
  }

  h1 {
    gap: 10px;
    font-size: 24px;
  }

  h1 .logo {
    width: 50px;
    height: 50px;
  }

  #grid {
    grid-template-columns: repeat(5, 70px);
    grid-template-rows: repeat(5, 70px);
  }

  .cell {
    width: 70px;
    height: 70px;
    font-size: 20px;
  }

  .guinea-pig svg {
    width: 50px;
    height: 50px;
  }

  button {
    padding: 8px 12px;
    font-size: 15px;
  }

  #programSidebar,
  #solutionSidebar {
    width: 160px;
  }

  .cmd-item {
    width: 34px;
    height: 34px;
    font-size: 20px;
  }
}

/* Mobile phones (landscape) */
@media screen and (max-width: 768px) {
  body {
    padding: 10px;
  }

  h1 {
    flex-wrap: wrap;
    font-size: 20px;
    gap: 8px;
    margin: 10px 0;
  }

  h1 .logo {
    width: 40px;
    height: 40px;
  }

  .lang-flags {
    margin-left: 0 !important;
  }

  .lang-flags .flag {
    font-size: 18px;
    padding: 2px 4px;
  }

  #levelInfo {
    font-size: 16px;
    margin: 10px;
  }

  #subtitle {
    font-size: 14px;
    margin: 10px 0;
  }

  #grid {
    grid-template-columns: repeat(5, 60px);
    grid-template-rows: repeat(5, 60px);
    gap: 1px;
    margin-top: 15px;
  }

  .cell {
    width: 60px;
    height: 60px;
    font-size: 18px;
  }

  .guinea-pig {
    font-size: 22px;
  }

  .guinea-pig svg {
    width: 42px;
    height: 42px;
  }

  #playArea {
    flex-direction: column;
    gap: 15px;
    align-items: center;
  }

  #programSidebar,
  #solutionSidebar {
    width: 100%;
    max-width: 320px;
    margin-top: 0;
  }

  #controls {
    margin-top: 15px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 5px;
  }

  button {
    padding: 8px 10px;
    font-size: 14px;
    margin: 2px;
  }

  .tiers {
    flex-wrap: wrap;
    gap: 5px;
  }

  .tier-btn {
    padding: 6px 10px;
    font-size: 14px;
  }

  .levels button {
    min-width: 70px;
    font-size: 13px;
  }

  .cmd-item {
    width: 32px;
    height: 32px;
    font-size: 18px;
  }

  #legend {
    font-size: 11px !important;
  }

  #solutionSidebar h3 {
    font-size: 13px !important;
  }

  #solutionNote {
    font-size: 11px !important;
  }

  /* Tutorial responsive */
  .tutorial-btn {
    width: 36px;
    height: 36px;
    font-size: 18px;
    margin-left: 8px;
  }

  .modal {
    padding: 10px;
  }

  .modal-content {
    padding: 20px;
    max-height: 85vh;
  }

  .modal-content h2 {
    font-size: 22px;
    margin-bottom: 15px;
  }

  .tutorial-section h3 {
    font-size: 18px;
    margin-bottom: 12px;
  }

  .control-grid,
  .tiles-grid {
    grid-template-columns: 1fr;
  }

  .control-item,
  .tile-item {
    padding: 10px;
  }

  .control-icon {
    font-size: 28px;
    min-width: 36px;
  }

  .tile-icon {
    font-size: 24px;
    min-width: 32px;
  }

  .step-item {
    padding: 10px;
    gap: 12px;
  }

  .step-number {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }

  .tips-list li {
    font-size: 13px;
    padding: 8px;
  }
}

/* Mobile phones (portrait) - small screens */
@media screen and (max-width: 480px) {
  body {
    padding: 8px;
  }

  h1 {
    font-size: 18px;
  }

  h1 .logo {
    width: 35px;
    height: 35px;
  }

  .lang-flags .flag {
    font-size: 16px;
  }

  #levelInfo {
    font-size: 15px;
    margin: 8px;
  }

  #subtitle {
    font-size: 13px;
  }

  #grid {
    grid-template-columns: repeat(5, 50px);
    grid-template-rows: repeat(5, 50px);
    margin-top: 10px;
  }

  .cell {
    width: 50px;
    height: 50px;
    font-size: 16px;
  }

  .guinea-pig {
    font-size: 18px;
  }

  .guinea-pig svg {
    width: 36px;
    height: 36px;
  }

  button {
    padding: 7px 9px;
    font-size: 13px;
  }

  .tier-btn {
    padding: 5px 8px;
    font-size: 13px;
  }

  .levels button {
    min-width: 60px;
    font-size: 12px;
    padding: 6px 8px;
  }

  .cmd-item {
    width: 30px;
    height: 30px;
    font-size: 16px;
  }

  #programSidebar::before {
    font-size: 13px;
  }

  #legend {
    font-size: 10px !important;
    line-height: 1.2 !important;
  }

  .tile-double,
  .tile-skip,
  .tile-turn {
    font-size: 22px;
  }

  .explosion {
    font-size: 32px;
  }

  /* Tutorial for small phones */
  .tutorial-btn {
    width: 32px;
    height: 32px;
    font-size: 16px;
    margin-left: 5px;
  }

  .modal-content {
    padding: 15px;
  }

  .modal-content h2 {
    font-size: 20px;
  }

  .tutorial-section {
    margin-bottom: 20px;
    padding-bottom: 15px;
  }

  .tutorial-section h3 {
    font-size: 16px;
  }

  .control-desc strong,
  .tile-desc strong {
    font-size: 13px;
  }

  .control-desc p,
  .tile-desc p {
    font-size: 11px;
  }

  .step-item p {
    font-size: 12px;
  }

  .tips-list li {
    font-size: 11px;
  }

  .close-tutorial-btn {
    padding: 10px;
    font-size: 14px;
  }
}

/* Extra small devices (very small phones) */
@media screen and (max-width: 360px) {
  h1 {
    font-size: 16px;
  }

  h1 .logo {
    width: 30px;
    height: 30px;
  }

  #grid {
    grid-template-columns: repeat(5, 45px);
    grid-template-rows: repeat(5, 45px);
  }

  .cell {
    width: 45px;
    height: 45px;
    font-size: 14px;
  }

  .guinea-pig svg {
    width: 32px;
    height: 32px;
  }

  button {
    padding: 6px 8px;
    font-size: 12px;
  }

  .cmd-item {
    width: 28px;
    height: 28px;
    font-size: 15px;
  }

  .levels button {
    min-width: 55px;
    font-size: 11px;
  }
}

/* Landscape orientation optimization for mobile */
@media screen and (max-height: 600px) and (orientation: landscape) {
  body {
    padding: 5px;
  }

  h1 {
    margin: 5px 0;
    font-size: 16px;
  }

  h1 .logo {
    width: 30px;
    height: 30px;
  }

  #levelInfo {
    margin: 5px;
    font-size: 14px;
  }

  #subtitle {
    margin: 5px 0;
    font-size: 12px;
  }

  #grid {
    grid-template-columns: repeat(5, 55px);
    grid-template-rows: repeat(5, 55px);
    margin-top: 5px;
  }

  .cell {
    width: 55px;
    height: 55px;
  }

  #playArea {
    flex-direction: row;
    gap: 10px;
  }

  #programSidebar,
  #solutionSidebar {
    width: 140px;
    max-width: none;
  }

  #controls {
    margin-top: 10px;
  }

  button {
    padding: 5px 8px;
    font-size: 12px;
    margin: 2px;
  }

  .cmd-item {
    width: 28px;
    height: 28px;
    font-size: 16px;
  }

  .tiers {
    margin: 5px 0;
  }

  .tier-btn {
    padding: 4px 8px;
    font-size: 12px;
  }
}
