:root {
  --ink: #3b2f22;
  --ink-soft: #7a6c5c;
  --paper: rgba(255, 255, 255, 0.9);
  --line: #eadfcd;
  --accent: #ffcf3a;
  --green: #4f9e3c;
  --green-dark: #3d7f2d;
  --red: #d9534f;
  --shadow: 0 4px 16px rgba(40, 60, 80, 0.18);
  --font: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Yu Gothic UI", system-ui, sans-serif;
  --top: max(10px, env(safe-area-inset-top));
  --bottom: max(10px, env(safe-area-inset-bottom));
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  font-weight: 500;
  color: var(--ink);
  background: linear-gradient(#a6d9fb, #dcf1ff 65%, #f2faff);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#view:active { cursor: grabbing; }

/* ---- 画面のふち ---- */

.hud { position: fixed; z-index: 2; }

.hud.top {
  top: var(--top);
  left: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.hud.top > * { pointer-events: auto; }
.spacer { flex: 1; }

.pill {
  background: var(--paper);
  border-radius: 999px;
  padding: 7px 13px;
  font-weight: 800;
  font-size: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  white-space: nowrap;
}
.coins { font-size: 16px; }
#online { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }

.hud.camera {
  top: calc(var(--top) + 50px);
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.hud.camera button {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: var(--shadow);
  font-size: 20px;
}

/* ---- 道具 ---- */

.hud.bottom {
  bottom: var(--bottom);
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  display: flex;
  gap: 6px;
  align-items: stretch;
  padding: 7px;
  background: var(--paper);
  border-radius: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.hud.bottom:empty { display: none; }

.tool {
  flex: none;
  min-width: 54px;
  height: 56px;
  padding: 4px 6px;
  border: none;
  border-radius: 15px;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}
.tool .icon { font-size: 22px; line-height: 1; }
.tool .label { font-size: 11px; font-weight: 800; }
.tool.active { background: var(--accent); }
.tool:not(.active):hover { background: rgba(0, 0, 0, 0.05); }

.divider { width: 1px; background: var(--line); margin: 6px 2px; flex: none; }

.seeds {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  min-width: 50px;
}
.seeds::-webkit-scrollbar { display: none; }
.seed {
  position: relative;
  flex: none;
  width: 50px;
  height: 56px;
  border: 2px solid transparent;
  border-radius: 15px;
  background: rgba(0, 0, 0, 0.04);
  font-size: 22px;
}
.seed.active { border-color: var(--green); background: #eaf6e2; }
.seed .count {
  position: absolute;
  right: 4px;
  bottom: 3px;
  font-size: 11px;
  font-weight: 800;
}
.seed.empty { font-size: 12px; font-weight: 800; width: auto; padding: 0 10px; }
.seed.building {
  width: auto;
  min-width: 64px;
  padding: 2px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}
.seed.building .b-emoji { font-size: 22px; line-height: 1; }
.seed.building .b-cost { font-size: 10px; font-weight: 800; white-space: nowrap; }
.seed.building.poor { opacity: 0.5; }
.seed.building.category { background: #fff3c4; }
.seed.building.rotate { background: #e8eef7; }
.seed.building.category .b-cost, .seed.building.rotate .b-cost { font-size: 9px; }

.empty-note.small { font-size: 12px; line-height: 1.6; padding: 4px 4px 8px; text-align: left; }
.section { font-weight: 800; font-size: 13px; margin: 10px 2px 2px; }
.row.log { font-size: 13px; padding: 7px 10px; }
.row.unknown { opacity: 0.6; }

/* 建てるときの建物の一覧（道具バーの上の段） */
.hud.subbar {
  bottom: calc(var(--bottom) + 80px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 24px);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  padding: 6px;
  background: var(--paper);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.hud.subbar[hidden] { display: none; }
.hud.subbar .seed.building { height: 50px; }
body.has-subbar .toasts { bottom: calc(var(--bottom) + 200px); }

/* ---- マスの説明 ---- */

.tip {
  position: fixed;
  z-index: 1;
  transform: translate(-50%, calc(-100% - 34px));
  background: var(--paper);
  border-radius: 12px;
  padding: 6px 11px;
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.45;
  pointer-events: none;
  white-space: nowrap;
  text-align: center;
}
.tip .place { color: var(--ink-soft); font-size: 11px; }
.tip .what { font-weight: 800; }

/* ---- お知らせ ---- */

.toasts {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: calc(var(--bottom) + 84px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.toast {
  background: rgba(59, 47, 34, 0.92);
  color: #fff;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 800;
  box-shadow: var(--shadow);
  animation: toast 2.6s ease forwards;
  white-space: nowrap;
}
.toast.error { background: rgba(196, 64, 60, 0.94); }
@keyframes toast {
  0% { opacity: 0; transform: translateY(8px); }
  8%, 85% { opacity: 1; transform: none; }
  100% { opacity: 0; }
}

.status {
  position: fixed;
  z-index: 4;
  top: calc(var(--top) + 50px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(59, 47, 34, 0.9);
  color: #fff;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 800;
}

/* ---- ダイアログ ---- */

dialog {
  border: none;
  border-radius: 24px;
  padding: 24px;
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  color: var(--ink);
  box-shadow: 0 12px 40px rgba(30, 50, 70, 0.3);
}
dialog::backdrop { background: rgba(30, 50, 70, 0.35); backdrop-filter: blur(3px); }
dialog h1, dialog h2 { margin: 0 0 8px; font-weight: 800; }
dialog h1 { font-size: 26px; }
dialog h2 { font-size: 20px; }
dialog p { margin: 0 0 16px; line-height: 1.7; color: var(--ink-soft); }

input[type="text"], input:not([type]) {
  width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: 14px;
  outline: none;
  margin-bottom: 12px;
  user-select: text;
}
input:focus { border-color: var(--green); }
dialog p.hint { margin: -6px 0 14px; font-size: 12px; line-height: 1.5; }

button.primary {
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 13px 18px;
  background: var(--green);
  color: #fff;
  font-weight: 800;
  font-size: 16px;
}
button.primary:hover { background: var(--green-dark); }

.small-btn {
  border: none;
  border-radius: 10px;
  padding: 7px 11px;
  background: #eef4ea;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}
.small-btn:hover { background: #e0ecd8; }
.small-btn:disabled { opacity: 0.4; cursor: default; }

/* お店と持ち物 */
#bag-dialog[open] {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: min(560px, calc(100dvh - 32px));
  max-height: calc(100dvh - 32px);
  padding: 18px;
}
.sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.sheet-head .spacer { flex: 1; }
.close-btn { border: none; background: none; font-size: 22px; padding: 4px; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button {
  flex: 1;
  white-space: nowrap;
  font-size: 13px;
  border: none;
  border-radius: 12px;
  padding: 9px;
  background: #f4efe6;
  font-weight: 800;
}
.tabs button.active { background: var(--accent); }
.rows { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; flex: 1; min-height: 0; }
.rows > * { flex: none; }
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 14px;
  background: #faf7f1;
}
.row .emoji { font-size: 26px; width: 32px; text-align: center; }
.row .info { flex: 1; min-width: 0; }
.row .name { font-weight: 800; }
.row .name, .row .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 12px; color: var(--ink-soft); }
.row .actions { display: flex; gap: 4px; }
.empty-note { text-align: center; color: var(--ink-soft); padding: 20px 0; }

.report-list { margin: 0 0 16px; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.report-list li { background: #faf7f1; border-radius: 12px; padding: 10px 12px; font-weight: 800; }

@media (max-width: 520px) {
  .tool { min-width: 48px; }
  .tool .label { font-size: 10px; }
  .seed { width: 46px; }
}
