/* มดบุกโต๊ะ! */
.ar .ar-big { font-size: 20px; min-height: 56px; }
.ar-center { text-align: center; margin: 0; }

/* start */
.ar-demo { font-size: clamp(20px, 6vw, 28px); text-align: center; letter-spacing: 1px; line-height: 1.4; }
.ar-best { text-align: center; font-weight: 600; }

/* play */
#scrPlay { display: grid; gap: 8px; max-width: 460px; margin: 0 auto; }
#scrPlay[hidden] { display: none; }
.ar-hud {
  display: grid; grid-template-columns: 1fr 1fr 1fr auto auto; align-items: center; gap: 6px;
  padding: 6px 8px !important; text-align: center;
}
.ar-stat small { display: block; font-size: 12px; color: var(--sk-muted); }
.ar-stat b { font-family: "Fredoka", "Mitr", sans-serif; font-size: 21px; line-height: 1.15; white-space: nowrap; }
.ar-stat.low b { color: var(--sg-red); animation: arPulse 0.5s infinite alternate; display: inline-block; }
.ar-ibtn {
  min-width: 42px; height: 40px; padding: 0 8px; border: 2.5px solid var(--sg-ink); border-radius: 12px; background: #fff;
  color: var(--sg-ink); font: 600 14px "Fredoka", "Mitr", sans-serif; cursor: pointer; box-shadow: 0 2px 0 var(--sg-ink);
  touch-action: manipulation;
}
.ar-ibtn.on { background: var(--sg-yellow); }

.ar-boardwrap {
  position: relative; margin: 0 auto; aspect-ratio: 7 / 11;
  width: min(100%, 440px, max(240px, calc((100svh - 395px) * 7 / 11)));
}
.ar-board {
  display: block; width: 100%; height: 100%; border: 3px solid var(--sg-ink); border-radius: 18px;
  background: #7fc77a; box-shadow: 0 4px 0 var(--sg-ink); touch-action: manipulation; cursor: pointer;
  -webkit-tap-highlight-color: transparent; box-sizing: border-box;
}

