:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #111318;
  color: #eef1f5;
}

* {
  box-sizing: border-box;
}

body {
  height: 100vh;
  margin: 0;
  overflow: hidden;
  background: #111318;
}

button {
  border: 0;
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 328px;
  gap: 14px;
  width: min(1320px, calc(100vw - 20px));
  height: 100vh;
  margin: 0 auto;
  padding: 10px 0;
}

.game-stage {
  position: relative;
  display: grid;
  align-items: center;
  min-width: 0;
}

canvas {
  width: 100%;
  max-height: calc(100vh - 20px);
  aspect-ratio: 3 / 2;
  border: 1px solid #303844;
  border-radius: 8px;
  background: #171b22;
  box-shadow: 0 18px 70px rgba(0, 0, 0, 0.35);
}

.start-overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(17, 19, 24, 0.72);
  border-radius: 8px;
}

.start-overlay.active {
  display: grid;
}

.start-panel {
  display: grid;
  gap: 12px;
  width: min(420px, 100%);
  padding: 22px;
  border: 1px solid #354050;
  border-radius: 8px;
  background: #171b22;
  box-shadow: 0 18px 70px rgba(0, 0, 0, 0.38);
}

.start-panel h2 {
  color: #eef1f5;
  font-size: 28px;
}

.start-summary,
.final-score {
  margin: 0;
  color: #aab5c4;
  font-size: 14px;
  line-height: 1.45;
}

.final-score {
  padding: 10px;
  border: 1px solid #2b333f;
  border-radius: 8px;
  background: #1e242d;
  color: #eef1f5;
  font-weight: 700;
}

.name-field {
  display: grid;
  gap: 6px;
  color: #aab5c4;
  font-size: 12px;
  font-weight: 700;
}

.name-field input {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid #354050;
  border-radius: 8px;
  background: #1e242d;
  color: #eef1f5;
  font: inherit;
}

.name-field input:focus {
  border-color: #8eb7ff;
  outline: none;
}

.start-button {
  min-height: 42px;
  border: 1px solid #8eb7ff;
  border-radius: 8px;
  background: #2d528b;
  color: #eef1f5;
  cursor: pointer;
  font-weight: 800;
}

.start-button:hover {
  background: #3766ad;
}

.record-button {
  min-height: 36px;
  border: 1px solid #facc15;
  border-radius: 8px;
  background: #3b2f11;
  color: #fde68a;
  cursor: pointer;
  font-weight: 800;
}

.record-button:hover {
  background: #4b3a12;
}

.record-button[disabled] {
  cursor: default;
  opacity: 0.55;
}

.profile-points {
  min-height: 24px;
  color: #facc15;
  font-size: 13px;
  font-weight: 800;
}

.ranking-box {
  display: grid;
  gap: 8px;
}

.ranking-list {
  display: grid;
  gap: 6px;
  min-height: 34px;
  margin: 0;
  padding-left: 22px;
  color: #dbe2ec;
  font-size: 13px;
}

.ranking-list li::marker {
  color: #8eb7ff;
  font-weight: 800;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  height: calc(100vh - 20px);
  max-height: calc(100vh - 20px);
  padding: 12px;
  border: 1px solid #303844;
  border-radius: 8px;
  background: #171b22;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.side-panel::-webkit-scrollbar {
  width: 8px;
}

.side-panel::-webkit-scrollbar-track {
  background: #111318;
  border-radius: 999px;
}

.side-panel::-webkit-scrollbar-thumb {
  background: #3d4959;
  border-radius: 999px;
}

.panel-header {
  display: grid;
  gap: 2px;
}

.eyebrow {
  margin: 0;
  color: #8eb7ff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.15;
}

h2 {
  color: #cbd3df;
  font-size: 13px;
}

.stat-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.stat-strip div {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid #2b333f;
  border-radius: 8px;
  background: #1e242d;
}

.stat-strip span {
  color: #9ca8b7;
  font-size: 11px;
}

.stat-strip strong {
  font-size: 17px;
  line-height: 1;
}

.panel-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 0.8fr;
  gap: 6px;
}

.panel-button,
.next-button {
  min-height: 34px;
  border: 1px solid #354050;
  border-radius: 8px;
  background: #242b35;
  color: #dbe2ec;
  cursor: pointer;
}

.panel-button.active,
.panel-button:hover,
.next-button:hover {
  border-color: #8eb7ff;
  background: #243755;
}

.panel-button.close {
  color: #aab5c4;
}

.panel-pane {
  display: none;
  min-height: 0;
  overflow: visible;
}

.panel-pane.active {
  display: grid;
  flex: 0 0 auto;
  gap: 8px;
  align-content: start;
  padding-right: 4px;
}

