/* ── C64 PALETTE ── */
:root {
  --c64-bg: #40318D;
  --c64-border: #7869C4;
  --c64-text: #DDD6F3;
  --c64-white: #FFFFFF;
  --c64-dark: #2B1E5C;
  --font: 'Press Start 2P', monospace;

  /* Fe web component theming */
  --fe-code-bg: #2B1E5C;
  --fe-code-border: #7869C4;
  --fe-code-text: #C8BFE7;
  --fe-code-font: 'Press Start 2P', monospace;
  --fe-code-size: 0.6rem;
  --fe-code-line-height: 1.8;
  --fe-code-line-number: #7869C4;
  --fe-hl-keyword: #c678dd;
  --fe-hl-type: #e5c07b;
  --fe-hl-function: #7ec8ff;
  --fe-hl-string: #98c379;
  --fe-hl-number: #d19a66;
  --fe-hl-comment: #7869C4;
  --fe-hl-operator: #C8BFE7;
  --fe-hl-punctuation: #C8BFE7;
}

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

/* ── BASE ── */
html {
  font-size: 14px;
}

body {
  background: var(--c64-border);
  font-family: var(--font);
  color: var(--c64-text);
  line-height: 1.8;
  height: 100vh;
  overflow: hidden;
}

/* ── CRT BORDER / FRAME ── */
.c64-border {
  background: var(--c64-border);
  border: 16px solid var(--c64-border);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.c64-screen {
  background: var(--c64-bg);
  padding: 16px;
  position: relative;
  overflow: hidden;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Scanline overlay */
.c64-screen::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.08) 2px,
    rgba(0, 0, 0, 0.08) 4px
  );
  pointer-events: none;
}

/* ── HEADER ── */
.c64-header {
  text-align: center;
  padding: 8px 0;
  flex-shrink: 0;
}

.c64-header .stars {
  color: var(--c64-white);
  font-size: 1rem;
  margin-bottom: 4px;
}

.c64-header p {
  font-size: 0.75rem;
}

/* Blinking cursor */
.cursor {
  animation: blink 1s step-end infinite;
  color: var(--c64-text);
  margin-left: 4px;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ── GRID LAYOUT ── */
.c64-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 8px;
  flex: 1;
  min-height: 0;
}

/* ── QUADRANTS ── */
.c64-quadrant {
  border: 2px solid var(--c64-border);
  padding: 16px;
  overflow-y: auto;
}

/* ── TYPOGRAPHY ── */
h2 {
  color: var(--c64-white);
  font-size: 0.8rem;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--c64-border);
  padding-bottom: 6px;
}

h3 {
  color: var(--c64-white);
  font-size: 0.65rem;
  margin-top: 16px;
  margin-bottom: 8px;
}

p {
  font-size: 0.75rem;
  margin-bottom: 8px;
}

a {
  color: var(--c64-white);
  text-decoration: underline;
}

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

ol {
  list-style: none;
  counter-reset: steps;
  padding-left: 0;
}

ol li {
  font-size: 0.75rem;
  margin-bottom: 6px;
  counter-increment: steps;
}

ol li::before {
  content: counter(steps) ". ";
  color: var(--c64-white);
}

/* ── SRC BUTTON ── */
.source-btn {
  font-family: var(--font);
  font-size: 0.55rem;
  line-height: 1;
  color: var(--c64-bg);
  background: var(--c64-text);
  border: 1px solid var(--c64-dark);
  padding: 5px 7px;
  cursor: pointer;
  flex-shrink: 0;
}

.source-btn:hover,
.source-btn:focus {
  background: var(--c64-white);
  outline: none;
}

.source-btn.active {
  background: var(--c64-white);
}

/* ── SOURCE VIEWER (bottom-right) ── */
.source-viewer-content {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.source-viewer-content fe-code-block {
  margin: 0;
}

.source-viewer-hint {
  font-size: 0.6rem;
  opacity: 0.6;
  text-align: center;
  margin-top: 2rem;
}

.source-viewer-label {
  font-size: 0.65rem;
  color: var(--c64-white);
  margin-bottom: 6px;
}

#source-viewer {
  display: flex;
  flex-direction: column;
}

/* ── DOC DETAILS (fields & impls in source viewer) ── */
.doc-fields,
.doc-impl {
  margin-top: 12px;
  border-top: 1px solid var(--c64-dark);
  padding-top: 8px;
}

.doc-field,
.doc-method {
  padding: 6px 8px;
  margin-bottom: 4px;
  border-left: 2px solid var(--c64-border);
}

