:root {
  --c64-beige: #d8cfb5;
  --c64-panel: #e3dac2;

  --ink: #2b2b2b;
  --muted: #5a574e;

  --border: rgba(0,0,0,0.15);
  --header-control-width: 120px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--c64-beige);
  color: var(--ink);
}

.img-pixel {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.page-centered {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 40px 24px;
}

.page-top {
  min-height: 100vh;
  padding: 40px 24px;

  display: flex;
  justify-content: center;   /* horizontal centre */
  align-items: flex-start;   /* stick to top */
}

.hero {
  width: min(900px, 100%);
  background: var(--c64-panel);
  border-radius: 18px;
  padding: 48px 36px;
  text-align: center;
  border: 1px solid var(--border);
  box-shadow:
    inset 0 2px 4px rgba(255,255,255,0.5),
    0 10px 25px rgba(0,0,0,0.08);
}

.logo {
  width: min(720px, 100%);
  height: auto;
  display: block;
  margin: 0 auto;
}

.tagline {
  margin-top: 24px;
  font-size: 1.1rem;
  color: var(--muted);
}

.actions {
  margin-top: 32px;
}

.primary-btn {
  background: #2b2b2b;
  color: white;
  border: none;
  padding: 14px 28px;
  font-size: 1rem;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.05s ease, box-shadow 0.15s ease;
}

.primary-btn:hover {
  box-shadow: 0 6px 18px rgba(0,0,0,0.2);
}

.primary-btn:active {
  transform: translateY(1px);
}

.upload { display: flex; gap: 12px; justify-content: center; align-items: center; flex-wrap: wrap; }

.file-input {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.35);
}

.result {
  margin-top: 24px;
  text-align: left;
  background: rgba(255,255,255,0.45);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  overflow: auto;
  max-width: 100%;
}

.error {
  margin-top: 18px;
  color: #8a1f1f;
  font-weight: 600;
}

/* Viewer layout */
.viewer {
  width: min(1100px, 100%);
  background: var(--c64-panel);
  border-radius: 18px;
  border: 1px solid var(--border);
  box-shadow:
    inset 0 2px 4px rgba(255,255,255,0.5),
    0 10px 25px rgba(0,0,0,0.08);
  overflow: hidden;
}

.viewer-topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
}

.viewer-logo {
  width: 180px; /* small logo top-right */
  height: auto;
  display: block;
}

.viewer-panel {
  background: rgba(255,255,255,0.15);
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 12px 12px;
  padding: 18px;
}

.viewer-toolbar-center {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 42px;
}

.viewer-nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.viewer-nav-btn {
  min-width: var(--header-control-width);
  text-align: center;
  background: rgba(255,255,255,0.20);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 16px;
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
  color: inherit;
}

.viewer-nav-btn:hover {
  background: rgba(255,255,255,0.28);
}

.sprite-actions {
  display: flex;
  justify-content: center;
  align-items: center;
}

.sprite-actions[hidden] {
  display: none !important;
}

.viewer-topbar-simple {
  grid-template-columns: auto 1fr auto;
}

.sheet-wrap {
  max-height: 70vh;
  overflow: auto;
  padding: 12px;

  background: rgba(255,255,255,0.10);
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 12px 12px;

  text-align: center;
}

.sheet-img {
  display: inline-block;
  height: auto;
  max-width: none;   /* remove width constraint */
}

.sheet-stage {
  position: relative;
  display: inline-block;
  line-height: 0;
}

.sheet-grid {
  position: absolute;
  inset: 10px;
  display: grid;
  grid-template-columns: repeat(16, 48px);
  grid-auto-rows: 42px;
  gap: 6px;
  pointer-events: none;
}

.sprite-hit {
  pointer-events: auto;
  width: 48px;
  height: 42px;
  padding: 0;
  margin: 0;
  border: 2px solid transparent;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
}

.sprite-hit:hover {
  border-color: rgba(255, 255, 255, 0.45);
}

.sprite-hit.is-selected {
  border-color: #d11f1f;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.35);
}

.sprite-hit.is-drag-preview {
  border-color: rgba(209, 31, 31, 0.55);
  background: rgba(209, 31, 31, 0.12);
}



/* =========================
   Menu bar (generic)
   ========================= */

.menu-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.menu {
  position: relative;
}

.menu > button {
  min-width: var(--header-control-width);
  text-align: center;
}

.menu-btn {
  background: rgba(255,255,255,0.20);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 4px;
  cursor: pointer;
  font-weight: 700;
}

.menu-btn:hover {
  background: rgba(255,255,255,0.28);
}

.menu-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 6px 8px;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
  font-weight: 700;
}

.menu-item:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.menu-item:hover {
  background: rgba(255,255,255,0.20);
}

