* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Theme: light (default), dark. System is resolved in JS to light or dark. */
:root,
[data-theme="light"] {
  --bg: #f0f4f8;
  --text: #1e293b;
  --text-muted: #64748b;
  --board-bg: #e2e8f0;
  --board-cell: #cbd5e1;
  --progress-border: #94a3b8;
  --progress-bg: #f1f5f9;
  --progress-fill-start: #0ea5e9;
  --progress-fill-end: #10b981;
  --toolbar-icon: #475569;
  --toolbar-icon-hover: #1e293b;
}

[data-theme="dark"] {
  --bg: #0d2137;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --board-bg: #2d2d44;
  --board-cell: #16213e;
  --progress-border: #3498db;
  --progress-bg: #16213e;
  --progress-fill-start: #3498db;
  --progress-fill-end: #2ecc71;
  --toolbar-icon: #94a3b8;
  --toolbar-icon-hover: #e2e8f0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
}

.board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
}

.board {
  position: relative;
  background: var(--board-bg);
  border-radius: 6px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.12);
}

[data-theme="dark"] .board {
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.board-bg {
  position: absolute;
  inset: 0;
  display: grid;
  gap: 2px;
  padding: 6px;
  pointer-events: none;
}

.board-bg.landscape {
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(6, 1fr);
}

.board-bg.portrait {
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(10, 1fr);
}

.board-bg-cell {
  background: var(--board-cell);
  border-radius: 3px;
}

.board-tiles {
  position: absolute;
  inset: 6px;
  pointer-events: none;
}

.piece-tile {
  position: absolute;
  border-radius: 3px;
  transition: left 0.3s ease, top 0.3s ease, width 0.3s ease, height 0.3s ease;
}

/* Top status and controls: progress bar, orientation toggle, theme toggle */
.top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px 12px 24px;
  font-size: 0.95rem;
  color: var(--text-muted);
  flex-shrink: 0;
  width: 100%;
  box-sizing: border-box;
}

.progress-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  border: 2px solid var(--progress-border);
  border-radius: 8px;
  background: var(--progress-bg);
  overflow: hidden;
  height: 48px;
}

.progress-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, var(--progress-fill-start), var(--progress-fill-end));
  transition: width 0.2s ease;
}

.top-bar .icon-btn {
  flex-shrink: 0;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 50px;
  height: 50px;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--toolbar-icon);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: var(--board-cell);
  color: var(--toolbar-icon-hover);
}

.toolbar-icon {
  width: 28px;
  height: 28px;
}

.orientation-icon {
  display: block;
  object-fit: contain;
}

.orientation-icon.portrait {
  transform: rotate(90deg);
}

[data-theme="dark"] .orientation-icon {
  filter: invert(1);
}

.progress-wrap.loading .progress-bar {
  width: 30% !important;
  animation: loading-pulse 1s ease-in-out infinite;
}

@keyframes loading-pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.status-text {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", "Consolas", monospace;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  text-align: center;
  pointer-events: none;
}

/* Piece colors - 12 maximally distinct hues */
.piece-tile[data-letter="F"] { background: #d32f2f; }
.piece-tile[data-letter="I"] { background: #f57c00; }
.piece-tile[data-letter="L"] { background: #ffeb3b; }
.piece-tile[data-letter="N"] { background: #8bc34a; }
.piece-tile[data-letter="P"] { background: #388e3c; }
.piece-tile[data-letter="T"] { background: #009688; }
.piece-tile[data-letter="U"] { background: #00bcd4; }
.piece-tile[data-letter="V"] { background: #2196f3; }
.piece-tile[data-letter="W"] { background: #3f51b5; }
.piece-tile[data-letter="X"] { background: #9c27b0; }
.piece-tile[data-letter="Y"] { background: #e91e63; }
.piece-tile[data-letter="Z"] { background: #795548; }
