:root {
  --ink: #18231c;
  --paper: #fff8e6;
  --panel: rgba(255, 250, 235, 0.94);
  --leaf: #315b3f;
  --leaf-bright: #4b7f56;
  --earth: #9a6438;
  --clay: #c6753d;
  --gold: #e9b946;
  --aqua: #5aa6a6;
  --danger: #b34036;
  --line: rgba(42, 35, 25, 0.16);
  --shadow: 0 14px 34px rgba(24, 35, 28, 0.22);
  font-family:
    "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #213928;
  color: var(--ink);
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  touch-action: manipulation;
}

button {
  font: inherit;
}

.app-shell {
  min-height: 100dvh;
  padding: max(10px, env(safe-area-inset-top)) 10px max(12px, env(safe-area-inset-bottom));
  background:
    linear-gradient(rgba(29, 62, 43, 0.62), rgba(29, 62, 43, 0.88)),
    url("./assets/yoshinogari-bg.png") center / cover fixed;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  max-width: 1120px;
  margin: 0 auto 10px;
  color: white;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
}

.place {
  margin: 0 0 2px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  color: #ffe49a;
}

h1 {
  margin: 0;
  font-size: clamp(1.05rem, 4.8vw, 2rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.scoreboard {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  min-width: 84px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  background: rgba(20, 36, 28, 0.58);
  text-align: right;
  font-size: 0.78rem;
  font-weight: 800;
  backdrop-filter: blur(8px);
}

.scoreboard b {
  font-size: 1.05rem;
  color: #ffe49a;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  max-width: 1120px;
  margin: 0 auto;
}

.scene-panel {
  position: relative;
  overflow: hidden;
  min-height: 154px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  isolation: isolate;
}

.scene-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 58%;
  z-index: -2;
}

.scene-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(26, 39, 28, 0.58), rgba(26, 39, 28, 0.08) 52%, rgba(26, 39, 28, 0.34));
  z-index: -1;
}

.onikin {
  position: absolute;
  right: max(8px, 3vw);
  bottom: -12px;
  width: min(32vw, 170px);
  min-width: 106px;
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.28));
  pointer-events: none;
}

.bubble {
  position: absolute;
  left: 12px;
  bottom: 12px;
  width: min(62%, 520px);
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 8px;
  background: rgba(255, 248, 230, 0.92);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1.42;
}

.dig-zone {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  background: #7c502f;
  box-shadow: var(--shadow);
}

#digCanvas {
  display: block;
  width: 100%;
  height: min(48dvh, 470px);
  min-height: 290px;
  touch-action: none;
  cursor: crosshair;
}

.dig-status {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 6px 8px;
  border: 1px solid rgba(255, 255, 255, 0.44);
  border-radius: 8px;
  background: rgba(39, 28, 20, 0.58);
  color: white;
  font-size: 0.74rem;
  font-weight: 800;
}

.tool-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.tool,
.tab-button,
.primary-action {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 8px 18px rgba(18, 28, 22, 0.16);
  font-weight: 900;
}

.tool {
  display: grid;
  grid-template-columns: 24px minmax(0, auto);
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 6px;
  font-size: 0.88rem;
}

.tool.active {
  border-color: rgba(255, 255, 255, 0.36);
  background: #f6c64d;
  box-shadow: inset 0 -3px 0 rgba(121, 76, 28, 0.24), 0 8px 18px rgba(18, 28, 22, 0.2);
}

.tool.ghost {
  background: rgba(255, 248, 230, 0.78);
}

.tool-icon {
  position: relative;
  display: inline-block;
  width: 24px;
  height: 24px;
}

.trowel-icon::before {
  content: "";
  position: absolute;
  inset: 2px 5px 8px 5px;
  border-radius: 10px 10px 4px 4px;
  background: #859097;
  transform: rotate(-26deg);
}

.trowel-icon::after {
  content: "";
  position: absolute;
  left: 12px;
  bottom: 1px;
  width: 5px;
  height: 14px;
  border-radius: 5px;
  background: #7a4f2c;
  transform: rotate(-26deg);
}

.brush-icon::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 9px;
  width: 6px;
  height: 13px;
  border-radius: 5px;
  background: #8b552f;
}

