* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: 'Trebuchet MS', 'Segoe UI', sans-serif;
  background: #9fd8f5;
  user-select: none;
  -webkit-user-select: none;
}

canvas {
  display: block;
  touch-action: none;
}

.hidden {
  display: none !important;
}

/* ---------- Join screen ---------- */

#join-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(40, 90, 120, 0.6);
  z-index: 10;
}

.join-box {
  background: white;
  padding: 30px 40px;
  border-radius: 20px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.join-box h1 {
  margin-top: 0;
}

.join-box input {
  font-size: 22px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 2px solid #ccc;
  width: 220px;
  text-align: center;
}

.join-box input {
  margin-bottom: 4px;
}

.join-box .play-button,
.join-box button {
  display: block;
  margin: 16px auto 0;
  font-size: 22px;
  padding: 8px 30px;
  border: none;
  border-radius: 12px;
  background: #4caf50;
  color: white;
  cursor: pointer;
}

#character-choice {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.join-box .character {
  margin: 0;
  font-size: 40px;
  line-height: 1.2;
  padding: 8px 20px;
  background: #f1f3f5;
  color: #333;
  border: 3px solid transparent;
}

.join-box .character small {
  font-size: 18px;
}

.join-box .character.selected {
  border-color: #ff9800;
  background: #fff3e0;
}

/* ---------- Players (top left) ---------- */

#left-column {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  max-height: calc(100vh - 140px);
}

#players {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.player {
  background: rgba(255, 255, 255, 0.85);
  padding: 6px 12px;
  border-radius: 12px;
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.player.me {
  font-weight: bold;
  font-size: 22px;
}

.player.offline {
  opacity: 0.5;
}

.player .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
}

#join-screen .start-error {
  color: #c62828;
  font-weight: bold;
}

#join-screen .small-links {
  font-size: 14px;
  margin-top: 18px;
}

/* ---------- Tasks and islands (left, under the players) ---------- */

#islands-button {
  font-family: inherit;
  font-size: 18px;
  padding: 6px 12px;
  border: none;
  border-radius: 12px;
  background: #2196f3;
  color: white;
  cursor: pointer;
}

#islands {
  width: 300px;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 15px;
}

#islands .island-row {
  padding: 6px 0;
  border-bottom: 1px solid #eee;
}

#islands button,
#islands select,
#islands input {
  font-family: inherit;
  font-size: 14px;
  margin: 2px 4px 2px 0;
}

#islands button {
  border: none;
  border-radius: 8px;
  padding: 3px 8px;
  background: #4caf50;
  color: white;
  cursor: pointer;
}

#islands button:disabled {
  background: #ccc;
}

#islands .link-box {
  width: 100%;
  font-size: 12px;
}

/* ---------- Tasks (left, under the players) ---------- */

#tasks-button {
  font-family: inherit;
  font-size: 18px;
  padding: 6px 12px;
  border: none;
  border-radius: 12px;
  background: #ff9800;
  color: white;
  cursor: pointer;
}

#tasks {
  width: 300px;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 15px;
}

#tasks .task {
  padding: 8px 0;
  border-bottom: 1px solid #eee;
}

#tasks .goal.done {
  color: #2e7d32;
}

#tasks .reward {
  font-weight: bold;
}

#tasks h4 {
  margin: 10px 0 4px;
}

#tasks .hint {
  margin-bottom: 6px;
}

/* ---------- Messages (top middle) ---------- */

#messages {
  position: fixed;
  z-index: 20; /* above the start screen, so errors there can be seen */
  top: calc(10px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
}

.message {
  background: rgba(255, 255, 255, 0.92);
  padding: 8px 16px;
  border-radius: 12px;
  font-size: 18px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.15);
}

/* ---------- Info card (top right) ---------- */

#clock {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  right: 10px;
  background: rgba(255, 255, 255, 0.85);
  padding: 6px 14px;
  border-radius: 12px;
  font-size: 20px;
  font-weight: bold;
}

#clock:empty {
  display: none;
}

#info {
  position: fixed;
  top: 56px;
  right: 10px;
  width: 240px;
  background: rgba(255, 255, 255, 0.92);
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 16px;
}

#info h3 {
  margin: 0 0 6px;
}

.bar {
  height: 10px;
  background: #ddd;
  border-radius: 5px;
  overflow: hidden;
  margin: 2px 0 8px;
}

.bar div {
  height: 100%;
}

/* ---------- Help text ---------- */

#help {
  position: fixed;
  bottom: 186px;
  left: 50%;
  transform: translateX(-50%);
  color: white;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  font-size: 14px;
  pointer-events: none;
  white-space: nowrap;
}

/* ---------- Mute button (bottom right) ---------- */

#mute-button {
  position: fixed;
  right: 10px;
  bottom: 150px;
  font-size: 26px;
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.85);
  cursor: pointer;
}

/* ---------- Bottom bar: tabs + shop / tools / build ---------- */

#bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.75);
  /* Keep the buttons above the iPad/iPhone home bar. */
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

#tabs {
  display: flex;
  gap: 4px;
  padding: 6px 8px 0;
}

.tab {
  font-family: inherit;
  font-size: 16px;
  padding: 6px 16px;
  border: none;
  border-radius: 12px 12px 0 0;
  background: rgba(255, 255, 255, 0.6);
  cursor: pointer;
}

.tab.selected {
  background: white;
  font-weight: bold;
}

.tab-content {
  display: flex;
  gap: 6px;
  padding: 8px;
  overflow-x: auto;
}

.recipe {
  flex: 0 0 auto;
  width: 120px;
  height: 88px;
  background: white;
  border-radius: 14px;
  padding: 4px 6px;
  font-size: 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.recipe-title {
  font-weight: bold;
  font-size: 13px;
}

.recipe button {
  font-family: inherit;
  font-size: 12px;
  border: none;
  border-radius: 8px;
  padding: 2px 4px;
  background: #4caf50;
  color: white;
  cursor: pointer;
}

.recipe button.place {
  background: #2196f3;
}

.recipe button.place.selected {
  background: #ff9800;
}

.recipe button.make.missing {
  background: #bdbdbd;
}

.recipe button.make.done {
  background: #e0f2e9;
  color: #2e7d32;
  cursor: default;
}

.recipe-title {
  cursor: pointer;
}

#info .missing-item {
  color: #c62828;
}

#info .how-to-get {
  font-size: 13px;
  color: #555;
  margin: 0 0 6px 22px;
}

.recipe button:disabled {
  background: #ccc;
  cursor: default;
}

/* ---------- Bag (above the bottom bar) ---------- */

#bag {
  position: fixed;
  bottom: 150px;
  left: 10px;
  background: rgba(255, 255, 255, 0.85);
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 18px;
}

.shop-item {
  flex: 0 0 auto;
  width: 82px;
  height: 88px;
  border: 3px solid transparent;
  border-radius: 14px;
  background: white;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  padding: 2px;
}

.shop-item .icon {
  font-size: 30px;
  line-height: 1.1;
}

.shop-item .name {
  font-size: 12px;
}

.shop-item .cost {
  font-size: 12px;
  color: #2e7d32;
  font-weight: bold;
}

.shop-item.selected {
  border-color: #ff9800;
  background: #fff3e0;
}

.shop-item.too-expensive .cost {
  color: #c62828;
}

.shop-item.locked {
  opacity: 0.45;
  cursor: default;
}

.shop-item.locked .cost {
  color: #555;
  font-weight: normal;
  font-size: 10px;
  text-align: center;
}
