:root {
  color-scheme: light;
  --ink: #213342;
  --muted: #5b6f7a;
  --paper: rgba(255, 250, 232, 0.9);
  --paper-strong: rgba(255, 248, 218, 0.96);
  --edge: rgba(78, 82, 45, 0.25);
  --leaf: #2f7d4d;
  --leaf-dark: #20563e;
  --sand: #f3c77d;
  --water: #229bd0;
  --shadow: rgba(15, 45, 69, 0.22);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #1499cc;
  color: var(--ink);
  font-family:
    ui-rounded,
    "SF Pro Rounded",
    "Nunito",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button {
  font: inherit;
}

#gameCanvas {
  display: block;
  width: 100vw;
  height: 100vh;
  image-rendering: pixelated;
  background: var(--water);
  cursor: crosshair;
  touch-action: none;
}

#overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.topbar,
.quest-panel,
.inventory-panel,
.mini-map,
.friend-panel,
.hint-card,
.toolbar,
.reset-button,
.shop-card {
  border: 1px solid var(--edge);
  box-shadow: 0 12px 28px var(--shadow);
  backdrop-filter: blur(10px);
}

.topbar {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--paper);
}

.brand {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.brand strong {
  font-size: 18px;
  line-height: 1.1;
}

.brand span,
.stat {
  color: var(--muted);
  font-size: 13px;
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.stat {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
}

.stat b {
  color: var(--ink);
}

.weather-chip {
  gap: 5px;
  font-weight: 700;
  color: var(--ink);
  transition: background 240ms ease;
}

.weather-chip b {
  font-size: 18px;
  line-height: 1;
}

.weather-chip[data-weather="sunny"] {
  background: linear-gradient(135deg, #fff3a6, #ffe07a);
}

.weather-chip[data-weather="cloudy"] {
  background: linear-gradient(135deg, #e8edf2, #cfd6df);
}

.weather-chip[data-weather="rainy"] {
  background: linear-gradient(135deg, #c8e1f2, #99b6cf);
}

.weather-chip[data-weather="foggy"] {
  background: linear-gradient(135deg, #e6e6dd, #c6c8c0);
}

.mute-button {
  min-height: 32px;
  width: 38px;
  border: 1px solid rgba(47, 125, 77, 0.3);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
  font-size: 16px;
  cursor: pointer;
  pointer-events: auto;
}

.mute-button[aria-pressed="true"] {
  background: #f4d1cc;
  border-color: rgba(168, 70, 60, 0.4);
}

.quest-panel,
.inventory-panel {
  position: absolute;
  left: 16px;
  width: min(310px, calc(100vw - 32px));
  padding: 12px;
  border-radius: 8px;
  background: var(--paper);
}

.quest-panel {
  top: 88px;
}

.inventory-panel {
  bottom: 92px;
}

.mini-map {
  position: absolute;
  right: 16px;
  top: 140px;
  width: 176px;
  padding: 10px;
  border-radius: 8px;
  background: var(--paper);
}

.friend-panel {
  position: absolute;
  right: 16px;
  top: 306px;
  width: 176px;
  padding: 10px;
  border-radius: 8px;
  background: var(--paper);
}

.friend-list {
  display: grid;
  gap: 8px;
}

.friend-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px;
  align-items: center;
  min-height: 40px;
  padding: 7px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
}

.friend-row.ready {
  background: #fff0bc;
}

.friend-icon {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.friend-name,
.friend-state {
  display: block;
}

.friend-name {
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.friend-hearts {
  color: #c95d6a;
  font-size: 12px;
  letter-spacing: 0;
}

.friend-state {
  color: var(--muted);
  font-size: 11px;
}

.mini-map-field {
  position: relative;
  height: 114px;
  overflow: hidden;
  border: 1px solid rgba(34, 91, 105, 0.24);
  border-radius: 7px;
  background: linear-gradient(145deg, #1598ca, #21add6);
}

.map-island,
.map-bridge,
.map-player {
  position: absolute;
  transform: translate(-50%, -50%);
}

.map-island {
  border: 1px solid rgba(61, 118, 53, 0.35);
  border-radius: 999px;
  background: #78ba4e;
  box-shadow: inset 0 0 0 2px rgba(154, 107, 61, 0.34);
}

.map-island.sand {
  background: #eec071;
}

.map-bridge {
  height: 5px;
  border-radius: 999px;
  background: #b87638;
}

.map-player {
  width: 9px;
  height: 9px;
  border: 2px solid #fff9c9;
  border-radius: 999px;
  background: #dc593f;
  box-shadow: 0 0 0 3px rgba(220, 89, 63, 0.22);
}

.panel-title {
  margin-bottom: 8px;
  color: var(--leaf-dark);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

#questList {
  display: grid;
  gap: 7px;
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
}

#questList li {
  padding-left: 2px;
}

#questList .done {
  color: var(--leaf);
  font-weight: 800;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  min-height: 28px;
  padding: 5px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--muted);
  font-size: 12px;
}

.chip b {
  color: var(--ink);
}

.toolbar {
  position: absolute;
  left: 50%;
  bottom: 18px;
  display: flex;
  gap: 7px;
  max-width: calc(100vw - 32px);
  padding: 8px;
  border-radius: 8px;
  background: var(--paper-strong);
  transform: translateX(-50%);
  pointer-events: auto;
}

.tool-button,
.icon-button,
.reset-button {
  border: 1px solid rgba(47, 125, 77, 0.3);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.78);
  cursor: pointer;
}

.tool-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-size: 20px;
}

.tool-button[disabled] {
  opacity: 0.38;
  cursor: not-allowed;
}

.tool-button.active {
  color: #173522;
  border-color: rgba(32, 86, 62, 0.82);
  background: #caedbd;
  box-shadow: inset 0 -3px 0 rgba(32, 86, 62, 0.18);
}

.hint-card {
  position: absolute;
  right: 16px;
  bottom: 92px;
  width: min(360px, calc(100vw - 32px));
  min-height: 58px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 9px 10px 9px 13px;
  border-radius: 8px;
  background: var(--paper);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.action-button {
  min-width: 82px;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(180deg, #3c9860, #27744e);
  box-shadow: inset 0 -3px 0 rgba(17, 64, 40, 0.24);
  cursor: pointer;
  font-weight: 800;
  pointer-events: auto;
}

.action-button:active {
  transform: translateY(1px);
  box-shadow: inset 0 -1px 0 rgba(17, 64, 40, 0.24);
}

.reset-button {
  position: absolute;
  right: 16px;
  top: 88px;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  font-size: 22px;
  pointer-events: auto;
}

.shop-dialog {
  width: min(520px, calc(100vw - 28px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

.shop-dialog::backdrop {
  background: rgba(20, 63, 82, 0.42);
}

.shop-card {
  margin: 0;
  padding: 16px;
  border-radius: 8px;
  background: var(--paper-strong);
  color: var(--ink);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.icon-button {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 22px;
}

#shopIntro {
  margin: 8px 0 14px;
  color: var(--muted);
  font-size: 14px;
}

.shop-grid {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.shop-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
}

.shop-row strong {
  display: block;
  font-size: 15px;
}

.shop-row span {
  color: var(--muted);
  font-size: 12px;
}

.shop-row .shop-detail {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  opacity: 0.8;
}

.shop-row button,
.primary-button {
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--leaf);
  cursor: pointer;
}

.shop-row button {
  padding: 0 12px;
}

.shop-row button[disabled] {
  opacity: 0.42;
  cursor: not-allowed;
}

.primary-button {
  width: 100%;
  padding: 0 14px;
  font-weight: 800;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 8px;
  color: #173522;
  background: #fff3b3;
  box-shadow: 0 12px 30px var(--shadow);
  opacity: 0;
  transform: translate(-50%, 12px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
  pointer-events: none;
}

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

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
  }

  .quest-panel {
    top: auto;
    bottom: 150px;
    max-height: 178px;
    overflow: auto;
  }

  .inventory-panel {
    display: none;
  }

  .mini-map {
    display: none;
  }

  .friend-panel {
    display: none;
  }

  .hint-card {
    right: 16px;
    left: 16px;
    bottom: 84px;
    width: auto;
    grid-template-columns: 1fr 76px;
  }

  .toolbar {
    overflow-x: hidden;
    justify-content: flex-start;
    gap: 5px;
    padding: 6px;
  }

  .tool-button {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    font-size: 18px;
  }
}
