:root {
  --bg: #0f1a10;
  --bg-2: #16241a;
  --fg: #cfe8c2;
  --accent: #88c070;
  --accent-dk: #34685c;
  --border: #2a3a2a;
  --shadow: 0 2px 0 #000a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  overflow: hidden;
}

#app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  box-sizing: border-box;
  overflow: hidden;
}

#viewport-wrap {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  position: relative;
  padding: 16px;
  box-sizing: border-box;
  overflow: hidden;
}

canvas#viewport {
  display: block;
  background: #000;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-crisp-edges;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  box-shadow: 0 0 0 2px var(--border), 0 0 24px #0008;
}

#error-msg {
  color: #f88;
  text-align: center;
  padding: 24px;
  max-width: 80ch;
}

#controls {
  flex: 0 0 auto;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.ctrl-group {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 8px;
  padding-right: 16px;
  border-right: 1px solid var(--border);
}
.ctrl-group:last-child {
  padding-right: 0;
  border-right: none;
}

@media (max-width: 720px) {
  #controls { flex-direction: column; align-items: center; gap: 8px; }
  .ctrl-group {
    padding-right: 0;
    padding-bottom: 8px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .ctrl-group:last-child { padding-bottom: 0; border-bottom: none; }
}

#controls button {
  background: var(--bg-2);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 10px 14px;
  width: 160px;
  height: 96px;
  cursor: pointer;
  font: inherit;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  box-shadow: var(--shadow);
  transition: background 0.1s, transform 0.05s;
}

/* Gallery button: 2x width, split into left (text) + right (preview) */
#controls #btn-gallery {
  width: 330px;
  flex-direction: row;
  align-items: stretch;
  justify-content: stretch;
  gap: 0;
  padding: 0;
}
#controls #btn-gallery .gallery-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  flex: 1;
  padding: 10px 14px;
  text-align: center;
}
#controls #btn-gallery .gallery-right {
  flex: 1;
  flex-shrink: 0;
  background: var(--bg-2);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  position: relative;
  overflow: hidden;
  padding: 10px 16px 10px 6px;
  transition: background 0.1s;
}
#controls #btn-gallery:hover:not(:disabled) .gallery-right {
  background: var(--accent-dk);
}
#controls #btn-gallery .gallery-right canvas {
  display: block;
  width: 140px;
  height: 63px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 1px solid var(--border);
  border-radius: 2px;
  box-shadow: inset 0 0 4px #0006;
  background: #0a0f0a;
}

#controls button:hover:not(:disabled) {
  background: var(--accent-dk);
  color: #fff;
}

#controls button:active:not(:disabled) {
  transform: translateY(1px);
}

#controls button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

#controls button#btn-reserved {
  visibility: hidden;
}

#controls #btn-gallery:disabled .gallery-right {
  background: var(--bg-2);
}

#countdown {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 90;
  font-size: clamp(96px, 22vw, 280px);
  font-weight: bold;
  color: var(--accent);
  text-shadow:
    0 0 16px #000,
    0 0 32px #000,
    0 4px 0 #000a;
  letter-spacing: 0.05em;
}
#countdown[hidden] { display: none; }

#flash {
  position: absolute;
  pointer-events: none;
  z-index: 5;
  background: #fff;
  opacity: 0;
  mix-blend-mode: screen;
}
#flash[hidden] { display: none; }
#flash.active {
  animation: flash-pulse 220ms ease-out;
}
@keyframes flash-pulse {
  0%   { opacity: 0; }
  25%  { opacity: 0.5; }
  100% { opacity: 0; }
}

#canvas-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 0 12px;
}
#canvas-controls .toolbar {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px;
  box-shadow: 0 2px 8px #000a, inset 0 1px 0 #fff1;
}
#canvas-controls .icon-btn {
  background: transparent;
  color: var(--fg);
  border: none;
  width: 32px;
  height: 32px;
  font-size: 16px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 4px;
  font-family: inherit;
  padding: 0;
  transition: background 0.1s, color 0.1s;
}
#canvas-controls .icon-btn:hover:not(:disabled) {
  background: var(--accent-dk);
  color: #fff;
}
#canvas-controls .icon-btn:active:not(:disabled) {
  transform: scale(0.95);
}
#canvas-controls .icon-btn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}
#canvas-controls .icon-btn.active {
  background: var(--accent);
  color: #000;
}
#canvas-controls #btn-dithering:not(.active) {
  color: #555;
}

.btn-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}
.btn-sub {
  font-size: 13px;
  font-weight: bold;
}
.btn-count {
  font-size: 10px;
  color: var(--accent);
  opacity: 0.85;
}

.modal {
  position: fixed;
  inset: 0;
  background: #000c;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  cursor: pointer;
}
.modal[hidden] { display: none; }

.modal-inner {
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 20px;
  max-width: 820px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  cursor: default;
}

.modal-toolbar {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.modal-toolbar #modal-title {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-right: auto;
}
.modal-toolbar button {
  background: var(--accent-dk);
  color: #fff;
  border: 1px solid var(--border);
  padding: 6px 12px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.modal-toolbar button:hover { background: var(--accent); color: #000; }
.modal-toolbar #btn-close-modal {
  background: transparent;
  font-size: 16px;
  padding: 4px 10px;
}
.modal-toolbar #btn-close-modal:hover {
  background: var(--accent);
  color: #000;
}

.snap-grid {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 24px;
  justify-content: center;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}

.snap-group {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 16px;
  padding: 12px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.2);
  align-items: flex-start;
  justify-content: center;
}

.snap-grid figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.snap-grid figcaption {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
}

.snap-grid img {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  width: 240px;
  height: 216px;
  object-fit: contain;
  cursor: pointer;
  border: 1px solid var(--border);
}

.snap-grid a.snap-img-link {
  display: block;
  padding: 0;
  background: none;
  line-height: 0;
}
.snap-grid a.snap-img-link:hover { background: none; }
.snap-grid a.snap-img-link:hover img {
  border-color: var(--accent);
}

.snap-grid a {
  background: var(--accent-dk);
  color: #fff;
  text-decoration: none;
  padding: 6px 12px;
  font-size: 12px;
}
.snap-grid a:hover { background: var(--accent); color: #000; }

.modal-hint {
  text-align: center;
  margin: 16px 0 0;
  color: #888;
  font-size: 12px;
}
