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

:root {
  --bg: #ffffff;
  --fg: #000000;
  --muted: #888;
  --faint: #e0e0e0;
  --fainter: #f4f4f4;
  --serif: 'EB Garamond', Georgia, serif;
  --mono: 'DM Mono', monospace;
}

html, body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

nav {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 14px 30px 14px;
  border-bottom: 1px solid var(--faint);
  flex-shrink: 0;
}

.nav-links {
  display: flex;
  gap: 28px;
  font-family: 'Pixelify Sans', monospace;
  font-size: 16px;
  letter-spacing: .04em;
}

.nav-links a { color: var(--fg); text-decoration: none; transition: color .15s; }
.nav-links a.muted { color: var(--muted); }
.nav-links a:hover { color: var(--fg); }

.page-header {
  padding: 16px 30px;
  border-bottom: 1px solid var(--faint);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  flex-shrink: 0;
}

.page-title {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 36px;
  line-height: 1.1;
  letter-spacing: -.02em;
}

.page-desc {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .04em;
  line-height: 1.8;
  max-width: 240px;
  text-align: right;
}

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  flex: 1;
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--faint);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
}

.main {
  display: grid;
  grid-template-columns: 4fr 2fr;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.col-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--faint);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  min-height: 44px;
}

.col-header:first-child { border-right: 1px solid var(--faint); }

.col-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--faint);
  flex-shrink: 0;
  transition: background .2s;
}
.col-dot.on { background: var(--fg); }

/* Zoom controls */
.zoom-controls {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
}
.zoom-btn {
  width: 22px; height: 22px;
  border: 1px solid var(--faint);
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  border-radius: 0;
  transition: all .12s;
  line-height: 1;
}
.zoom-btn:hover { border-color: var(--fg); background: var(--fainter); }
.zoom-label {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  min-width: 34px;
  text-align: center;
  letter-spacing: .04em;
}

.canvas-area {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  overflow: hidden;
  background-image:
    linear-gradient(var(--faint) 1px, transparent 1px),
    linear-gradient(90deg, var(--faint) 1px, transparent 1px);
  background-size: 20px 20px;
  background-color: var(--fainter);
  border-right: 1px solid var(--faint);
  position: relative;
}

/* Zoomable wrapper inside canvas-area */
.zoom-viewport {
  width: 100%; height: 100%;
  overflow: hidden;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.zoom-content {
  transform-origin: center center;
  transition: transform .15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.code-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.palette-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 10px 24px;
  border-bottom: 1px solid var(--faint);
  align-items: center;
  min-height: 44px;
  flex-shrink: 0;
}

.pal-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-right: 4px;
}

.swatch {
  width: 14px; height: 14px;
  border: 1px solid rgba(0,0,0,0.12);
  cursor: pointer;
  transition: transform .1s;
  position: relative;
}
.swatch:hover { transform: scale(1.35); z-index: 1; }
.swatch::after {
  content: '✎';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  opacity: 0;
  color: white;
  text-shadow: 0 0 2px rgba(0,0,0,.8);
  transition: opacity .1s;
}
.swatch:hover::after { opacity: 1; }

/* Color picker popover */
.color-picker-pop {
  position: fixed;
  z-index: 200;
  background: var(--bg);
  border: 1px solid var(--fg);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 4px 4px 0 var(--faint);
  min-width: 180px;
}
.cp-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
#cp-native {
  width: 36px; height: 36px;
  border: 1px solid var(--faint);
  padding: 2px;
  cursor: pointer;
  border-radius: 0;
  background: none;
  flex-shrink: 0;
}
#cp-hex-input {
  flex: 1;
  padding: 6px 8px;
  font-family: var(--mono);
  font-size: 12px;
  border: 1px solid var(--faint);
  border-radius: 0;
  color: var(--fg);
  background: var(--bg);
  outline: none;
  transition: border-color .15s;
}
#cp-hex-input:focus { border-color: var(--fg); }
.cp-btns {
  display: flex;
  gap: 6px;
}
.cp-btns button {
  flex: 1;
  padding: 5px 10px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid var(--faint);
  border-radius: 0;
  background: var(--bg);
  color: var(--muted);
  transition: all .12s;
}
.cp-btns button:hover { border-color: var(--fg); color: var(--fg); }
.cp-btns .cp-primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.cp-btns .cp-primary:hover { opacity: .78; }

.export-panel {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-height: 0;
}

.fmt-row { display: flex; border: 1px solid var(--faint); width: fit-content; flex-shrink: 0; }

.fmt-btn {
  padding: 6px 14px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
  border: none;
  border-right: 1px solid var(--faint);
  border-radius: 0;
  background: var(--bg);
  color: var(--muted);
  transition: all .15s;
}
.fmt-btn:last-child { border-right: none; }
.fmt-btn.active { background: var(--fg); color: var(--bg); }
.fmt-btn:hover:not(.active) { background: var(--fainter); color: var(--fg); }

