/* -------------------- General Body Styles -------------------- */
* {
  box-sizing: border-box;
}

body {
  margin: 2em;
  font-family: Arial, sans-serif;
  font-size: 0.9em;
  color: #222;
}

h1 {
  text-align: center;
  margin-bottom: 1em;
}

/* -------------------- Main Grid Layout -------------------- */
.app-layout {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)); /* 3 equal columns */
  gap: 20px;
  width: 100%;
  align-items: start;
  justify-items: stretch;
}

.app-layout > div {
  min-width: 0;
  overflow: visible;
  height: 100%;
}

/* Responsive resizing: 3 → 2 → 1 columns */
@media (max-width: 1100px) {
  .app-layout {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 700px) {
  .app-layout {
    grid-template-columns: 1fr;
  }
}

/* -------------------- Fieldset Styles -------------------- */
fieldset {
  width: 100%;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  height: 100%;
}

legend {
  font-weight: bold;
}

/* -------------------- Tables -------------------- */
fieldset table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 5px;
}

fieldset table th,
fieldset table td {
  padding: 6px 10px;
  text-align: left;
}

table.zebra tr:nth-child(even) {
  background: #f9f9f9;
}

/* -------------------- Textareas -------------------- */
textarea {
  resize: none;
  padding: 6px;
  min-height: 100px;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-family: inherit;
  width: 100%;
  min-width: 0;
}

#hist,
#msgbox {
  height: 80%;
  margin-top: 8px;
}

/* -------------------- Buttons -------------------- */
.center-buttons {
  text-align: center;
  margin-top: auto;
  padding-top: 10px;
}

button,
input[type="submit"],
#restartTutorialBtn,
#finishBtn,
.nextBtn,
.backBtn {
  padding: 6px 12px;
  border: 1px solid #999;
  background: #f2f2f2;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
}

button:hover,
input[type="submit"]:hover,
#restartTutorialBtn:hover,
#finishBtn:hover,
.nextBtn:hover,
.backBtn:hover {
  background: #e0e0e0;
}

/* -------------------- Manual Memory Access -------------------- */
#memory-access fieldset {
  overflow-x: auto;
}

#memory-access table {
  width: 100%;
}

.manual-access input,
.manual-access select {
  width: 100%;
  box-sizing: border-box;
}

/* -------------------- P5 Canvas -------------------- */
#p5canvas {
  width: 100%;
  height: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  grid-column: span 2; /* take 2 columns on wide screens */
}

#p5canvas canvas {
  width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
  max-width: 100%;
}

/* Force it to take full row when fewer columns */
@media (max-width: 1100px) {
  #p5canvas {
    grid-column: span 2; /* covers both columns in 2-col layout */
  }
}

@media (max-width: 700px) {
  #p5canvas {
    grid-column: 1 / -1; /* fills entire width on 1-col layout */
  }
}

/* -------------------- Help Button -------------------- */
.section-help {
  background: #e0e0ff;
  border: 1px solid #666;
  border-radius: 50%;
  width: 20px;
  height: 20Spx;
  font-weight: bold;
  cursor: pointer;
  margin-left: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1/1;
}

/* -------------------- Accessibility (Screen-reader-only) -------------------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* -------------------- Modals -------------------- */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,0.4);
  overflow-y: auto;
}

.modal-content {
  background: #fff;
  margin: 10% auto;
  padding: 20px;
  border-radius: 8px;
  width: 400px;
  max-width: 95%;
  border: 1px solid #ccc;
  color: inherit;
  font-family: inherit;
  position: relative;
}

.close {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 22px;
  font-weight: bold;
  cursor: pointer;
}

/* -------------------- Modal Buttons -------------------- */
#restartTutorialBtn,
#finishBtn,
.nextBtn,
.backBtn {
  margin-top: 10px;
}

/* -------------------- Responsive Modals -------------------- */
@media (max-width: 600px) {
  .modal-content {
    width: 90%;
    margin: 15% auto;
    padding: 15px;
  }

  .close {
    font-size: 1.5em;
  }
}
