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

html, body { height: 100%; }

body {
  font-family: 'Courier New', monospace;
  background: #fff;
  color: #111;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

header {
  background: #111;
  color: #fff;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 2px;
  text-transform: uppercase;
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-link {
  color: #aaa;
  text-decoration: none;
  font-size: 12px;
  letter-spacing: 1px;
  border: 1px solid #444;
  padding: 3px 10px;
  transition: color 0.15s, border-color 0.15s;
}
.nav-link:hover {
  color: #fff;
  border-color: #fff;
}

/* ── Main two-column area ── */
main {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.panel-header {
  background: #111;
  color: #fff;
  padding: 4px 10px;
  font-size: 12px;
  flex-shrink: 0;
}

/* ── LEFT: Program ── */
#program-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

#editor {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#line-numbers {
  padding: 10px 8px;
  background: #f7f7f7;
  border-right: 1px solid #ddd;
  color: #aaa;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.5;
  text-align: right;
  user-select: none;
  white-space: pre;
  overflow: hidden;
  flex-shrink: 0;
  min-width: 2.5em;
}

#program {
  flex: 1;
  border: none;
  padding: 10px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  resize: none;
  background: #fff;
  outline: none;
  line-height: 1.5;
  min-height: 0;
  overflow-y: scroll;
}

/* ── Resize handle ── */
#resize-handle {
  width: 5px;
  cursor: col-resize;
  background: #111;
  flex-shrink: 0;
  position: relative;
}

#resize-handle::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: -3px; right: -3px;
}

#resize-handle:hover, #resize-handle.dragging {
  background: #555;
}

/* ── RIGHT: stacked panels ── */
#right-panel {
  width: 340px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── 2D Tape grid ── */
#tape-panel {
  flex-shrink: 0;
  border-bottom: 2px solid #111;
}

#tape-scroll {
  overflow: auto;
  padding: 6px 0;
  background: #fff;
}

#tape-inner {
  display: grid;
  padding: 4px 12px 8px;
  justify-content: center;
}

.tape-cell {
  width: 28px;
  height: 28px;
  outline: 1px solid #bbb;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  background: #fff;
  position: relative;
}

.tape-cell.head {
  background: #111;
  color: #fff;
  outline: 2px solid #111;
  z-index: 1;
}

.tape-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  color: #999;
  user-select: none;
}

.row-label {
  justify-content: flex-end;
  padding-right: 4px;
  height: 28px;
}

.col-label {
  height: 16px;
}

/* Config inputs */
#config-panel {
  flex-shrink: 0;
  border-bottom: 1px solid #111;
}

#input-area {
  padding: 8px 10px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.input-row label {
  font-size: 12px;
  width: 68px;
  flex-shrink: 0;
  color: #555;
}

.input-row input {
  flex: 1;
  border: 1px solid #aaa;
  padding: 3px 6px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  background: #fff;
  outline: none;
  min-width: 0;
}

.input-row input:focus {
  border-color: #111;
  background: #fffde7;
}

/* Status bar */
#status-bar {
  background: #111;
  color: #fff;
  padding: 5px 10px;
  font-size: 11px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  flex-shrink: 0;
}

.status-item { color: #aaa; }
.status-item span { color: #fff; font-weight: bold; }

#status-msg { margin-left: auto; font-size: 10px; color: #aaa; }
#status-msg.ok     { color: #6d6; }
#status-msg.err    { color: #f66; }
#status-msg.brk    { color: #fc0; }
#status-msg.halted { color: #6cf; }

/* Controls */
#controls-panel {
  background: #f0f0f0;
  border-top: 1px solid #111;
  border-bottom: 1px solid #111;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  flex-shrink: 0;
}

button {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  font-weight: bold;
  border: none;
  border-right: 1px solid #ccc;
  padding: 8px 12px;
  cursor: pointer;
  background: #f0f0f0;
  color: #111;
  transition: background 0.1s, color 0.1s;
}

button:hover { background: #111; color: #fff; }
button:disabled { color: #aaa; cursor: default; }
button:disabled:hover { background: #f0f0f0; color: #aaa; }
button.active { background: #111; color: #fff; }

#speed-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  font-size: 11px;
  color: #555;
}

#speed { width: 70px; accent-color: #111; }

#btn-share.copied { background: #111; color: #6d6; }

/* ── History ── */
#history-panel {
  flex: 1;
  overflow-y: auto;
  background: #fff;
  min-height: 0;
}

#history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

#history-table th {
  background: #111;
  color: #fff;
  padding: 3px 8px;
  text-align: left;
  position: sticky;
  top: 0;
  font-size: 11px;
  font-weight: normal;
}

#history-table td {
  padding: 2px 8px;
  border-bottom: 1px solid #eee;
  color: #333;
}

#history-table tr:nth-child(even) td { background: #fafafa; }
#history-table tr.current-step td { background: #fffde7; color: #111; font-weight: bold; }
