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

:root {
  --bg:           #0c0c12;
  --surface:      #14141c;
  --surface2:     #1a1a24;
  --border:       #26263a;
  --text:         #c4c4d8;
  --text-dim:     #60607a;
  --accent:       #5a5aff;
  --btn-bg:       #1c1c2a;
  --btn-hover:    #24243a;
  --active-ring:  #6868ff;
}

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Courier New', Courier, monospace;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── header ── */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

h1 {
  font-size: 0.95rem;
  font-weight: normal;
  letter-spacing: 0.08em;
  color: var(--text);
}

.header-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ── buttons ── */

button {
  background: var(--btn-bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 0.8rem;
  padding: 4px 12px;
  cursor: pointer;
  border-radius: 3px;
  line-height: 1.6;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
  -webkit-tap-highlight-color: transparent;
}

button:hover {
  background: var(--btn-hover);
  border-color: #44446a;
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button.active {
  border-color: var(--active-ring);
  color: #a0a0ff;
}

/* ── speed control ── */

.speed-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}

.speed-wrap button {
  padding: 4px 8px;
  min-width: 26px;
}

#speed-label {
  font-size: 0.78rem;
  color: var(--text-dim);
  min-width: 28px;
  text-align: center;
}

/* ── main layout ── */

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

/* ── palette sidebar ── */

.palette {
  width: 148px;
  min-width: 148px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 10px 8px 12px;
  gap: 0;
  overflow-y: auto;
  flex-shrink: 0;
}

#palette-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.el-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.78rem;
  color: var(--text);
  text-align: left;
  width: 100%;
  transition: background 0.1s, border-color 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.el-btn:hover {
  background: var(--btn-hover);
  border-color: var(--border);
}

.el-btn.active {
  background: var(--btn-bg);
  border-color: var(--active-ring);
}

.el-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.el-swatch {
  display: inline-block;
  width: 13px;
  height: 13px;
  border-radius: 2px;
  flex-shrink: 0;
}

.el-name {
  flex: 1;
}

.el-key {
  color: var(--text-dim);
  font-size: 0.7rem;
  flex-shrink: 0;
}

/* ── brush control ── */

.brush-control {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 0 2px;
}

.brush-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-dim);
}

#brush-size {
  width: 100%;
  cursor: pointer;
  accent-color: var(--accent);
  height: 4px;
}

/* ── keyboard hint ── */

.key-hints {
  margin-top: 14px;
  padding: 0 2px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.68rem;
  color: var(--text-dim);
  line-height: 1.5;
}

.key-hints span {
  display: flex;
  justify-content: space-between;
}

.key-hints .k {
  color: #484860;
  letter-spacing: 0.03em;
}

/* ── canvas area ── */

.canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #07070c;
  overflow: auto;
  padding: 16px;
  min-width: 0;
}

#sim-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
  border: 1px solid var(--border);
  /* scale up on large screens, shrink on small */
  max-width: 100%;
  max-height: calc(100vh - 100px);
  width: 600px;
  height: 450px;
}

/* ── footer ── */

footer {
  padding: 10px 18px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-dim);
  flex-shrink: 0;
}

footer a {
  color: var(--text-dim);
  text-decoration: none;
}

footer a:hover {
  color: var(--text);
}

/* ── mobile ── */

@media (max-width: 640px) {
  main {
    flex-direction: column;
    overflow: visible;
  }

  .palette {
    width: 100%;
    min-width: unset;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    padding: 8px;
    gap: 6px;
    overflow-y: visible;
  }

  #palette-list {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
  }

  .el-btn {
    flex-direction: column;
    padding: 6px 8px;
    gap: 3px;
    align-items: center;
    font-size: 0.65rem;
    min-width: 48px;
  }

  .el-key { display: none; }

  .brush-control {
    margin-top: 0;
    min-width: 120px;
  }

  .key-hints { display: none; }

  .canvas-wrap {
    padding: 8px;
  }

  #sim-canvas {
    max-height: none;
    width: 100%;
    height: auto;
    aspect-ratio: 4/3;
  }
}
