:root {
  --ink: #2b2118;
  --paper: #fffaf0;
  --accent: #e0702c;
  --accent-dark: #b2521a;
  --wood: #a8692f;
  --stone: #8d949b;
  --panel: rgba(255, 250, 240, 0.92);
  --danger: #c0392b;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #24452a;
  color: var(--ink);
  font-family: 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'Noto Sans JP', 'Yu Gothic', 'Meiryo', sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
canvas#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  touch-action: none;
}
.hidden {
  display: none !important;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
}
#hud-top {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.panel {
  background: var(--panel);
  border-radius: 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  padding: 6px 10px;
  font-size: 14px;
  line-height: 1.3;
}
#pack {
  min-width: 120px;
}
.pack-label {
  font-size: 12px;
}
.pack-label b {
  font-size: 16px;
}
#pack-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 3px;
  max-width: 180px;
}
.slot {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1.5px dashed rgba(0, 0, 0, 0.25);
}
.slot.wood {
  background: var(--wood);
  border: 1.5px solid #6e4019;
}
.slot.stone {
  background: var(--stone);
  border: 1.5px solid #5d636a;
}
#pack.full {
  outline: 3px solid var(--accent);
}
#objective {
  flex: 1;
  font-size: 15px;
  font-weight: bold;
  text-align: center;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
}
#hud-right {
  display: flex;
  gap: 6px;
  align-items: flex-start;
}
#clock {
  font-variant-numeric: tabular-nums;
  font-weight: bold;
}
.icon-btn {
  pointer-events: auto;
  width: 40px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--panel);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  font-size: 16px;
  font-weight: bold;
  color: var(--ink);
  cursor: pointer;
}
#workers {
  display: inline-block;
  margin-top: 6px;
  font-size: 13px;
  white-space: pre-line;
  background: rgba(61, 111, 158, 0.92);
  color: #fff;
}
#toasts {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(90vw, 460px);
}
.toast {
  background: rgba(43, 33, 24, 0.85);
  color: #fff;
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 15px;
  text-align: center;
  animation: toast-in 0.25s ease-out;
}
.toast.big {
  background: var(--accent);
  font-size: 20px;
  font-weight: bold;
  padding: 10px 22px;
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.toast.big small {
  display: block;
  font-size: 13px;
  font-weight: normal;
}
.toast.fade {
  opacity: 0;
  transition: opacity 0.4s;
}
@keyframes toast-in {
  from {
    transform: scale(0.7);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}
#actions {
  position: absolute;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}
.act-btn {
  pointer-events: auto;
  border: none;
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 15px;
  font-weight: bold;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  min-width: 110px;
}
.act-btn.key::after {
  content: attr(data-key);
  font-size: 11px;
  opacity: 0.6;
  margin-left: 6px;
}

/* ---------- 画面 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 35, 22, 0.55);
  padding: 16px;
  z-index: 10;
}
.card {
  background: var(--paper);
  border-radius: 18px;
  padding: 20px 22px;
  width: min(440px, 100%);
  max-height: 100%;
  overflow: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  touch-action: pan-y;
}
.card h1 {
  margin: 0 0 4px;
  font-size: 30px;
  color: var(--accent-dark);
  letter-spacing: 0.05em;
}
.card h2 {
  margin: 0 0 10px;
  font-size: 22px;
}
.sub {
  margin: 0 0 14px;
}
.howto {
  padding-left: 1.1em;
  margin: 0 0 16px;
  line-height: 1.6;
  font-size: 14px;
}
.buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.btn {
  border: none;
  border-radius: 12px;
  padding: 12px;
  font-size: 17px;
  font-weight: bold;
  background: #e9e1d2;
  color: var(--ink);
  cursor: pointer;
}
.btn.primary {
  background: var(--accent);
  color: #fff;
}
.btn.danger {
  background: #f3d6d2;
  color: var(--danger);
}
.tiny {
  font-size: 12px;
  opacity: 0.7;
  margin: 12px 0 0;
  text-align: center;
}
.tiny a {
  color: inherit;
}
.result-time {
  font-size: 36px;
  font-weight: bold;
  text-align: center;
  margin: 4px 0 8px;
  color: var(--accent-dark);
}
.result-list {
  font-size: 14px;
  line-height: 1.7;
  margin: 0 0 14px;
  padding-left: 1.1em;
}

@media (max-width: 600px) {
  #hud-top {
    flex-wrap: wrap;
  }
  #objective {
    order: 3;
    flex-basis: 100%;
    font-size: 14px;
  }
  #pack {
    flex: 1;
  }
  .panel {
    font-size: 13px;
  }
}

@media (hover: none) {
  .act-btn.key::after {
    display: none;
  }
}