.doc-sig {
  font-family: var(--font);
  font-size: 0.65rem;
  color: var(--c64-text);
  word-break: break-all;
}

.doc-sig .sig-link {
  color: var(--c64-white);
  text-decoration: none;
}

.doc-sig .sig-link:hover {
  text-decoration: underline;
}

.doc-desc {
  font-size: 0.65rem;
  margin-top: 4px;
  margin-bottom: 0;
  opacity: 0.7;
}

/* ── GLOBAL FOOTER ── */
.c64-footer {
  display: flex;
  justify-content: center;
  gap: 24px;
  padding: 6px 0;
  flex-shrink: 0;
}

.c64-footer a {
  font-family: var(--font);
  font-size: 0.55rem;
  color: var(--c64-text);
  text-decoration: none;
}

.c64-footer a:hover {
  color: var(--c64-white);
}

.c64-footer-credit {
  font-family: var(--font);
  font-size: 0.55rem;
  color: var(--c64-border);
}

/* ── MORE-INFO LINK ── */
.more-info {
  margin-top: 12px;
}

.more-info a {
  font-size: 0.65rem;
  color: var(--c64-white);
  text-decoration: none;
}

.more-info a:hover {
  color: var(--c64-text);
  text-decoration: underline;
}

/* ── TABLE (Contracts / Source) ── */
.c64-table {
  width: 100%;
  border-collapse: collapse;
}

.c64-table td {
  font-size: 0.65rem;
  padding: 6px 0;
  vertical-align: top;
}

.c64-table tr {
  border-bottom: 1px solid var(--c64-dark);
}

.c64-table td:first-child {
  color: var(--c64-white);
  white-space: nowrap;
  padding-right: 20px;
  width: 1%;
}

.c64-table td:last-child {
  word-break: break-all;
}

.contract-entry {
  display: flex;
  align-items: center;
  gap: 6px;
}

.contract-value {
  min-width: 0;
  flex: 1;
}

.copy-contract-btn {
  font-family: var(--font);
  font-size: 0.55rem;
  line-height: 1;
  color: var(--c64-bg);
  background: var(--c64-text);
  border: 1px solid var(--c64-dark);
  padding: 5px 7px;
  cursor: pointer;
  flex-shrink: 0;
}

.copy-contract-btn:hover,
.copy-contract-btn:focus {
  background: var(--c64-white);
  outline: none;
}

.copy-contract-btn.copied {
  background: var(--c64-white);
}

/* ── PUZZLE ── */
.puzzle-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.c64-btn {
  font-family: var(--font);
  font-size: 0.65rem;
  color: var(--c64-bg);
  background: var(--c64-text);
  border: none;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}

.c64-btn:hover,
.c64-btn:focus {
  background: var(--c64-white);
  color: var(--c64-bg);
  outline: none;
}

.c64-btn.active {
  background: var(--c64-white);
  color: var(--c64-bg);
}

.puzzle-status {
  display: flex;
  gap: 24px;
  font-size: 0.65rem;
  margin-bottom: 12px;
}

.puzzle-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  max-width: 280px;
  margin: 0 auto 12px;
  aspect-ratio: 1;
}

.puzzle-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--c64-bg);
  background: var(--c64-text);
  border: 2px solid var(--c64-dark);
  cursor: pointer;
  user-select: none;
  transition: transform 0.08s, background 0.08s;
}

.puzzle-tile:hover {
  background: var(--c64-white);
}

.puzzle-tile.empty {
  background: var(--c64-bg);
  border-color: var(--c64-bg);
  cursor: default;
}

.puzzle-message {
  text-align: center;
  font-size: 0.7rem;
  color: var(--c64-white);
  min-height: 1.8em;
}

.puzzle-hint {
  text-align: center;
  font-size: 0.6rem;
  opacity: 0.6;
}

/* ── RESPONSIVE: single column on small screens ── */
@media (max-width: 768px) {
  body {
    height: auto;
    overflow: auto;
  }

  .c64-border {
    height: auto;
    border-width: 8px;
  }

  .c64-screen {
    padding: 8px;
    overflow-x: hidden;
  }

  .c64-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  .c64-quadrant {
    overflow-y: visible;
    overflow-x: hidden;
    padding: 12px 8px;
  }

  html {
    font-size: 12px;
  }

  .puzzle-board {
    max-width: 260px;
  }

  .contract-entry {
    flex-wrap: wrap;
  }

  .contract-value {
    width: 100%;
    flex: unset;
  }

  .c64-table td:first-child {
    padding-right: 8px;
  }

  .c64-footer {
    flex-wrap: wrap;
    gap: 12px;
  }
}