textarea {
  width: 100%;
  flex: 1;
  min-height: 0;
  font-size: 11px;
  font-family: var(--mono);
  line-height: 1.65;
  background: var(--fainter);
  border: 1px solid var(--faint);
  border-radius: 0;
  padding: 14px 16px;
  resize: none;
  color: var(--fg);
  outline: none;
  transition: border-color .15s;
}
textarea:focus { border-color: var(--fg); }
textarea.code-edited { border-color: #aaa; background: #fffdf7; }

.bottom-row { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }

.copy-btn {
  padding: 8px 18px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid var(--faint);
  border-radius: 0;
  background: var(--bg);
  color: var(--muted);
  transition: all .15s;
}
.copy-btn:hover { border-color: var(--fg); color: var(--fg); }
.copy-btn:active { background: var(--fainter); }
.copy-btn.ok { border-color: var(--fg); color: var(--fg); }

.info-chip {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: .06em;
}

.code-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .08em;
  color: var(--faint);
  text-transform: uppercase;
}

/* Sidebar */
.field-group { display: flex; flex-direction: column; gap: 8px; }

.field-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.field-label b {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--fg);
  letter-spacing: 0;
  text-transform: none;
}

.field-value {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--fg);
  letter-spacing: 0;
  text-transform: none;
}

.field-hint {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--muted);
  letter-spacing: .03em;
  line-height: 1.4;
}

/* removed col-num-input */

.dim-row { display: grid; grid-template-columns: 1fr 12px 1fr; gap: 6px; align-items: center; }
.dim-sep { text-align: center; font-size: 13px; color: var(--muted); font-family: var(--mono); }

input[type=number] {
  width: 100%;
  padding: 7px 10px;
  font-size: 14px;
  font-family: var(--mono);
  background: var(--bg);
  border: 1px solid var(--faint);
  border-radius: 0;
  color: var(--fg);
  -moz-appearance: textfield;
  transition: border-color .15s;
  text-align: center;
}
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; }
input[type=number]:focus { outline: none; border-color: var(--fg); }

input[type=range] {
  width: 100%;
  height: 1px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--faint);
  outline: none;
  cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--fg);
  cursor: pointer;
  transition: transform .12s;
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.2); }

.upload-zone {
  border: 1px dashed var(--faint);
  padding: 20px 12px;
  text-align: center;
  cursor: pointer;
  position: relative;
  transition: border-color .15s;
}
.upload-zone:hover { border-color: var(--fg); }
.upload-zone.has-file { border-style: solid; border-color: var(--fg); }
.upload-zone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.upload-zone p { font-family: var(--mono); font-size: 10px; color: var(--muted); letter-spacing: .04em; }
.upload-arrow { font-size: 20px; line-height: 1; margin-bottom: 8px; display: block; color: var(--muted); }
.upload-zone:hover .upload-arrow,
.upload-zone.has-file .upload-arrow { color: var(--fg); }
.filename { font-family: var(--mono); font-size: 10px; color: var(--fg); margin-top: 4px; display: none; }

.divider { height: 1px; background: var(--faint); }

.btn-group { display: flex; flex-direction: column; gap: 8px; margin-top: auto; }

button.btn {
  width: 100%;
  padding: 9px 14px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid var(--faint);
  border-radius: 0;
  background: var(--bg);
  color: var(--muted);
  transition: all .15s;
}
button.btn:hover { border-color: var(--fg); color: var(--fg); }
button.btn:active { background: var(--fainter); }
button.btn:disabled { opacity: .25; cursor: not-allowed; }

button.btn.primary {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}
button.btn.primary:hover { opacity: .78; }
button.btn.primary:disabled { opacity: .18; cursor: not-allowed; }

/* Crop & canvas */
.empty {
  text-align: center;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .06em;
  line-height: 2;
}
.empty-grid {
  display: grid;
  grid-template-columns: repeat(4, 8px);
  gap: 5px;
  margin: 0 auto 16px;
  width: fit-content;
}
.empty-grid span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--faint);
}

#pixel-canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  box-shadow: 0 0 0 1px var(--faint);
  display: block;
}

.crop-wrap { position: relative; display: inline-block; user-select: none; max-width: 100%; max-height: 100%; }
#src-img { display: block; max-width: 100%; max-height: 260px; }
#crop-overlay { position: absolute; inset: 0; cursor: move; }
#crop-box { position: absolute; border: 1px solid var(--fg); pointer-events: none; }

footer {
  border-top: 1px solid var(--faint);
  padding: 16px 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
footer span { font-family: var(--mono); font-size: 10px; color: var(--muted); letter-spacing: .06em; }
footer a { color: var(--muted); text-decoration: none; }
footer a:hover { color: var(--fg); }

/* ── MOBILE ── */
@media (max-width: 700px) {
  html, body {
    height: auto;
    overflow: auto;
  }

  nav { padding: 12px 16px; }

  .page-header {
    padding: 12px 16px;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  .page-title { font-size: 26px; }
  .page-desc { text-align: left; max-width: none; }

  .app {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--faint);
    padding: 16px;
    overflow-y: visible;
    height: auto;
  }

  .main {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 0;
  }

  /* Preview section */
  .col-header { padding: 10px 16px;}
  .col-header:first-child { border-right: none; border-bottom: 1px solid var(--faint); }

  .canvas-area {
    height: 320px;
    border-right: none;
    border-bottom: 1px solid var(--faint);
  }

  /* Code section */
  .code-col {
    height: auto;
    min-height: 0;
  }

  .palette-bar { padding: 10px 16px; }

  .export-panel {
    padding: 16px;
    height: auto;
  }

  textarea {
    min-height: 200px;
    flex: none;
    height: 200px;
  }

  .code-empty {
    height: 80px;
    flex: none;
  }

  footer { padding: 14px 16px; }

  .zoom-controls { gap: 3px; }
  .zoom-label { min-width: 28px; font-size: 9px; }
}