* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #fff8ec;
  color: #3a2e25;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

body {
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #ffffff;
  box-shadow: 0 2px 10px rgba(90, 60, 30, 0.12);
  z-index: 2;
}

.topbar h1 {
  margin: 0 4px;
  font-size: 1.3rem;
  font-weight: 800;
  white-space: nowrap;
}

.spacer {
  flex: 1;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 8px 12px;
  background: #fff1d6;
  color: #3a2e25;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

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

.btn:focus-visible {
  outline: 3px solid #f59f00;
  outline-offset: 2px;
}

.rooms {
  display: flex;
  gap: 6px;
}

.rooms .btn[aria-pressed="true"] {
  background: #ffc078;
}

.found {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-size: 1.1rem;
}

.found-pencil {
  width: 44px;
  height: 12px;
}

.found-pencil rect,
.found-pencil polygon {
  fill: #d8d0c8;
  transition: fill 0.3s;
}

.found-pencil.got .body {
  fill: #ffc61a;
}

.found-pencil.got .eraser {
  fill: #ff8fab;
}

.found-pencil.got .ferrule {
  fill: #adb5bd;
}

.found-pencil.got .tip {
  fill: #f2c79a;
}

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  touch-action: none;
}

#stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

.zoom {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2;
}

.zoom .btn {
  width: 48px;
  height: 48px;
  font-size: 1.5rem;
  padding: 0;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 8px rgba(90, 60, 30, 0.2);
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  max-width: calc(100% - 140px);
  transform: translate(-50%, 20px);
  padding: 10px 18px;
  border-radius: 16px;
  background: rgba(58, 46, 37, 0.88);
  color: #ffffff;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 3;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(58, 46, 37, 0.35);
  z-index: 5;
}

.overlay[hidden] {
  display: none;
}

.overlay .card {
  max-width: 420px;
  width: 100%;
  padding: 24px;
  border-radius: 24px;
  background: #ffffff;
  box-shadow: 0 10px 30px rgba(58, 46, 37, 0.25);
  text-align: center;
}

.overlay h2 {
  margin: 0 0 12px;
  font-size: 1.5rem;
}

.overlay ul {
  margin: 0 0 20px;
  padding: 0;
  list-style: none;
  text-align: left;
  font-size: 1.1rem;
  line-height: 1.9;
}

.overlay ul li::before {
  content: "👉 ";
}

.overlay p {
  font-size: 1.1rem;
}

.overlay .row {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn.big {
  padding: 12px 24px;
  font-size: 1.2rem;
  background: #ffa94d;
}

@media (max-width: 600px) {
  .topbar {
    gap: 6px;
    padding: 6px 8px;
  }
  .topbar h1 {
    font-size: 1.1rem;
  }
  .btn {
    padding: 6px 9px;
    font-size: 0.95rem;
  }
  .found-pencil {
    width: 32px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #toast,
  .found-pencil rect,
  .found-pencil polygon {
    transition: none;
  }
}
