:root {
  --hex-w: 156px;
  --hex-h: calc(var(--hex-w) * 1.1547);
  --gap: 6px;
  --bg: #F7F6F3;
  --surface: #ffffff;
  --text: #2a2825;
  --text-muted: #999490;
  --outline-default: #dedad4;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  background: var(--bg);
  color: var(--text);
}

/* Ghost background grid */
#hex-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.ghost-hex {
  position: absolute;
  width: var(--hex-w);
  height: var(--hex-h);
}
.ghost-hex::before {
  content: '';
  position: absolute;
  inset: 0;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  background: #e8e4df;
}
.ghost-hex::after {
  content: '';
  position: absolute;
  inset: 1px;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  background: var(--bg);
}

/* Centers the stage in the viewport */
.honeycomb-wrap {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* Absolute-positioned stage — width/height set by JS */
.honeycomb-stage {
  position: relative;
  z-index: 1;
}

/* Tile wrapper */
.hex-wrap {
  position: absolute;
  width: var(--hex-w);
  height: var(--hex-h);
  opacity: 0;
  animation: fadeUp 0.5s forwards cubic-bezier(0.22, 1, 0.36, 1);
  cursor: pointer;
}

/* Skip fade-in animation on post-swap rebuilds */
.honeycomb-stage.no-animate .hex-wrap {
  animation: none;
  opacity: 1;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Tile surface */
.hex {
  display: block;
  width: 100%;
  height: 100%;
  position: relative;
  transition: transform 220ms cubic-bezier(0.34, 1.2, 0.64, 1);
}

/* Outline layer */
.hex::before {
  content: '';
  position: absolute;
  inset: 0;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  background: var(--outline-default);
  transition: background 220ms ease;
}

/* Surface layer — inset 2px creates outline thickness */
.hex::after {
  content: '';
  position: absolute;
  inset: 2px;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  background: var(--surface);
  transition: background 220ms ease;
}

/* Icon + label */
.hex-inner {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  pointer-events: none;
  user-select: none;
}

.hex-inner img {
  width: 53px;
  height: 53px;
  object-fit: contain;
  border-radius: 6px;
  display: block;
}

.label {
  font-size: 10px;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  transition: color 220ms ease;
}

/* Hover — suppressed in arrange mode */
body:not(.edit-mode) .hex-wrap:hover .hex {
  transform: translateY(-4px);
  filter: drop-shadow(0 6px 16px color-mix(in srgb, var(--tile-color) 45%, transparent));
}
body:not(.edit-mode) .hex-wrap:hover .hex::before { background: var(--tile-color); }
body:not(.edit-mode) .hex-wrap:hover .hex::after  { background: color-mix(in srgb, var(--tile-color) 30%, #ffffff); }
body:not(.edit-mode) .hex-wrap:hover .label        { color: var(--text); }

/* Title tile — surface invisible, outline visible, reorderable */
.hex-wrap.title-tile .hex::after { background: var(--bg); }

.hex-wrap.title-tile .label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: normal;
  text-align: center;
  line-height: 1.4;
  padding: 0 16px;
}

/* ── Arrange mode ───────────────────────────────────────── */

/* Long-press indicator — outline darkens only, no layout shift */
.hex-wrap.pressing .hex::before { background: #c0bcb6; }

/* Selected tile — lifted, coloured */
.hex-wrap.selected .hex {
  transform: translateY(-6px) scale(1.06);
  filter: drop-shadow(0 8px 20px color-mix(in srgb, var(--tile-color) 50%, transparent));
}
.hex-wrap.selected .hex::before { background: var(--tile-color) !important; }
.hex-wrap.selected .hex::after  { background: color-mix(in srgb, var(--tile-color) 22%, #fff) !important; }

/* Swap target — pulsing outline on all non-selected tiles */
.hex-wrap.swap-target .hex::before {
  background: var(--tile-color);
  animation: pulse 700ms ease-in-out infinite alternate;
}

@keyframes pulse {
  from { opacity: 0.3; }
  to   { opacity: 0.65; }
}

/* Hint bar */
#edit-hint {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(42,40,37,0.82);
  color: #fff;
  font-size: 12px;
  letter-spacing: 0.06em;
  padding: 8px 20px;
  border-radius: 20px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 200ms ease;
  z-index: 300;
  white-space: nowrap;
}

body.edit-mode #edit-hint { opacity: 1; }

/* Responsive */
@media (max-width: 720px) {
  :root {
    --hex-w: 110px;
    --gap: 4px;
  }
  .hex-inner img { width: 38px; height: 38px; }
}
