.topbar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--tile-border);
}

.brand {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: 0.04em;
}

.meta {
  display: flex;
  gap: 1rem;
  align-items: baseline;
  color: var(--fg-muted);
  font-size: 0.95rem;
}

.theme {
  padding: .15em .55em;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.timer {
  font-variant-numeric: tabular-nums;
  font-family: var(--font-tile);
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  padding: 2rem 1rem;
}

.status {
  padding: .5em 1em;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent);
}
.status.win {
  background: var(--tile-locked-bg);
  color: var(--tile-locked-fg);
}

.board {
  display: grid;
  grid-template-columns: repeat(5, var(--tile-size));
  grid-template-rows: repeat(5, var(--tile-size));
  gap: var(--gap);
  position: relative;
  touch-action: none; /* enable Pointer-Events drag without browser scrolling */
  user-select: none;
}

.tile {
  display: grid;
  place-items: center;
  background: var(--tile-bg);
  color: var(--tile-fg);
  border: 1px solid var(--tile-border);
  border-radius: var(--radius);
  font-family: var(--font-tile);
  font-size: calc(var(--tile-size) * 0.5);
  font-weight: 600;
  text-transform: uppercase;
  box-shadow: var(--shadow);
  cursor: grab;
  transition: transform .15s, box-shadow .15s, background-color .25s;
  will-change: transform;
}
.tile:hover:not(.fixed):not(.locked) {
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(0, 0, 0, .1);
}
.tile.fixed {
  background: var(--tile-fixed-bg);
  color: var(--tile-fixed-fg);
  cursor: not-allowed;
  box-shadow: none;
}
.tile.fixed::after {
  content: "";
  position: absolute;
  inset: auto 4px 4px auto;
  width: 8px;
  height: 8px;
  border: 1.5px solid currentColor;
  border-radius: 50% 50% 50% 0;
  opacity: .4;
}
.tile.locked {
  background: var(--tile-locked-bg);
  color: var(--tile-locked-fg);
  cursor: default;
  border-color: transparent;
  animation: lock-settle .55s ease-out;
}
.tile.dragging {
  cursor: grabbing;
  z-index: 10;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  transform: scale(1.05);
  transition: none;
}
.tile.drop-target {
  background: var(--tile-target-bg);
  border-color: var(--accent);
}
.tile.illegal-target {
  background: var(--tile-fixed-bg);
}

@keyframes lock-settle {
  0%   { transform: scale(1); background: var(--tile-bg); }
  35%  { transform: scale(1.08); background: #4ade80; box-shadow: 0 0 14px rgba(74, 222, 128, .65); }
  70%  { transform: scale(0.97); background: var(--tile-locked-bg); }
  100% { transform: scale(1);    background: var(--tile-locked-bg); }
}

.actions {
  display: flex;
  gap: .75rem;
}

.footer {
  padding: 1rem;
  text-align: center;
  color: var(--fg-muted);
  font-size: 0.85rem;
}

.permalink a {
  color: inherit;
  text-decoration: none;
  font-family: var(--font-tile);
}
.permalink a:hover { color: var(--accent); }

/* Modal dialogs (native <dialog>). */

.dialog {
  border: 1px solid var(--tile-border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--fg);
  padding: 0;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .25);
  max-width: 26rem;
  width: calc(100% - 2rem);
}
.dialog::backdrop {
  background: rgba(0, 0, 0, .35);
  backdrop-filter: blur(2px);
}
.dialog-body {
  padding: 1.25rem 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .85rem;
}
.dialog-body h2 {
  margin: 0;
  font-size: 1.15rem;
}
.dialog-text {
  margin: 0;
  line-height: 1.45;
}
.dialog-meta {
  margin: 0;
  font-size: .85rem;
  color: var(--fg-muted);
  font-family: var(--font-tile);
}
.dialog-actions {
  margin: 0;
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
}
.dialog-actions button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.iconbtn {
  background: transparent;
  border: 1px solid transparent;
  font-size: 1.1em;
  padding: .15em .45em;
  cursor: pointer;
  color: var(--fg-muted);
}
.iconbtn:hover { color: var(--fg); border-color: var(--tile-border); }

.dialog.settings {
  max-width: 30rem;
}
.settings-section {
  border-top: 1px solid var(--tile-border);
  padding-top: 1rem;
  margin-top: .25rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.settings-section:first-of-type {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}
.settings-section h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 500;
  color: var(--fg-muted);
}
.theme-radio {
  display: flex;
  gap: 1rem;
}
.theme-radio label {
  display: flex;
  gap: .35rem;
  align-items: center;
  cursor: pointer;
}
.settings-row {
  display: flex;
  gap: .5rem;
}
.settings-row input {
  flex: 1;
  font: inherit;
  padding: .4em .6em;
  border-radius: var(--radius);
  border: 1px solid var(--tile-border);
  background: var(--bg);
  color: var(--fg);
}
.settings-actions {
  display: flex;
  gap: .5rem;
}
.export-text {
  width: 100%;
  font-family: var(--font-tile);
  font-size: .8rem;
  padding: .5em;
  border-radius: var(--radius);
  border: 1px solid var(--tile-border);
  background: var(--bg);
  color: var(--fg);
  resize: vertical;
}

.qr-canvas {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 256px;
  background: white;
  padding: 8px;
  border-radius: var(--radius);
}
.qr-canvas img, .qr-canvas canvas { display: block; }

.qr-video {
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  display: block;
  background: black;
  border-radius: var(--radius);
  aspect-ratio: 4 / 3;
}

.countdown {
  font-family: var(--font-tile);
}

.import-step {
  display: none;
  flex-direction: column;
  gap: .75rem;
}
.import-step.active { display: flex; }

.tile.solution-anim {
  animation: solution-cascade .55s ease-out both;
}
@keyframes solution-cascade {
  0%   { transform: scale(0.85); opacity: .6; }
  50%  { transform: scale(1.05); }
  100% { transform: scale(1);    opacity: 1; }
}