.menu-check {
  visibility: hidden;
  font-weight: 700;
}

.menu-items {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 170px;
  background: var(--c64-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.12);
  z-index: 50;
}

.menu.open .menu-items {
  display: block;
}

/* =========================
   Dialogs (generic)
   ========================= */

.dlg {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0;
  background: var(--c64-panel);
  width: min(520px, calc(100vw - 40px));
}

.dlg::backdrop {
  background: rgba(0,0,0,0.35);
}

.dlg-form {
  padding: 18px 18px 16px 18px;
}

.dlg-title {
  margin: 0 0 8px 0;
  font-size: 18px;
}

.dlg-text {
  margin: 0 0 14px 0;
  color: var(--muted);
  line-height: 1.4;
}

.dlg-file {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.25);
}

.dlg-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.btn {
  display: inline-block;
  color: inherit;
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.20);
  cursor: pointer;
  font-weight: 800;
}

.btn:hover {
  background: rgba(255,255,255,0.28);
}

.btn.primary {
  background: rgba(0,0,0,0.75);
  color: #fff;
  border-color: rgba(0,0,0,0.55);
}

.btn.primary:hover {
  background: rgba(0,0,0,0.85);
}

.menu-item-check {
  position: relative;
  padding-left: 34px; /* room for tick */
}

.menu-item-check[aria-checked="true"]::before {
  content: "✓";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-weight: 900;
  line-height: 1;
}

.menu-sep {
  height: 1px;
  margin: 8px 6px;
  background: rgba(0,0,0,0.10);
}

.menu-sep-title {
  padding: 6px 10px 4px 10px;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.menu-colour {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.menu-colour-label {
  flex: 1;
}

.swatch {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  border: 1px solid rgba(0,0,0,0.25);
  box-shadow: inset 0 1px 1px rgba(255,255,255,0.4);
}

/* 2 x 8 colour picker grid */
.palette-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.palette-swatch {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.20);
  cursor: pointer;
  box-shadow: 0 10px 18px rgba(0,0,0,0.08), inset 0 1px 1px rgba(255,255,255,0.35);
}

.palette-swatch:hover {
  transform: translateY(-1px);
}

.offset-control {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 8px 10px;
}

.offset-btn {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255,255,255,0.20);
  cursor: pointer;
  font-weight: 800;
  font-size: 18px;
  line-height: 1;
}

.offset-btn:hover {
  background: rgba(255,255,255,0.28);
}

.offset-value {
  min-width: 32px;
  text-align: center;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.admin-banner {
  margin: 0 0 16px 0;
  padding: 10px 14px;
  border: 1px solid #c99a00;
  background: #fff4cc;
  color: #5c4700;
  font-weight: 600;
}

.maintenance-message {
  text-align: center;
}

/* =========================
   Configure
   ========================= */

.config-sprite-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 14px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
  max-height: 440px;
  overflow-y: auto;
}

.config-sprite {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  cursor: pointer;
  box-sizing: border-box;
}

.config-sprite:hover {
  border-color: rgba(255,255,255,0.25);
}

.config-sprite.is-selected {
  border-color: rgba(209, 31, 31, 0.45);
  background: rgba(209, 31, 31, 0.08);
}

.config-sprite.active {
  border-color: #d11f1f;
  background: rgba(209, 31, 31, 0.14);
}

.config-sprite-stage {
  width: 96px;
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.06);
  border-radius: 6px;
  overflow: hidden;
}

.config-sprite-img {
  display: block;
  max-width: none;
}

.config-sprite-meta {
  font-size: 0.8rem;
  line-height: 1.2;
  opacity: 0.85;
}

.config-workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  padding: 18px;
}

.compose-workspace {
  grid-template-columns: 280px 1fr;
  align-items: start;
}

.config-preview-box {
  min-height: 260px;
  padding: 16px;
  background: rgba(255,255,255,0.08);
  border-radius: 8px;
}

.config-preview-stage {
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.config-preview-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.config-preview-img {
  display: block;
  max-width: none;
}

.config-preview-meta {
  font-size: 0.9rem;
  opacity: 0.9;
}

.config-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 260px;
}

.config-check {
  display: flex;
  align-items: center;
  gap: 10px;
}

.config-field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.config-form.is-inheriting .config-field-group,
.config-form.is-inheriting .config-check:not(:first-child) {
  opacity: 0.65;
}

.config-move-panel {
  margin-bottom: 18px;
}

.config-move-panel h3 {
  margin-top: 0;
  margin-bottom: 10px;
}

.config-move-grid {
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 8px;
  align-items: center;
  justify-content: start;
}

.config-move-grid .btn {
  min-width: 88px;
}

.config-move-grid .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.config-colour-btn {
  width: 180px;
  max-width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 400;
  text-align: left;
  cursor: pointer;
  margin-left: 2px;
}