.brush-icon::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 2px;
  width: 14px;
  height: 11px;
  border-radius: 8px 8px 3px 3px;
  background: repeating-linear-gradient(90deg, #f1d18a 0 2px, #cda360 2px 4px);
}

.box-icon::before {
  content: "";
  position: absolute;
  inset: 6px 3px 4px;
  border: 3px solid #8d5b35;
  border-top-width: 5px;
  background: #d99a4f;
}

.reset-icon::before,
.reset-icon::after {
  content: "";
  position: absolute;
}

.reset-icon::before {
  inset: 5px;
  border: 3px solid var(--leaf);
  border-right-color: transparent;
  border-radius: 50%;
}

.reset-icon::after {
  right: 4px;
  top: 3px;
  width: 0;
  height: 0;
  border-left: 7px solid var(--leaf);
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
}

.lower-tabs {
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tab-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--line);
}

.tab-button {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: rgba(255, 255, 255, 0.2);
}

.tab-button.active {
  background: #315b3f;
  color: white;
}

.tab-panel {
  display: none;
  padding: 10px;
}

.tab-panel.active {
  display: block;
}

.artifact-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(66px, 1fr));
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.artifact-card {
  min-width: 66px;
  min-height: 76px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf5;
  text-align: center;
}

.artifact-card .icon {
  display: grid;
  place-items: center;
  height: 42px;
  margin-bottom: 4px;
}

.artifact-card img {
  max-width: 44px;
  max-height: 42px;
  object-fit: contain;
  filter: drop-shadow(0 3px 3px rgba(68, 45, 28, 0.18));
}

.artifact-card.locked {
  color: rgba(24, 35, 28, 0.44);
  background: rgba(255, 255, 255, 0.54);
}

.artifact-card.broken {
  color: var(--danger);
  background: #fff0ec;
}

.artifact-card span {
  display: block;
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1.2;
}

#villageCanvas {
  display: block;
  width: 100%;
  height: 220px;
  border-radius: 8px;
  background: #bedf95;
}

.fact-dialog {
  width: min(92vw, 420px);
  padding: 18px;
  border: 0;
  border-radius: 8px;
  background: #fffaf0;
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}

.fact-dialog::backdrop {
  background: rgba(18, 26, 23, 0.58);
  backdrop-filter: blur(4px);
}

.close-dialog {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: #e8dcc5;
}

.close-dialog::before,
.close-dialog::after {
  content: "";
  position: absolute;
  left: 10px;
  top: 16px;
  width: 14px;
  height: 2px;
  background: var(--ink);
}

.close-dialog::before {
  transform: rotate(45deg);
}

.close-dialog::after {
  transform: rotate(-45deg);
}

.fact-kicker {
  margin: 0 0 4px;
  color: var(--clay);
  font-size: 0.78rem;
  font-weight: 900;
}

.fact-dialog h2 {
  margin: 0 36px 8px 0;
  font-size: 1.35rem;
  letter-spacing: 0;
}

.fact-dialog p {
  line-height: 1.65;
}

.fact-image {
  display: block;
  width: min(46vw, 150px);
  height: 120px;
  margin: 4px auto 10px;
  object-fit: contain;
  filter: drop-shadow(0 8px 10px rgba(91, 57, 30, 0.22));
}

.primary-action {
  width: 100%;
  background: var(--leaf);
  color: white;
}

@media (min-width: 860px) {
  .app-shell {
    padding: 18px;
  }

  .game-layout {
    grid-template-columns: minmax(360px, 0.95fr) minmax(420px, 1.25fr);
    align-items: start;
  }

  .scene-panel {
    min-height: 610px;
    grid-row: span 4;
  }

  .scene-bg {
    object-position: center;
  }

  .onikin {
    right: 18px;
    width: min(28vw, 310px);
  }

  .bubble {
    top: 22px;
    bottom: auto;
    width: min(72%, 400px);
    font-size: 1rem;
  }

  #digCanvas {
    height: 474px;
  }

  .artifact-grid {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }
}

@media (max-width: 380px) {
  .tool {
    grid-template-columns: 1fr;
    gap: 1px;
    font-size: 0.76rem;
  }

  .tool-icon {
    margin: 0 auto;
  }

  #digCanvas {
    min-height: 268px;
  }

  .bubble {
    font-size: 0.78rem;
  }
}
