/* Cầu Tre Vượt Sông — tranh làng quê tươi: trời xanh, đất nâu, lá tre */
:root {
  --ink: #3a2a1a;
  --muted: #7d6a55;
  --panel: #fffaf0;
  --panel2: #f3e7cf;
  --line: rgba(90, 60, 30, 0.15);
  --accent: #2e9d5a;
  --accent2: #237a46;
  --gold: #e3a21a;
  --red: #e0533f;
  --shadow: 0 5px 0 rgba(90, 60, 30, 0.14), 0 12px 28px rgba(90, 60, 30, 0.14);
}
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
[hidden] {
  display: none !important;
}
html,
body {
  height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: "Be Vietnam Pro", system-ui, sans-serif;
  background: linear-gradient(180deg, #9ad7ff, #e9f7ff 55%, #cfe8a8);
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}
h1,
h2,
h3 {
  font-family: "Baloo 2", "Be Vietnam Pro", sans-serif;
}
.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}
.grow {
  flex: 1;
}
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- nút ---------- */
.btn {
  border: 0;
  background: var(--panel2);
  border-radius: 14px;
  padding: 11px 18px;
  font-weight: 800;
  font-size: 15px;
  box-shadow: 0 4px 0 rgba(90, 60, 30, 0.16);
  transition: transform 0.08s;
}
.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(90, 60, 30, 0.16);
}
.btn.primary,
.btn.go {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 0 var(--accent2);
}
.btn.go.stop {
  background: #e0833f;
  box-shadow: 0 4px 0 #a85a22;
}
.btn.big {
  padding: 15px 26px;
  font-size: 19px;
}
.btn.small {
  padding: 8px 12px;
  font-size: 13.5px;
}
.btn.danger {
  background: transparent;
  color: var(--red);
  box-shadow: none;
  border: 2px dashed rgba(224, 83, 63, 0.4);
}
.btn small {
  font-size: 13px;
  opacity: 0.85;
  margin-left: 4px;
}
.icon-btn {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 13px;
  border: 0;
  background: var(--panel);
  box-shadow: 0 3px 0 rgba(90, 60, 30, 0.14);
  font-size: 18px;
  font-weight: 900;
  display: grid;
  place-items: center;
}
.back {
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  font-size: 14px;
  padding: 10px 14px;
  border-radius: 13px;
  background: var(--panel);
  box-shadow: 0 3px 0 rgba(90, 60, 30, 0.14);
}
.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  flex: none;
}
.bar h2 {
  margin: 0;
  font-size: 24px;
}
.pill {
  font-weight: 900;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--panel);
  box-shadow: 0 3px 0 rgba(90, 60, 30, 0.12);
}
.seg {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  border-radius: 12px;
  background: var(--panel2);
}
.seg button {
  border: 0;
  background: transparent;
  border-radius: 9px;
  padding: 6px 10px;
  font-weight: 800;
  font-size: 13px;
  color: var(--muted);
}
.seg button.on {
  background: var(--accent);
  color: #fff;
}

