:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #eae5da;
  --ink: #231f20;
  --muted: #6e675f;
  --accent: #ff6b35;
  --shadow: 0 6px 18px rgba(35, 31, 32, 0.08);
  --radius: 16px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  overflow: hidden;
}

#app {
  max-width: 520px;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 10px 14px 14px;
  gap: 10px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--surface);
  padding: 10px 12px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-icon {
  font-size: 24px;
  line-height: 1;
}

#level-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.progress-bar {
  width: 110px;
  height: 7px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ff7a45, #ffb347);
  border-radius: 999px;
  transition: width 0.25s ease;
}

#progress-text {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  border: none;
  background: var(--surface-2);
  color: var(--ink);
  height: 34px;
  min-width: 34px;
  padding: 0 8px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}

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

.pill-btn {
  border: none;
  background: var(--ink);
  color: #fff;
  height: 34px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.pill-btn.primary {
  background: var(--accent);
}

.pill-btn.secondary {
  background: var(--surface-2);
  color: var(--ink);
}

.pill-btn:active {
  transform: scale(0.95);
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.hint-banner {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(35, 31, 32, 0.85);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
}

.tray-area {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.slots-label,
.stream-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.stream-sub {
  font-weight: 500;
  font-size: 11px;
}

.active-slots {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.slot-cell {
  height: 54px;
  border-radius: 12px;
  background: var(--bg);
  border: 2px dashed #d5cec2;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.box-stream {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.stream-lane {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  background: var(--bg);
  padding: 6px;
  border-radius: 12px;
  min-height: 136px;
  position: relative;
}

.lane-count {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  margin-top: auto;
}

.lane-empty {
  margin: auto;
  font-size: 11px;
  font-weight: 600;
  color: #b5aea2;
}

.ant-box {
  width: 100%;
  height: 52px;
  border-radius: 11px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.22), inset 0 2px 0 rgba(255, 255, 255, 0.28);
  border: 2px solid rgba(0, 0, 0, 0.15);
  transition: transform 0.12s ease, opacity 0.15s ease, filter 0.15s ease;
}

.ant-box.selectable {
  cursor: pointer;
}

.ant-box.selectable:hover {
  transform: translateY(-2px);
}

.ant-box.selectable:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.22);
}

.ant-box.locked {
  opacity: 0.52;
  filter: saturate(0.75);
  cursor: not-allowed;
}

.ant-box.active-deploying {
  animation: pulseBox 0.7s infinite alternate ease-in-out;
}

.ant-box.waiting {
  opacity: 0.85;
}

@keyframes pulseBox {
  from { transform: scale(1); }
  to { transform: scale(1.04); }
}

.box-count {
  font-size: 16px;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.box-sub {
  font-size: 10px;
  opacity: 0.92;
  margin-top: 2px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.box-match-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.2);
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(35, 31, 32, 0.45);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.hidden {
  display: none !important;
}

.modal-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.22);
}

.modal-card.center {
  text-align: center;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.level-card {
  border: 2px solid var(--surface-2);
  background: var(--bg);
  border-radius: 14px;
  padding: 12px;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: border-color 0.15s ease, transform 0.1s ease;
}

.level-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.level-card.cleared {
  border-color: #4caf50;
}

.level-emoji {
  font-size: 24px;
}

.level-meta {
  display: flex;
  flex-direction: column;
}

.level-name {
  font-size: 13px;
  font-weight: 700;
}

.level-info {
  font-size: 11px;
  color: var(--muted);
}

.end-emoji {
  font-size: 46px;
  margin-bottom: 6px;
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
}
