:root {
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: #f5f7fa;
  background-color: #070b11;
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: radial-gradient(circle at top, #1b283c, #050608 65%);
  color: #f5f7fa;
  overflow-x: hidden;
  overflow-y: auto;
}

main {
  width: min(960px, 94vw);
  padding: 24px 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.tabs {
  width: min(960px, 94vw);
  display: flex;
  gap: 10px;
  justify-content: center;
}

.tab-button {
  background: rgba(9, 13, 19, 0.8);
  border-color: #33548f;
}

.tab-button.is-active {
  background: #2d6ef3;
  border-color: #6f9dff;
}

.tab-panel {
  width: 100%;
  display: none;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.tab-panel.is-active {
  display: flex;
}

.panel {
  position: relative;
  background: rgba(9, 13, 19, 0.9);
  border: 1px solid #1f2a3f;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  width: 100%;
  max-width: 100%;
  overflow: auto;
}

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

.hud-score strong {
  font-size: 1.6rem;
  letter-spacing: 0.04em;
}

.hud-status {
  font-weight: 600;
  color: #9ddcff;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.hud-controls {
  display: flex;
  gap: 8px;
}

button {
  border: 1px solid #1f5cff;
  background: #123980;
  color: #f5f7fa;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease;
}

button:hover,
button:focus-visible {
  background: #1a4fb2;
  outline: none;
}

button:active {
  transform: scale(0.97);
}

button:disabled {
  cursor: default;
  opacity: 0.5;
  transform: none;
}

.grid {
  --columns: 20;
  --cell-size: 24px;
  --grid-gap: 2px;
  --grid-padding: 8px;
  --grid-border-width: 4px;
  --grid-radius: 12px;
  display: grid;
  grid-template-columns: repeat(var(--columns), var(--cell-size));
  grid-auto-rows: var(--cell-size);
  gap: var(--grid-gap);
  width: max-content;
  height: max-content;
  background: #0a101b;
  padding: var(--grid-padding);
  border-radius: var(--grid-radius);
  border: var(--grid-border-width) solid #d13232;
  box-shadow: inset 0 0 0 2px rgba(255, 220, 220, 0.18);
  position: relative;
  margin: 0 auto;
}

.challenge-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #274f8a;
  background: linear-gradient(135deg, rgba(18, 57, 128, 0.35), rgba(13, 21, 34, 0.9));
}

.challenge-banner strong {
  display: block;
  font-size: 0.98rem;
}

.challenge-eyebrow {
  margin: 0 0 4px;
  color: #9ddcff;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.cell {
  background: rgba(8, 15, 26, 0.7);
  border-radius: 4px;
  transition: background 80ms ease;
  width: var(--cell-size);
  height: var(--cell-size);
}

.cell-body {
  background: linear-gradient(135deg, #1abc9c, #149174);
}

.cell-head {
  background: linear-gradient(135deg, #f1c40f, #f39c12);
  box-shadow: 0 0 6px rgba(243, 156, 18, 0.8);
}

.cell-food {
  background: radial-gradient(circle, #ff5f6d, #ffc371);
  box-shadow: 0 0 8px rgba(255, 95, 109, 0.7);
}

.cell-wall {
  background: linear-gradient(135deg, #66758f, #36465d);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.cell-void {
  background: rgba(3, 7, 13, 0.96);
}

.overlay {
  position: absolute;
  inset: 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: rgba(5, 8, 15, 0.84);
  border-radius: 12px;
  text-align: center;
  gap: 12px;
  border: 1px solid #18243a;
}

.share-status {
  margin: 0;
  color: #c8e6ff;
  font-size: 0.9rem;
}

.secondary-action {
  background: transparent;
  border-color: #4f7ad3;
}

.pad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.pad-row {
  display: flex;
  gap: 8px;
}

.pad button {
  width: 72px;
}

.howto {
  background: rgba(9, 13, 19, 0.8);
  border: 1px solid #1f2a3f;
  border-radius: 12px;
  padding: 12px 18px;
}

.howto h2 {
  margin-top: 0;
}

.howto ul {
  padding-left: 18px;
  margin: 0;
  line-height: 1.6;
}

.editor-panel {
  width: min(960px, 94vw);
  overflow-x: auto;
}

.editor-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.editor-header h2 {
  margin: 0;
}

.editor-copy {
  margin: 0;
  max-width: 420px;
  line-height: 1.5;
  color: #c9d8ea;
}

.editor-controls,
.editor-tools,
.editor-import {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.editor-controls label,
.editor-share span {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.92rem;
  color: #d9e6f5;
}

.editor-controls input {
  width: 96px;
  border-radius: 10px;
  border: 1px solid #2c446c;
  background: #09111d;
  color: #f5f7fa;
  padding: 8px 10px;
}

.editor-slider {
  min-width: 180px;
}

.editor-slider input[type="range"] {
  width: 180px;
  padding: 0;
  accent-color: #2d6ef3;
}

.editor-tools button.is-active {
  background: #2d6ef3;
  border-color: #6f9dff;
}

.editor-status {
  margin: 0 0 12px;
  min-height: 1.4em;
  color: #c8e6ff;
}

.editor-status.error {
  color: #ff9f9f;
}

.editor-grid {
  --cell-size: 24px;
  gap: 1px;
  padding: 6px;
  background: #51627d;
  border-color: #3b4d68;
  margin-bottom: 14px;
  touch-action: none;
  max-width: none;
  max-height: none;
}

.editor-grid .cell {
  cursor: crosshair;
  box-shadow: inset 0 0 0 0.35px rgba(154, 180, 214, 0.14);
}

.editor-grid .cell:hover {
  filter: brightness(1.12);
}

.editor-grid .cell-playable {
  background: rgba(26, 61, 32, 0.82);
}

.editor-grid .cell-wall {
  background: linear-gradient(135deg, #88a0c4, #516888);
}

.editor-share {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.editor-share textarea {
  width: min(720px, 92vw);
  min-height: 84px;
  border-radius: 12px;
  border: 1px solid #2c446c;
  background: #09111d;
  color: #f5f7fa;
  padding: 10px 12px;
  resize: vertical;
}

.editor-share span {
  width: min(720px, 92vw);
  text-align: left;
}

.editor-import {
  justify-content: center;
  margin-top: 16px;
}

@media (max-width: 640px) {
  main {
    padding: 12px;
  }
  .challenge-banner {
    align-items: flex-start;
    flex-direction: column;
  }
  .tabs {
    width: 100%;
  }
  button {
    padding: 8px 10px;
  }
  .editor-header {
    flex-direction: column;
  }
  .editor-copy {
    max-width: none;
  }
  .editor-slider {
    min-width: 100%;
  }
  .editor-slider input[type="range"] {
    width: 100%;
  }
  .editor-share textarea {
    width: 100%;
  }
}