.closed-hint {
  display: grid;
  gap: 5px;
  padding: 10px;
  border: 1px dashed #3d4959;
  border-radius: 8px;
  color: #aab5c4;
  font-size: 13px;
}

.closed-hint strong {
  color: #eef1f5;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 2px;
}

.section-title.compact {
  margin-top: 4px;
}

.section-title span {
  color: #9ca8b7;
  font-size: 11px;
}

.inventory-grid {
  display: grid;
  gap: 4px;
  padding: 7px;
  border: 1px solid #2b333f;
  border-radius: 8px;
  background: #12161c;
}

.bag-cell {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 0;
  border: 1px solid #2e3743;
  border-radius: 5px;
  background: #202732;
  color: #111318;
  font-size: 12px;
  font-weight: 800;
  overflow: hidden;
}

.bag-cell.inactive {
  border-style: dashed;
  background: #151a21;
  opacity: 0.35;
}

.bag-cell.edge::after {
  content: "";
  position: absolute;
  inset: 2px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  pointer-events: none;
}

.bag-cell.can-place {
  border-color: #8eb7ff;
  box-shadow: inset 0 0 0 2px rgba(142, 183, 255, 0.36);
  cursor: pointer;
}

.bag-cell.preview-place {
  border-color: #8eb7ff;
  background: #26384f;
  box-shadow:
    inset 0 0 0 2px rgba(142, 183, 255, 0.32),
    0 0 12px rgba(142, 183, 255, 0.25);
}

.bag-cell.preview-invalid {
  border-color: #fb7185;
  background: #3a2029;
  box-shadow:
    inset 0 0 0 2px rgba(251, 113, 133, 0.28),
    0 0 10px rgba(251, 113, 133, 0.2);
}

.bag-cell.can-merge {
  border-color: #facc15;
  box-shadow: inset 0 0 0 2px rgba(250, 204, 21, 0.36);
  cursor: pointer;
}

.bag-cell.removable {
  cursor: pointer;
}

.bag-cell.removable:hover {
  border-color: #fb7185;
}

.reward-options {
  display: grid;
  gap: 7px;
}

.reward-card {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 8px;
  width: 100%;
  min-height: 50px;
  padding: 7px;
  border: 1px solid #354050;
  border-radius: 8px;
  background: #242b35;
  color: #dbe2ec;
  text-align: left;
  cursor: pointer;
}

.reward-card[disabled] {
  cursor: default;
  opacity: 0.45;
}

.reward-card:hover {
  border-color: #8eb7ff;
  background: #243755;
}

.reward-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  color: #111318;
  font-weight: 800;
}

.reward-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.reward-copy strong {
  font-size: 13px;
}

.reward-copy span {
  color: #aab5c4;
  font-size: 11px;
  line-height: 1.2;
}

.reward-shape {
  display: inline-grid;
  gap: 2px;
  justify-self: start;
  margin-top: 3px;
}

.reward-shape .shape-cell {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.reward-price {
  align-self: center;
  color: #facc15;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.shop-actions {
  display: grid;
  grid-template-columns: 1fr;
}

.hidden-action {
  display: none;
}

.stash-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}

.stash-list .effect-pill {
  grid-column: 1 / -1;
}

.stash-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 5px;
  border: 1px solid #354050;
  border-radius: 8px;
  background: #242b35;
  color: #dbe2ec;
  cursor: pointer;
}

.stash-button.active,
.stash-button:hover {
  border-color: #8eb7ff;
  background: #243755;
}

.stash-label {
  min-width: 0;
  overflow: hidden;
  font-size: 11px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stash-shape {
  display: inline-grid;
  gap: 1px;
  justify-self: end;
}

.stash-shape .shape-cell {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

.pending-item {
  min-height: 30px;
  padding: 7px 9px;
  border: 1px dashed #3d4959;
  border-radius: 8px;
  color: #aab5c4;
  font-size: 12px;
}

.pending-item.ready {
  border-color: #8eb7ff;
  background: #1e2a3c;
  color: #eef1f5;
}

.shape-preview {
  display: inline-grid;
  gap: 3px;
  min-height: 24px;
}

.shape-cell {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: #242b35;
}

.shape-cell.filled {
  border-color: rgba(255, 255, 255, 0.36);
}

.effect-list {
  display: grid;
  gap: 5px;
}

.compact-list {
  grid-template-columns: 1fr;
}

.effect-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid #2b333f;
  border-radius: 8px;
  background: #1e242d;
  color: #dbe2ec;
  font-size: 12px;
}

.effect-pill span {
  color: #9ca8b7;
  white-space: nowrap;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .shell {
    grid-template-columns: 1fr;
    height: auto;
    width: min(100vw - 20px, 760px);
  }

  canvas {
    max-height: none;
  }

  .side-panel {
    height: auto;
    max-height: none;
    overflow: visible;
  }
}