.config-colour-btn:hover {
  background: transparent;
}

.config-colour-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.config-colour-label {
  font: inherit;
  font-weight: 400;
}

/* =========================
   Compose
   ========================= */

.compose-placeholder {
  opacity: 0.6;
}

.compose-left {
  width: 260px;
  flex-shrink: 0;
}

.compose-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.compose-stage {
  width: 768px;
  height: 672px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 6px;
}

.compose-grid {
  display: grid;
  grid-template-columns: repeat(4, 96px);
  grid-template-rows: repeat(4, 84px);
  gap: 0;
}

.compose-cell {
  width: 96px;
  height: 84px;
  border: 1px dashed rgba(0,0,0,0.2);
  background: rgba(0,0,0,0.03);
  position: relative;
  overflow: hidden;
}

.compose-cell-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 96px;
  height: 84px;
  display: block;
}

.compose-cell.is-filled {
  border-style: solid;
  border-color: rgba(0,0,0,0.25);
}

.compose-left-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.compose-edit-status {
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255,255,255,0.10);
  font-weight: 600;
}

.compose-stack-panel {
  min-height: 160px;
}

.compose-stack-meta {
  margin-bottom: 10px;
  font-weight: 700;
}

.compose-stack-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.compose-stack-item {
  width: 100%;
  display: block;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.compose-stack-item:hover {
  background: rgba(255,255,255,0.16);
}

.compose-cell.is-selected {
  border-style: solid;
  border-color: #d11f1f;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.35);
}

.compose-stack-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.compose-stack-item.is-selected {
  border-color: #d11f1f;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.35);
}

.compose-export-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.compose-export-size-label {
  font-weight: 700;
}

.compose-export-bar select {
  width: 84px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  color: inherit;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary:disabled {
  background: rgba(0,0,0,0.28);
  color: rgba(255,255,255,0.7);
  border-color: rgba(0,0,0,0.18);
  box-shadow: none;
}

.flash-wrap {
  padding: 14px 18px 0 18px;
}

.flash {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-weight: 700;
}

.flash-success {
  background: #e7f5df;
  color: #255c1f;
  border-color: rgba(37,92,31,0.25);
}

.browse-panel {
  text-align: left;
}

.browse-page-title {
  margin: 0;
  font-size: 1.6rem;
}

.browse-page-subtitle {
  margin: 4px 0 0 0;
  color: var(--muted);
}

.browse-breadcrumbs {
  margin-bottom: 18px;
  font-weight: 800;
}

.browse-breadcrumbs a {
  color: inherit;
  text-decoration: none;
}

.browse-breadcrumbs a:hover {
  text-decoration: underline;
}

.browse-breadcrumbs span {
  margin: 0 6px;
  color: var(--muted);
}

.browse-summary {
  margin: 0 0 18px 0;
  font-style: italic;
  font-weight: 400;
  color: var(--muted);
}

.browse-list {
  margin-top: 18px;
  display: grid;
  gap: 10px;
}

.browse-row {
  display: block;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.25);
  color: inherit;
  text-decoration: none;
  font-weight: 800;
}

.browse-row:hover {
  background: rgba(255,255,255,0.38);
}

.browse-empty {
  color: var(--muted);
}

.browse-download-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 0;
  background: rgba(255,255,255,0.18);
  margin-bottom: 22px;
}

.browse-file-row {
  display: block;
  padding: 7px 14px;
  color: inherit;
  text-align: left;
  text-decoration: none;
  font-weight: 400;
}

.browse-file-row:hover {
  background: rgba(255,255,255,0.28);
}

.browse-download-all {
  font-weight: 800;
}

.browse-preview-full {
  width: 100%;
  text-align: left;
}

.browse-preview-full img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.help-panel {
  text-align: left;
}

.help-toc {
  margin-bottom: 20px;
  font-size: 0.9rem;
  color: var(--muted);
}

.help-toc a {
  color: inherit;
  text-decoration: none;
  font-weight: 400;
}

.help-toc a:hover {
  text-decoration: underline;
}

.help-toc span {
  margin: 0 8px;
  color: var(--muted);
}

.help-section {
  margin-top: 28px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  scroll-margin-top: 24px;
}

.help-section h2 {
  margin: 0 0 10px 0;
  font-size: 1.1rem;
}

.start-secondary-actions {
  margin-top: 18px;
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.start-secondary-btn {
  width: 180px;
  text-align: center;
  text-decoration: none;
}

.browse-remix {
  font-weight: 700;
}

.flash-error {
  background: #f4d6d6; 
  border: 1px solid #d9a5a5;
  color: #5a1f1f;
}

.flash-success {
  background: #d6f4de;
  border: 1px solid #a5d9b3;
  color: #1f5a2e;
}