@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@600;700;800&family=Nunito:wght@600;700;900&display=swap');

:root {
  --ink: #173c43;
  --cream: #fff5cf;
  --sand: #f7c96c;
  --coral: #ef654d;
  --ocean: #287889;
  --green: #68bd72;
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; overflow: hidden; }

body {
  margin: 0;
  background: #145361;
  color: var(--ink);
  font-family: "Nunito", ui-rounded, system-ui, sans-serif;
  overscroll-behavior: none;
  user-select: none;
}

button, a { font: inherit; }
button { color: inherit; }

#game-shell {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 420px;
  overflow: hidden;
  background: var(--ocean);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.hud {
  position: absolute;
  z-index: 4;
  top: max(12px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, 360px) minmax(180px, 1fr);
  gap: 18px;
  align-items: start;
  pointer-events: none;
}

.phase-block, .health-block, .held-card {
  filter: drop-shadow(0 3px 0 rgba(17, 61, 68, .18));
}

.phase-block { display: flex; flex-direction: column; align-items: flex-start; }
#phase-label {
  padding: 5px 14px 3px;
  border: 3px solid var(--ink);
  border-radius: 10px 10px 0 0;
  background: var(--cream);
  font: 800 24px/1 "Baloo 2", sans-serif;
}
#preview-label {
  max-width: 320px;
  padding: 7px 12px;
  border: 3px solid var(--ink);
  border-radius: 0 10px 10px 10px;
  background: rgba(255, 245, 207, .94);
  font-size: 12px;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.health-block {
  padding: 8px 10px 10px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--cream);
}
.health-copy { display: flex; justify-content: space-between; font-size: 12px; font-weight: 900; }
.health-track { height: 12px; margin-top: 4px; overflow: hidden; border: 2px solid var(--ink); border-radius: 20px; background: #d8c99a; }
.health-track i { display: block; width: 100%; height: 100%; background: var(--green); transition: width .2s, background .2s; }

.hud-actions { display: flex; justify-content: flex-end; gap: 8px; pointer-events: auto; }
.round-button, .icon-button, .night-button, .action-button, .big-button, .build-button, .close-button {
  border: 3px solid var(--ink);
  background: var(--cream);
  box-shadow: 0 4px 0 var(--ink);
  font-weight: 900;
  cursor: pointer;
  transition: transform .1s, box-shadow .1s, filter .1s;
}
button:hover { filter: brightness(1.06); }
button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.round-button { padding: 9px 14px; border-radius: 12px; font-size: 12px; }
.icon-button { width: 42px; height: 42px; border-radius: 50%; font-size: 20px; }

.bottom-bar {
  position: absolute;
  z-index: 4;
  left: 16px;
  right: 16px;
  bottom: max(15px, env(safe-area-inset-bottom));
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}
.held-card {
  min-width: 180px;
  padding: 7px 12px;
  border: 3px solid var(--ink);
  border-radius: 11px;
  background: var(--cream);
}
.held-card span { display: block; font-size: 9px; font-weight: 900; letter-spacing: .1em; }
.held-card b { display: block; font: 800 17px/1.1 "Baloo 2", sans-serif; }
.night-button, .action-button { pointer-events: auto; padding: 11px 18px 8px; border-radius: 12px; background: #ed7659; color: #fff8dc; font: 800 18px/1 "Baloo 2", sans-serif; letter-spacing: .03em; }
.action-button { margin-left: auto; background: #ffd05d; color: var(--ink); }
.night-button[hidden], .action-button[hidden] { display: none; }

.toast, .context-hint {
  position: absolute;
  z-index: 6;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  text-align: center;
}
.toast {
  top: 22%;
  opacity: 0;
  padding: 9px 18px 6px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--cream);
  font: 800 22px/1 "Baloo 2", sans-serif;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, -8px); }
.context-hint { bottom: 82px; padding: 5px 10px; border-radius: 8px; background: rgba(23,60,67,.82); color: white; font-size: 12px; font-weight: 900; opacity: 0; transition: opacity .15s; }
.context-hint.show { opacity: 1; }

.drawer {
  position: absolute;
  z-index: 10;
  top: 0;
  right: 0;
  width: min(430px, 94vw);
  height: 100%;
  padding: max(20px, env(safe-area-inset-top)) 18px max(20px, env(safe-area-inset-bottom));
  overflow-y: auto;
  transform: translateX(105%);
  transition: transform .25s cubic-bezier(.2,.9,.3,1);
  border-left: 4px solid var(--ink);
  background: #fff4c9;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer-head small { font-weight: 900; letter-spacing: .14em; }
.drawer h2 { margin: -6px 0 0; font: 800 42px/1 "Baloo 2", sans-serif; }
.close-button { width: 42px; height: 42px; border-radius: 50%; font-size: 28px; line-height: 30px; }
.drawer-intro { margin: 8px 0 14px; font-size: 13px; }
.storage-strip { display: flex; gap: 5px; min-height: 34px; padding: 7px; overflow-x: auto; border: 2px dashed #9f8b54; border-radius: 9px; }
.storage-pill { flex: 0 0 auto; padding: 3px 7px; border: 2px solid var(--ink); border-radius: 20px; background: white; font-size: 11px; font-weight: 900; }
.storage-empty { font-size: 12px; opacity: .65; }
.recipe-list { display: grid; gap: 10px; margin-top: 12px; }
.recipe-card { display: grid; grid-template-columns: 52px 1fr auto; gap: 10px; align-items: center; padding: 9px; border: 3px solid #9a8b63; border-radius: 12px; background: #e9ddb3; opacity: .73; }
.recipe-card.ready { border-color: var(--ink); background: white; opacity: 1; box-shadow: 0 4px 0 rgba(23,60,67,.25); }
.weapon-badge { display: grid; place-items: center; width: 58px; height: 52px; padding: 3px; border: 3px solid var(--ink); border-radius: 12px; background: color-mix(in srgb, var(--weapon-color, #78c8c6) 28%, white); overflow: hidden; }
.weapon-badge img { display: block; width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 2px 0 rgba(23, 60, 67, .18)); }
.recipe-name { font: 800 17px/1 "Baloo 2", sans-serif; }
.ingredients { display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 5px; }
.ingredient { font-size: 10px; font-weight: 900; color: #766d51; }
.ingredient.have { color: #268348; }
.build-button { padding: 8px 10px 6px; border-radius: 8px; background: #67bd72; color: white; font: 900 12px/1 "Baloo 2", sans-serif; }
.build-button:disabled { cursor: not-allowed; background: #b3aa8e; box-shadow: none; transform: none; }

.scrim { position: absolute; z-index: 8; inset: 0; visibility: hidden; opacity: 0; background: rgba(9, 42, 48, .55); transition: opacity .2s; }
.scrim.show { visibility: visible; opacity: 1; }
.modal {
  position: absolute;
  z-index: 20;
  top: 50%; left: 50%;
  width: min(560px, calc(100% - 30px));
  max-height: calc(100% - 30px);
  overflow-y: auto;
  transform: translate(-50%, -50%);
  padding: 24px;
  border: 4px solid var(--ink);
  border-radius: 24px;
  background: var(--cream);
  box-shadow: 0 10px 0 rgba(15,55,62,.45);
  text-align: center;
}
.modal[hidden] { display: none; }
.title-art { width: min(450px, 100%); height: auto; }
.start-screen p { max-width: 430px; margin: 8px auto 20px; font-size: 17px; }
.big-button { padding: 12px 25px 9px; border-radius: 12px; background: #ef6b51; color: white; font: 800 23px/1 "Baloo 2", sans-serif; }
.text-button { display: block; margin: 14px auto; border: 0; background: none; text-decoration: underline; font-weight: 900; cursor: pointer; }
.back-link { display: inline-block; margin-top: 8px; color: var(--ink); font-size: 12px; font-weight: 900; }
.how-screen { text-align: left; }
.how-screen > .close-button { position: absolute; top: 14px; right: 14px; }
.how-screen h2 { margin: 0 40px 18px 0; font: 800 30px/1 "Baloo 2", sans-serif; }
.how-grid { display: grid; gap: 12px; }
.how-grid div { display: grid; grid-template-columns: 42px 1fr; gap: 10px; align-items: center; }
.how-grid b { display: grid; place-items: center; width: 40px; height: 40px; border: 3px solid var(--ink); border-radius: 50%; background: #ffd25f; font: 800 22px/1 "Baloo 2"; }
.how-screen .big-button { display: block; margin: 22px auto 0; }
.end-screen h1 { margin: 2px 0 15px; font: 800 clamp(34px, 8vw, 58px)/.9 "Baloo 2", sans-serif; }
.end-screen > p { margin: 0; font-weight: 900; letter-spacing: .12em; }
.stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 16px 0 22px; }
.stat { min-width: 100px; padding: 9px; border: 2px solid var(--ink); border-radius: 10px; background: white; }
.stat b { display: block; font: 800 22px/1 "Baloo 2"; }
.stat span { font-size: 9px; font-weight: 900; letter-spacing: .08em; }

@media (max-width: 700px) {
  .hud { left: 8px; right: 8px; grid-template-columns: 1fr auto; gap: 6px; }
  .health-block { grid-column: 1 / -1; grid-row: 2; width: min(320px, 78vw); justify-self: center; padding: 5px 8px 7px; }
  #preview-label { max-width: 210px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #phase-label { font-size: 19px; }
  .round-button { font-size: 10px; padding: 8px 10px; }
  .icon-button { width: 38px; height: 38px; }
  .bottom-bar { left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); }
  .held-card { min-width: 0; max-width: 42vw; padding: 6px 8px; }
  .held-card b { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 14px; }
  .night-button, .action-button { padding: 10px 11px 7px; font-size: 14px; }
  .context-hint { display: none; }
}

@media (max-height: 560px) {
  #preview-label { display: none; }
  .health-block { max-width: 280px; }
  .hud { grid-template-columns: 150px 1fr auto; }
  .health-block { grid-column: auto; grid-row: auto; }
  .held-card span { display: none; }
}