/* ---------- sảnh ---------- */
.home {
  overflow: auto;
}
.home-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 0 16px 28px;
  text-align: center;
}
.logo {
  margin: 0;
  font-size: clamp(40px, 8vw, 64px);
  line-height: 0.95;
  font-weight: 800;
  color: #6b4423;
  text-shadow: 0 4px 0 rgba(255, 255, 255, 0.7);
}
.logo span {
  display: block;
  color: var(--accent);
}
.hero-pic {
  width: min(520px, 100%);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 4px solid #fff;
}
.hero-cv {
  display: block;
  width: 100%;
  height: auto;
}
.tag {
  margin: 0;
  max-width: 520px;
  color: var(--muted);
  font-weight: 600;
}
.home-btns {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ---------- chọn màn ---------- */
.levels {
  overflow: auto;
}
.tabs {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 0 14px 12px;
}
.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 0;
  padding: 9px 14px;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 3px 0 rgba(90, 60, 30, 0.12);
  font-weight: 800;
}
.tab small {
  font-size: 11px;
  color: var(--muted);
  margin-left: 4px;
}
.tab.on {
  background: var(--accent);
  color: #fff;
}
.tab.locked {
  opacity: 0.6;
}
.lv-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  width: min(900px, 100%);
  margin: 0 auto;
  padding: 0 14px 24px;
}
.lv {
  position: relative;
  padding: 0;
  border: 3px solid #fff;
  border-radius: 18px;
  overflow: hidden;
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: left;
  transition: transform 0.12s;
}
.lv:hover:not(.locked) {
  transform: translateY(-3px);
}
.lv canvas {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 1;
}
.lv .li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px 2px;
}
.lv .ln {
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  width: 26px;
  height: 26px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #a87a4f;
  color: #fff;
  font-size: 14px;
}
.lv.done .ln {
  background: var(--accent);
}
.lv .li b {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lv .ls i {
  font-style: normal;
  color: rgba(90, 60, 30, 0.2);
}
.lv .ls i.on {
  color: var(--gold);
}
.lv .lvv {
  padding: 0 10px 9px 42px;
  font-size: 15px;
}
.lv.locked canvas {
  filter: grayscale(1) brightness(0.7);
}
.lv .lock {
  position: absolute;
  inset: 0 0 auto 0;
  aspect-ratio: 2 / 1;
  display: grid;
  place-items: center;
  font-size: 30px;
}

/* ---------- dựng cầu ---------- */
.edit {
  padding: 0;
}
#cv {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
.ebar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  pointer-events: none;
}
.ebar > * {
  pointer-events: auto;
}
.etitle {
  display: grid;
  background: rgba(255, 250, 240, 0.92);
  padding: 5px 12px;
  border-radius: 13px;
  box-shadow: 0 3px 0 rgba(90, 60, 30, 0.12);
  min-width: 0;
}
.etitle b {
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.etitle small {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cost {
  display: grid;
  justify-items: end;
  background: rgba(255, 250, 240, 0.92);
  padding: 5px 12px;
  border-radius: 13px;
  box-shadow: 0 3px 0 rgba(90, 60, 30, 0.12);
}
.cost b {
  font-size: 15px;
  font-family: "Baloo 2", sans-serif;
}
.cost.over b {
  color: var(--red);
}
.cost small {
  display: flex;
  gap: 8px;
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
}
.cost small .ok {
  color: var(--accent);
}
.tbar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px max(8px, env(safe-area-inset-bottom));
  background: rgba(255, 250, 240, 0.94);
  box-shadow: 0 -4px 18px rgba(90, 60, 30, 0.12);
}
.tools {
  flex: 1;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  min-width: 0;
  scrollbar-width: none;
}
.tool {
  flex: none;
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  column-gap: 6px;
  padding: 6px 10px 6px 8px;
  border: 2px solid transparent;
  border-radius: 13px;
  background: var(--panel2);
  text-align: left;
}
.tool .ti {
  grid-row: span 2;
  font-size: 22px;
}
.tool b {
  font-size: 13px;
  line-height: 1.1;
}
.tool small {
  font-size: 10.5px;
  color: var(--muted);
  font-weight: 700;
}
.tool.on {
  border-color: var(--c);
  background: #fff;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 35%, transparent);
}
.acts {
  display: flex;
  gap: 6px;
  align-items: center;
}
.btn.go {
  padding: 11px 16px;
  white-space: nowrap;
}
.rstat {
  font-weight: 800;
  color: var(--muted);
  font-size: 14px;
}
.free {
  position: absolute;
  left: 50%;
  translate: -50% 0;
  bottom: 74px;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  justify-content: center;
  max-width: calc(100% - 20px);
  padding: 8px 12px;
  border-radius: 14px;
  background: rgba(255, 250, 240, 0.94);
  box-shadow: 0 3px 0 rgba(90, 60, 30, 0.12);
  font-size: 13px;
  font-weight: 700;
}
.free label {
  display: flex;
  align-items: center;
  gap: 6px;
}
.free input {
  width: 110px;
  accent-color: var(--accent);
}
.fveh {
  display: flex;
  align-items: center;
  gap: 4px;
}
.vb {
  border: 0;
  background: var(--panel2);
  border-radius: 9px;
  padding: 3px 6px;
  font-size: 16px;
}
.vq {
  min-width: 40px;
  padding: 0 4px;
  font-size: 15px;
}
.tip {
  position: absolute;
  left: 50%;
  top: 70px;
  translate: -50% 0;
  z-index: 3;
  width: max-content;
  max-width: calc(100% - 24px);
  background: #fff8e1;
  border: 2px solid #f0d58a;
  padding: 9px 14px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 14px;
  box-shadow: var(--shadow);
  pointer-events: none;
}

/* ---------- lớp phủ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(58, 42, 26, 0.32);
  backdrop-filter: blur(3px);
}
.sheet {
  position: relative;
  width: min(440px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--panel);
  border-radius: 24px;
  padding: 22px 20px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  animation: pop 0.22s ease-out;
}
.sheet.wide {
  width: min(580px, 100%);
}
@keyframes pop {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
}
.sheet h2 {
  margin: 0;
  text-align: center;
  font-size: 26px;
}
.sheet h3 {
  margin: 4px 0 0;
}
.sheet ul {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 7px;
  font-size: 14px;
  line-height: 1.5;
}
.sub {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-weight: 600;
}
.close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: var(--panel2);
  font-size: 22px;
  line-height: 1;
}
.btns {
  display: grid;
  gap: 8px;
}
.res {
  text-align: center;
}
.res-ico {
  font-size: 58px;
  line-height: 1;
  animation: pop 0.45s ease-out;
}
.res-stars span {
  display: inline-block;
  font-size: 44px;
  color: rgba(90, 60, 30, 0.15);
}
.res-stars span.on {
  color: var(--gold);
  animation: starIn 0.4s backwards;
}
@keyframes starIn {
  from {
    transform: scale(2.2) rotate(-30deg);
    opacity: 0;
  }
}
.mat-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.mat-list div {
  display: grid;
  grid-template-columns: 30px 1fr;
  column-gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 13px;
  background: var(--panel2);
  border-left: 5px solid var(--c);
}
.mat-list span {
  grid-row: span 2;
  font-size: 22px;
}
.mat-list b {
  font-size: 14px;
}
.mat-list small {
  font-size: 12px;
  color: var(--muted);
}
.toast {
  position: absolute;
  left: 50%;
  bottom: 90px;
  translate: -50% 0;
  z-index: 40;
  max-width: calc(100% - 32px);
  background: #3a2a1a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 14px;
  text-align: center;
  pointer-events: none;
}

/* ---------- điện thoại ---------- */
@media (max-width: 720px) {
  .lv-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .tool {
    grid-template-columns: auto;
    justify-items: center;
    padding: 5px 7px;
  }
  .tool .ti {
    grid-row: auto;
    font-size: 20px;
  }
  .tool small {
    display: none;
  }
  .tool b {
    font-size: 11px;
  }
  .cost small {
    flex-direction: column;
    gap: 0;
    align-items: flex-end;
  }
  .etitle small {
    display: none;
  }
  .mat-list {
    grid-template-columns: 1fr;
  }
  .free {
    bottom: 80px;
  }
  .tbar {
    flex-wrap: wrap;
  }
  .tools {
    flex-basis: 100%;
    order: 2;
  }
  .acts {
    margin-left: auto;
  }
}
@media (max-height: 480px) {
  .home-body {
    gap: 8px;
  }
  .hero-pic,
  .tag {
    display: none;
  }
  .tool small {
    display: none;
  }
}
@media (max-height: 480px) {
  .sheet {
    gap: 8px;
    padding: 14px 16px;
  }
  .res-ico {
    font-size: 34px;
  }
  .res-stars span {
    font-size: 30px;
  }
  .sheet h2 {
    font-size: 22px;
  }
  .btns {
    grid-template-columns: 1fr 1fr;
  }
}