.ar-panel { padding: 8px !important; min-height: 76px; display: grid; align-items: center; }
.ar-hint { font-size: 14px; color: var(--sk-muted); text-align: center; line-height: 1.45; }
.ar-build { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.ar-star { font-size: 12.5px; font-weight: 600; color: #a16207; text-align: center; margin-bottom: 4px; }
.ar-tw {
  display: grid; justify-items: center; gap: 1px; padding: 6px 2px; border: 2.5px solid var(--sg-ink); border-radius: 14px;
  background: #fff; color: var(--sg-ink); font: inherit; cursor: pointer; box-shadow: 0 3px 0 var(--sg-ink);
  touch-action: manipulation; line-height: 1.2;
}
.ar-tw:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--sg-ink); }
.ar-tw:disabled { opacity: 0.45; cursor: not-allowed; }
.ar-tw b { font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.ar-tw small { display: none; }
.ar-tw i { font-style: normal; font: 600 14px "Fredoka", "Mitr", sans-serif; color: #b45309; }
.ar-twe { font-size: 24px; line-height: 1.1; }
.ar-twe.big { font-size: 34px; }
.ar-info { display: grid; grid-template-columns: auto 1fr 1fr; align-items: center; gap: 6px 8px; }
.ar-info .ar-twe { grid-row: span 2; }
.ar-infotext { grid-column: span 2; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 10px; min-width: 0; }
.ar-infotext b { font-size: 15px; }
.ar-infotext small { font-size: 12px; color: var(--sk-muted); }
.ar-lv { font-family: "Fredoka", sans-serif; color: #b45309; }
.ar-info .sg-btn { padding-left: 10px; padding-right: 10px; white-space: nowrap; }
.ar-up:not(:disabled) { background: var(--sg-yellow); }
.ar-wave { min-height: 50px; font-size: 17px; }
.ar-wave:disabled { opacity: 0.7; }

/* overlays */
.ar-toasts {
  position: absolute; left: 8px; right: 8px; top: 8px; z-index: 5; display: grid; justify-items: center; gap: 5px;
  pointer-events: none;
}
.ar-toast {
  max-width: 100%; padding: 5px 12px; border: 2.5px solid var(--sg-ink); border-radius: 999px; background: #fff;
  box-shadow: 0 3px 0 var(--sg-ink); font-weight: 600; font-size: 13.5px; text-align: center; line-height: 1.35;
  animation: arToast 2.8s ease forwards;
}
.ar-toast.good { background: var(--sk-green); color: #fff; }
.ar-toast.news { background: var(--sg-yellow); }
.ar-layer {
  position: absolute; inset: 0; z-index: 8; display: grid; place-content: center; justify-items: center; gap: 12px;
  border-radius: 18px; background: rgba(255, 250, 240, 0.88); text-align: center;
}
.ar-layer[hidden] { display: none; }
.ar-layer > b { font-size: 26px; }

/* game over */
.ar-over { text-align: center; }
.ar-overtitle { font-family: "Kanit", "Mitr", sans-serif; font-size: 28px; font-weight: 800; }
.ar-stars { font-size: 40px; letter-spacing: 4px; line-height: 1.1; }
.ar-stars[hidden] { display: none; }
.ar-record {
  justify-self: center; padding: 4px 14px; border: 2.5px solid var(--sg-ink); border-radius: 999px;
  background: var(--sg-yellow); font-weight: 700; animation: arGoal 0.6s infinite alternate;
}
.ar-record[hidden] { display: none; }
.ar-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ar-stats > div { padding: 10px 4px; border: 2.5px solid var(--sg-ink); border-radius: 16px; background: var(--sk-cream); }
.ar-stats small { display: block; color: var(--sk-muted); font-size: 13px; }
.ar-stats b { font-family: "Fredoka", "Mitr", sans-serif; font-size: 30px; line-height: 1.1; }

@keyframes arPulse { to { transform: scale(1.15); } }
@keyframes arGoal { to { transform: scale(0.9); } }
@keyframes arToast { 0% { opacity: 0; transform: translateY(-8px); } 10%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }
@keyframes arPop { from { transform: scale(0.9); opacity: 0; } }
@keyframes arRise { from { transform: translateY(10px) scale(0.97); } }
@media (prefers-reduced-motion: reduce) {
  .ar-record, .ar-stat.low b { animation: none; }
}

/* wide screens: HUD, build panel and wave button in a side column */
@media (min-width: 860px) {
  #scrPlay {
    max-width: 900px; grid-template-columns: 300px auto; grid-template-rows: auto auto auto auto 1fr;
    justify-content: center; align-items: start; column-gap: 18px;
  }
  .ar-hud { grid-column: 1; grid-row: 1; grid-template-columns: 1fr 1fr 1fr; row-gap: 8px; }
  .ar-hud .ar-ibtn { grid-row: 2; }
  .ar-hud #speedBtn { grid-column: 1 / 3; }
  .ar-boardwrap { grid-column: 2; grid-row: 1 / 5; width: min(520px, max(320px, calc((100svh - 120px) * 7 / 11))); }
  .ar-panel { grid-column: 1; grid-row: 2; min-height: 120px; }
  .ar-build { grid-template-columns: 1fr 1fr; }
  .ar-tw small { display: block; font-size: 11px; color: var(--sk-muted); }
  .ar-info { grid-template-columns: 1fr 1fr; }
  .ar-info .ar-twe { grid-row: auto; grid-column: span 2; justify-self: center; }
  .ar-wave { grid-column: 1; grid-row: 3; }
}

/* share sheet */
.ar-sheet {
  position: fixed; inset: 0; z-index: 200; display: flex; padding: 16px; overflow-y: auto;
  background: rgba(29, 27, 46, 0.6);
}
.ar-sheet[hidden] { display: none; }
.ar-sheetcard {
  position: relative; margin: auto; width: min(100%, 400px); display: grid; gap: 10px; text-align: center;
  animation: arPop 0.25s ease-out;
}
.ar-sheetcard > b { font-size: 20px; }
.ar-sheetx {
  position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; border: 2px solid var(--sg-ink);
  border-radius: 50%; background: #fff; color: var(--sg-ink); cursor: pointer; font-size: 15px;
}
.ar-sheetimg {
  position: relative; aspect-ratio: 1080 / 1350; width: min(100%, calc((100svh - 300px) * 0.8)); justify-self: center;
  border-radius: 14px; overflow: hidden; background: var(--sk-soft);
}
.ar-sheetimg img { display: block; width: 100%; height: 100%; object-fit: contain; }
.ar-spin { position: absolute; inset: 0; display: none; place-items: center; color: var(--sk-muted); }
.ar-sheet.loading .ar-spin { display: grid; }
.ar-sheet.loading img { visibility: hidden; }
.ar-sheetcard a.sg-btn { text-decoration: none; }
.ar-sheet.loading a.sg-btn { pointer-events: none; opacity: 0.5; }

/* synergy + relic chips */
.ar-chips { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; min-height: 28px; }
.ar-chip {
  display: inline-flex; align-items: center; gap: 2px; height: 28px; padding: 0 7px; border: 2px solid var(--sg-ink);
  border-radius: 999px; background: #fff; color: var(--sg-ink); font: 600 13px "Fredoka", "Mitr", sans-serif;
  cursor: pointer; opacity: 0.55; touch-action: manipulation;
}
.ar-chip b { font-weight: 700; }
.ar-chip.lv1 { opacity: 1; background: #d9f99d; }
.ar-chip.lv2 { opacity: 1; background: var(--sg-yellow); box-shadow: 0 2px 0 var(--sg-ink); }
.ar-chip.relic { opacity: 1; padding: 0 5px; font-size: 15px; }
.ar-chipsep { width: 2px; background: rgba(35, 31, 32, 0.2); margin: 3px 2px; }

/* tower panel: two branch buttons + sell */
.ar-ups { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; margin-top: 6px; }
.ar-ups:has(> .ar-br:only-of-type), .ar-ups:has(> .max) { grid-template-columns: 1fr auto; }
.ar-br {
  display: grid; gap: 1px; padding: 5px 6px; border: 2.5px solid var(--sg-ink); border-radius: 12px; background: var(--sg-yellow);
  color: var(--sg-ink); font: inherit; text-align: left; cursor: pointer; box-shadow: 0 2px 0 var(--sg-ink); line-height: 1.2;
  touch-action: manipulation; min-width: 0;
}
.ar-br + .ar-br { background: #ffd3da; }
.ar-br b { font-size: 13px; }
.ar-br small { font-size: 11px; color: #6b6461; }
.ar-br i { font-style: normal; font: 600 13px "Fredoka", "Mitr", sans-serif; color: #b45309; }
.ar-br:disabled { opacity: 0.45; cursor: not-allowed; }
.ar-br.max { display: grid; place-items: center; background: #f3f4f6; box-shadow: none; font-weight: 600; }
.ar-sell { line-height: 1.2; padding: 4px 10px !important; }
.ar-info { grid-template-columns: auto 1fr !important; }
.ar-info .ar-twe { grid-row: auto !important; }
.ar-infotext { grid-column: auto !important; }
.ar-infotext small { line-height: 1.35; }

/* reward / starter pick */
.ar-pick {
  position: fixed; inset: 0; z-index: 150; border-radius: 0; background: rgba(29, 27, 46, 0.55); padding: 16px;
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 10px; overflow-y: auto;
}
.ar-pick[hidden] { display: none; }
.ar-pick > * { width: min(100%, 420px); }
.ar-picktitle { color: #fff; text-shadow: 0 2px 0 var(--sg-ink); }
.ar-picktitle { font-size: 19px; text-align: center; }
.ar-pickcard {
  display: grid; grid-template-columns: 52px 1fr; align-items: center; gap: 8px; padding: 9px 10px; border: 3px solid var(--sg-ink);
  border-radius: 16px; background: #fff; color: var(--sg-ink); font: inherit; text-align: left; cursor: pointer;
  box-shadow: 0 4px 0 var(--sg-ink); animation: arRise 0.25s ease-out; touch-action: manipulation;
}
.ar-pickcard:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--sg-ink); }
.ar-pickcard.k-relic { background: #fff3d6; }
.ar-pickcard.k-tower { background: #e0f2fe; }
.ar-pickcard.k-kit { background: #ecfccb; }
.ar-pickicon { font-size: 30px; text-align: center; line-height: 1.1; letter-spacing: -2px; }
.ar-picktext { display: grid; gap: 2px; min-width: 0; }
.ar-picktext b { font-size: 15px; line-height: 1.25; }
.ar-picktext small { font-size: 12.5px; color: #6b6461; line-height: 1.35; }

.ar-seedbox { text-align: center; font-weight: 600; padding: 6px 10px; border-radius: 12px; background: #e0f2fe; }
.ar-seedbox[hidden] { display: none; }
.ar-seedline { font-size: 13px; color: var(--sk-muted); margin: 0; }
.ar-seedline b { font-family: "Fredoka", sans-serif; letter-spacing: 2px; color: var(--sg-ink); }
.ar-build-sum { font-size: 15px; margin: 0; }
#replayBtn { margin-top: 8px; }

@media (min-width: 860px) {
  .ar-chips { grid-column: 1; grid-row: 2; justify-content: flex-start; }
  .ar-panel { grid-row: 3 !important; }
  .ar-wave { grid-row: 4 !important; }
  .ar-boardwrap { grid-row: 1 / 6 !important; }
  .ar-ups { grid-template-columns: 1fr 1fr; }
  .ar-ups .ar-sell { grid-column: 1 / -1; }
}
