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

:root {
  --accent: #0ea5e9;
  --accent-2: #10b981;
  --accent-ink: #075985;
  --text: #1e293b;
  --glass: rgba(255, 255, 255, 0.92);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

html,
body {
  height: 100%;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 16%, rgba(255, 255, 255, 0.16), transparent 34%),
    radial-gradient(circle at 88% 84%, rgba(255, 255, 255, 0.12), transparent 36%),
    linear-gradient(135deg, #0ea5e9, #0f766e);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 14px 30px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100vh;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.28));
  background: #fff;
  flex-shrink: 0;
}

.brand h1 {
  font-size: 1.42rem;
  line-height: 1.08;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
}

.tagline {
  font-size: 0.74rem;
  opacity: 0.85;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 600;
  margin-top: 2px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  border: none;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.2);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: #fff;
  font-size: 1.2rem;
  transition: transform 0.15s ease, background 0.2s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.34);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: scale(0.94);
}

/* ---------- Controls ---------- */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: flex-end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.92);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 460px;
}

.chip {
  border: none;
  cursor: pointer;
  font-weight: 800;
  font-family: inherit;
  color: #fff;
  background: rgba(255, 255, 255, 0.22);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
  transition: transform 0.12s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.chip:hover:not(:disabled) {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.4);
}

.chip.active {
  background: var(--accent);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
}

.chip.level {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 1rem;
}

