:root {
  color-scheme: light;
  --ink: #222222;
  --muted: #666a73;
  --line: #d7d9de;
  --panel: #f8f8f6;
  --surface: #ffffff;
  --accent: #cf3f46;
  --accent-dark: #9f2c32;
  --grid: #8b8c90;
  --domino-border: #242222;
  --pip-1: #6415e8;
  --pip-2: #55c3d3;
  --pip-3: #ff6284;
  --pip-4: #f5c14c;
  --pip-5: #46b977;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: #e9eaed;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid #babdc4;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: #8d9098;
}

button:active {
  transform: translateY(1px);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(0, 2fr);
  height: 100vh;
  min-height: 640px;
}

.control-panel {
  width: 100%;
  height: 100vh;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid #cfd1d6;
}

.control-panel h1 {
  margin: 0;
  padding: 22px 24px 18px;
  font-size: 28px;
  line-height: 1.08;
  letter-spacing: 0;
}

.control-section {
  padding: 18px 24px;
  border-top: 1px solid var(--line);
}

.primary-controls {
  display: grid;
  gap: 14px;
}

.field,
.check-field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.check-field {
  grid-template-columns: 18px 1fr;
  align-items: center;
}

.check-field input {
  width: 16px;
  height: 16px;
}

.field select,
.field input[type="number"],
.field input[type="file"] {
  width: 100%;
  min-height: 38px;
  border: 1px solid #bfc2c9;
  background: #ffffff;
  color: var(--ink);
  padding: 7px 9px;
}

.field input[type="color"] {
  width: 100%;
  height: 40px;
  border: 1px solid #bfc2c9;
  padding: 3px;
  background: #ffffff;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 750;
}

.primary-button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.secondary-button {
  background: #ffffff;
}

.status-text {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.section-label {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.domino-tray {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 14px;
  align-items: start;
}

.advanced-section {
  display: grid;
  gap: 14px;
}

.advanced-section summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
  list-style-position: outside;
}

.advanced-section[open] {
  display: grid;
  gap: 14px;
}

.export-section {
  display: grid;
  gap: 10px;
  padding-bottom: 26px;
}

.preview-shell {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-width: 0;
  height: 100vh;
}

.preview-column {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  height: 100vh;
  background: #f1f2f4;
}

.preview-column + .preview-column {
  border-left: 1px solid #cacdd4;
}

.preview-title {
  padding: 14px 18px;
  border-bottom: 1px solid #d2d5dc;
  color: #424650;
  font-size: 14px;
  font-weight: 750;
  background: #ffffff;
}

.preview-scroll {
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: auto;
  padding: 24px;
}

.card-preview {
  position: relative;
  width: min(82%, 430px);
  aspect-ratio: 148 / 210;
  background: var(--preview-bleed, #f45757);
  box-shadow: 0 12px 30px rgba(22, 24, 29, 0.18);
  overflow: hidden;
}

.finished-area {
  position: absolute;
  overflow: hidden;
  border-radius: var(--finished-radius, 1.2%);
  background: var(--finished-bg, #fff4f4);
}

.preview-logo,
.preview-stars,
.content-area {
  position: absolute;
  z-index: 2;
}

.preview-logo {
  object-fit: contain;
}

.preview-stars {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 2px;
}

.preview-stars img {
  width: var(--star-size, 14px);
  height: var(--star-size, 14px);
  object-fit: contain;
}

.content-area {
  overflow: hidden;
  border: max(1px, var(--area-border, 0.3%)) solid #2f2f33;
  border-radius: var(--area-radius, 1.2%);
  background: #ffffff;
}

.board-stage {
  position: absolute;
}

.area-error {
  position: absolute;
  inset: 12%;
  display: grid;
  place-items: center;
  color: #9c1f2f;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
  text-align: center;
}

.board {
  position: relative;
  width: 100%;
  height: 100%;
  background: #ffffff;
}

.puzzle-board,
.answer-board.drop-active {
  border: 4px solid var(--domino-border);
}

.answer-board {
  border: 3px solid var(--domino-border);
}

.grid-cell {
  position: absolute;
  border-right: 2px solid var(--grid);
  border-bottom: 2px solid var(--grid);
}

.grid-cell.no-right {
  border-right: 0;
}

.grid-cell.no-bottom {
  border-bottom: 0;
}

.pip {
  position: absolute;
  width: var(--pip-size);
  height: var(--pip-size);
  border-radius: 50%;
  background: var(--pip-color);
  transform: translate(-50%, -50%);
}

.placed-outline {
  position: absolute;
  border: 4px solid var(--domino-border);
  border-radius: 7px;
  pointer-events: auto;
  cursor: grab;
  background: transparent;
}

.placed-outline:active {
  cursor: grabbing;
}

.placed-outline::after {
  content: "";
  position: absolute;
  background: var(--domino-border);
}

.placed-half {
  position: absolute;
}

.placed-outline.vertical .placed-half {
  left: 0;
  width: 100%;
  height: 50%;
}

.placed-outline.vertical .placed-half.first {
  top: 0;
}

.placed-outline.vertical .placed-half.second {
  bottom: 0;
}

.placed-outline.horizontal .placed-half {
  top: 0;
  width: 50%;
  height: 100%;
}

.placed-outline.horizontal .placed-half.first {
  left: 0;
}

.placed-outline.horizontal .placed-half.second {
  right: 0;
}

.placed-outline.horizontal::after {
  top: 0;
  bottom: 0;
  left: calc(50% - 1px);
  width: 2px;
}

.placed-outline.vertical::after {
  left: 0;
  right: 0;
  top: calc(50% - 1px);
  height: 2px;
}

.domino-tile {
  --tile-w: 58px;
  --tile-h: 102px;
  position: relative;
  width: var(--tile-w);
  height: var(--tile-h);
  margin: 0 auto;
  border: 4px solid var(--domino-border);
  border-radius: 11px;
  background: #ffffff;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.domino-tile.unavailable {
  opacity: 0.3;
  cursor: default;
}

.domino-tile.horizontal {
  --tile-w: 102px;
  --tile-h: 58px;
}

.domino-tile .half {
  position: absolute;
}

.domino-tile.vertical .half {
  left: 0;
  width: 100%;
  height: 50%;
}

.domino-tile.vertical .half.first {
  top: 0;
}

.domino-tile.vertical .half.second {
  bottom: 0;
}

.domino-tile.horizontal .half {
  top: 0;
  width: 50%;
  height: 100%;
}

.domino-tile.horizontal .half.first {
  left: 0;
}

.domino-tile.horizontal .half.second {
  right: 0;
}

.domino-tile::after {
  content: "";
  position: absolute;
  background: var(--domino-border);
}

.domino-tile.vertical::after {
  left: 12px;
  right: 12px;
  top: calc(50% - 1px);
  height: 2px;
}

.domino-tile.horizontal::after {
  top: 10px;
  bottom: 10px;
  left: calc(50% - 1px);
  width: 2px;
}

.drag-ghost {
  position: fixed;
  z-index: 50;
  margin: 0;
  pointer-events: none;
  box-shadow: 0 12px 24px rgba(18, 20, 25, 0.2);
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .control-panel,
  .preview-column,
  .preview-shell {
    height: auto;
  }

  .control-panel {
    border-right: 0;
    border-bottom: 1px solid #cfd1d6;
  }

  .preview-shell {
    grid-template-columns: 1fr;
  }

  .preview-column + .preview-column {
    border-left: 0;
    border-top: 1px solid #cacdd4;
  }

  .preview-scroll {
    min-height: 620px;
  }
}