/* ---------- Stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  background: var(--glass);
  border-radius: 18px;
  padding: 10px;
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-value {
  font-weight: 800;
  font-size: 1.12rem;
  color: #0f172a;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #64748b;
}

/* ---------- How-to hint ---------- */
.howto {
  text-align: center;
  color: #fff;
  font-size: 0.92rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  padding: 8px 12px;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

/* ---------- Play area ---------- */
.play {
  display: grid;
  gap: 14px;
  align-items: start;
}

.map-card {
  width: 100%;
  background: #fff;
  border-radius: 22px;
  padding: 10px;
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.map {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 14px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
}

body.holding .map {
  touch-action: none;
}

.land {
  fill: #fef3c7;
  stroke: #94a3b8;
  stroke-width: 2.5;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgba(71, 85, 105, 0.35));
}

.island-label {
  fill: #94a3b8;
  font-family: "Segoe UI", system-ui, Arial, sans-serif;
  font-size: 30px;
  font-weight: 800;
  text-anchor: middle;
  opacity: 0.7;
  pointer-events: none;
}

.ghost {
  pointer-events: none;
}

.ghost-circle {
  fill: rgba(14, 165, 233, 0.12);
  stroke: rgba(14, 165, 233, 0.55);
  stroke-width: 2;
  stroke-dasharray: 7 6;
  animation: ghostPulse 2.2s ease-in-out infinite;
}

.ghost-name {
  fill: rgba(71, 85, 105, 0.6);
  font-family: "Segoe UI", system-ui, Arial, sans-serif;
  font-size: 19px;
  font-weight: 700;
  text-anchor: middle;
}

.pin-dot {
  fill: url(#pin-grad);
  stroke: #fff;
  stroke-width: 3.5;
  filter: drop-shadow(0 2px 3px rgba(2, 44, 68, 0.4));
  animation: pinPop 0.35s cubic-bezier(0.34, 1.5, 0.64, 1) both;
}

.pin-name {
  font-family: "Segoe UI", system-ui, Arial, sans-serif;
  font-size: 17px;
  font-weight: 800;
  text-anchor: middle;
  fill: #0f172a;
  stroke: #fff;
  stroke-width: 4px;
  paint-order: stroke;
}

.hint-ring {
  fill: none;
  stroke: #ef4444;
  stroke-width: 3;
  stroke-dasharray: 8 7;
  animation: hintPulse 0.8s ease-out forwards;
  pointer-events: none;
}

/* ---------- Tray ---------- */
.tray {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 18px;
  padding: 12px;
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  min-height: 74px;
}

.chip-city {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 108px;
  min-height: 52px;
  padding: 8px 14px;
  border: none;
  border-radius: 14px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  font-family: inherit;
  font-weight: 800;
  font-size: 0.98rem;
  line-height: 1.15;
  color: #0f172a;
  background: linear-gradient(145deg, #ffffff, #f0f9ff);
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.18), inset 0 0 0 1px rgba(14, 165, 233, 0.22);
  transition: transform 0.14s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.chip-city .chip-island {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
}

.chip-city:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.24);
}

.chip-city:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.chip-city.held {
  background: linear-gradient(145deg, #e0f2fe, #bae6fd);
  box-shadow: 0 0 0 3px var(--accent), 0 9px 22px rgba(0, 0, 0, 0.26);
  transform: translateY(-4px) scale(1.04);
  z-index: 5;
}

.chip-city.dragging {
  position: fixed;
  z-index: 45;
  left: 0;
  top: 0;
  transform: translate(-50%, -70%) scale(1.08) rotate(-2deg);
  margin: 0;
  cursor: grabbing;
  pointer-events: none;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.32), 0 0 0 3px rgba(255, 255, 255, 0.8);
}

.chip-city.shake {
  animation: shake 0.42s ease;
}

.chip-city.placed {
  animation: chipGone 0.4s ease forwards;
  pointer-events: none;
}

/* ---------- Footer ---------- */
.footer {
  text-align: center;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.78rem;
  margin-top: auto;
  padding-top: 10px;
}

/* ---------- Win overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.55);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  padding: 18px;
  animation: fadeIn 0.25s ease both;
}

.overlay[hidden] {
  display: none;
}

.modal {
  width: min(92vw, 400px);
  background: #fff;
  border-radius: 24px;
  padding: 26px 22px;
  text-align: center;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
  animation: popIn 0.35s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}

.modal-stars {
  font-size: 2.4rem;
  letter-spacing: 6px;
  line-height: 1;
}

.star {
  color: #cbd5e1;
}

.star.lit {
  color: #f59e0b;
  filter: drop-shadow(0 2px 5px rgba(245, 158, 11, 0.6));
}

.modal h2 {
  margin: 8px 0 2px;
  font-size: 1.5rem;
  color: #0f172a;
}

.modal-subtitle {
  color: #64748b;
  font-size: 0.9rem;
  margin-bottom: 14px;
}

.modal-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 16px 0 20px;
}

.modal-stats div {
  background: #f1f5f9;
  border-radius: 12px;
  padding: 8px 4px;
}

.modal-stats span {
  display: block;
  font-weight: 800;
  font-size: 1rem;
  color: #0f172a;
  font-variant-numeric: tabular-nums;
}

.modal-stats label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #64748b;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  padding: 13px 16px;
  border: none;
  border-radius: 14px;
  font-weight: 700;
  font-size: 0.98rem;
  font-family: inherit;
  cursor: pointer;
  background: #f1f5f9;
  color: #334155;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

.btn-primary:hover {
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}

.btn-ghost {
  background: transparent;
  color: #64748b;
}

/* ---------- Effects canvas ---------- */
.fx-canvas {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
}

/* ---------- No JS ---------- */
.noscript {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background: #f8fafc;
  color: #334155;
  font-weight: 600;
}

/* ---------- Animations ---------- */
@keyframes ghostPulse {
  0%, 100% {
    opacity: 0.75;
  }
  50% {
    opacity: 1;
  }
}

@keyframes pinPop {
  from {
    transform: scale(0.3);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes hintPulse {
  0% {
    r: 14px;
    opacity: 0.9;
  }
  100% {
    r: 44px;
    opacity: 0;
  }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

@keyframes chipGone {
  to {
    transform: scale(0.4);
    opacity: 0;
  }
}

@keyframes popIn {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------- Desktop: map left, tray right ---------- */
@media (min-width: 860px) {
  .play {
    grid-template-columns: minmax(0, 1fr) 250px;
  }

  .tray {
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    position: sticky;
    top: 12px;
  }

  .chip-city {
    width: 100%;
  }
}

/* ---------- Small screens ---------- */
@media (max-width: 560px) {
  .stats {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px 4px;
    padding: 8px 4px;
  }

  .stat-value {
    font-size: 1rem;
  }

  .brand h1 {
    font-size: 1.18rem;
  }

  .brand-logo {
    width: 46px;
    height: 46px;
  }

  .map-card {
    padding: 7px;
    border-radius: 18px;
  }

  .chip-city {
    min-width: 96px;
    min-height: 48px;
    font-size: 0.9rem;
    padding: 6px 10px;
  }
}
