/* ============ base ============ */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at 50% 0%, #1c1a17 0%, #0c0b09 70%);
  color: #e7e5e4;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

/* container utilities (equivalent to the Tailwind classes in index.html) */
.container {
  width: 100%;
  margin: 0 auto;
}
.flex { display: flex; }
.flex-col { flex-direction: column; }
.h-screen { height: 100vh; height: 100dvh; }
.rounded-lg { border-radius: 0.5rem; }
.overflow-hidden { overflow: hidden; }
.shadow-2xl { box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6); }
.bg-gradient-to-br {
  background-image: linear-gradient(to bottom right, #451a03 0%, #1c1917 50%, #451a03 100%);
}

/* ============ header ============ */
header.flex { flex: none; }
.p-3 { padding: 0.75rem; }
.justify-between { justify-content: space-between; }
.items-center { align-items: center; }
.gap-2 { gap: 0.5rem; }
.bg-black\/30 { background-color: rgba(0, 0, 0, 0.3); }
.backdrop-blur-sm { backdrop-filter: blur(4px); }
.border-b { border-bottom: 1px solid; }
.border-amber-700\/30 { border-color: rgba(180, 83, 9, 0.3); }

.h-8 { height: 2rem; }
.w-8 { width: 2rem; }
.rounded-lg { border-radius: 0.5rem; }
.bg-amber-500\/20 { background-color: rgba(245, 158, 11, 0.2); }
.border { border: 1px solid; }
.border-amber-500\/30 { border-color: rgba(245, 158, 11, 0.3); }
.text-xl { font-size: 1.25rem; }

header h1 {
  margin: 0;
  font-size: 1.125rem;
  color: #fef3c7;
  font-weight: 700;
  letter-spacing: 0.3px;
}
header p {
  margin: 0;
  font-size: 0.75rem;
  color: rgba(253, 230, 138, 0.7);
}
@media (min-width: 640px) {
  .sm\:h-10 { height: 2.5rem; }
  .sm\:w-10 { width: 2.5rem; }
  .sm\:text-2xl { font-size: 1.5rem; }
  .sm\:text-sm { font-size: 0.875rem; }
  .sm\:p-4 { padding: 1rem; }
  .sm\:gap-3 { gap: 0.75rem; }
  header h1 { font-size: 1.5rem; }
  header p { display: block; }
}
.gap-3 { gap: 0.75rem; }
header .hidden { display: none; }
@media (min-width: 640px) {
  header p.hidden { display: block; }
}

.legend { display: flex; align-items: center; gap: 0.7rem; }
.lg { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: rgba(231, 229, 228, 0.6); }
.lg i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.lg.inf i { background: #5b8cff; box-shadow: 0 0 6px #5b8cff; }
.lg.arch i { background: #ff6b6b; box-shadow: 0 0 6px #ff6b6b; }
.lg.cav i { background: #36c98f; box-shadow: 0 0 6px #36c98f; }
.lg.adv i { background: #e0b94f; box-shadow: 0 0 6px #e0b94f; }

/* tree toggle (top right) */
.tree-toggle {
  display: inline-flex;
  border: 1px solid rgba(120, 53, 15, 0.5);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(28, 25, 23, 0.6);
}
.tree-toggle button {
  border: none;
  background: transparent;
  color: rgba(231, 229, 228, 0.6);
  font-size: 11px;
  font-weight: 700;
  padding: 6px 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.tree-toggle button + button { border-left: 1px solid rgba(120, 53, 15, 0.35); }
.tree-toggle button:hover { color: #fde68a; }
.tree-toggle button.active {
  background: linear-gradient(to bottom right, #f59e0b, #ea580c);
  color: #1c1917;
}

.controls { display: flex; align-items: center; gap: 4px; }
.controls button {
  width: 30px; height: 30px;
  border: 1px solid rgba(120, 53, 15, 0.6);
  background: rgba(28, 25, 23, 0.7);
  color: #fde68a;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.15s;
}
.controls button:hover { background: rgba(69, 26, 3, 0.8); }

/* ============ tree area ============ */
.flex-1 { flex: 1; }
.relative { position: relative; }
.tree-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
#tree {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
}
#edges { position: absolute; top: 0; left: 0; pointer-events: none; }
#nodes, #labels { position: absolute; top: 0; left: 0; }

#hint {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: rgba(231, 229, 228, 0.35);
  pointer-events: none;
  z-index: 5;
}

/* ============ node cards ============ */
.node {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 2;
  cursor: pointer;
  user-select: none;
}
.node .card {
  position: relative;
  border-radius: 0.75rem;
  border: 2px solid #44403c;
  background: linear-gradient(to bottom right, #292524, #1c1917);
  opacity: 0.9;
  min-width: 112px;
  padding: 8px 10px 9px;
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}
.node:hover .card {
  transform: scale(1.05);
  border-color: #a8a29e;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.6);
  opacity: 1;
}
.node .card .icon-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 52px;
  margin-bottom: 5px;
}
.node .card img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}
.node .card .name {
  margin: 0;
  text-align: center;
  font-size: 10.5px;
  font-weight: 700;
  color: #fff;
  line-height: 1.15;
  min-height: 2.3em;
  display: flex;
  align-items: center;
  justify-content: center;
}
.node .card .badge {
  position: absolute;
  top: -8px;
  right: -8px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(68, 64, 60, 0.8);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 700;
  color: #e7e5e4;
  white-space: nowrap;
}
.node .card .tier-tag {
  position: absolute;
  top: -8px;
  left: -8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  color: #fff;
  border: 2px solid #1c1917;
}
.node .card .progress {
  margin-top: 6px;
  width: 100%;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 999px;
  overflow: hidden;
  height: 4px;
}
.node .card .progress .bar {
  height: 100%;
  transition: width 0.5s;
  background: #57534e;
}

/* branch colors */
.node.inf .card { border-color: rgba(91, 140, 255, 0.55); }
.node.inf .tier-tag { background: #5b8cff; }
.node.cav .card { border-color: rgba(54, 201, 143, 0.55); }
.node.cav .tier-tag { background: #36c98f; }
.node.arch .card { border-color: rgba(255, 107, 107, 0.55); }
.node.arch .tier-tag { background: #ff6b6b; }
.node.adv .card { border-color: rgba(224, 185, 79, 0.55); }
.node.adv .tier-tag { background: #e0b94f; }
.node.merge .card { border-color: rgba(201, 162, 39, 0.8); box-shadow: 0 0 14px rgba(201, 162, 39, 0.25); }
.node.merge .tier-tag { background: #c9a227; }

/* start node (War Academy) */
.node.start .card {
  background: linear-gradient(to bottom right, #f59e0b, #ea580c);
  border-color: #fbbf24;
  box-shadow: 0 0 26px rgba(245, 158, 11, 0.45);
  min-width: 168px;
  padding: 14px 20px;
  opacity: 1;
}
.node.start .card img { width: 68px; height: 68px; }
.node.start .card .name { font-size: 15px; color: #1c1917; }
.node.start .card .badge { background: rgba(28, 25, 23, 0.75); color: #fbbf24; border-color: rgba(251, 191, 36, 0.5); }
.node.start .card .progress { background: rgba(28, 25, 23, 0.4); }
.node.start .card .progress .bar { background: #1c1917; }
.node.start:hover .card { border-color: #fff7ed; }

/* ============ base War Academy tree cards ============ */
.tree-academy .node .card {
  border-color: #44403c;
  opacity: 0.88;
  min-width: 138px;
  padding: 10px 12px 10px;
  background: linear-gradient(to bottom right, #292524, #1c1917);
}
.tree-academy .node .card .icon-wrap { height: 64px; margin-bottom: 6px; }
.tree-academy .node .card img { width: 56px; height: 56px; }
.tree-academy .node .card .name { font-size: 11.5px; }
.tree-academy .node .card .badge {
  background: rgba(0, 0, 0, 0.65);
  border-color: rgba(120, 53, 15, 0.6);
  color: #fde68a;
  font-size: 9.5px;
}
.tree-academy .node .tier-tag { display: none; }
.tree-academy .node:hover .card {
  border-color: #d6b36a;
  box-shadow: 0 6px 26px rgba(0, 0, 0, 0.65), 0 0 12px rgba(224, 185, 79, 0.25);
  opacity: 1;
}
.tree-academy .node.start .card { min-width: 178px; padding: 16px 22px; }
.tree-academy .node.start .card img { width: 72px; height: 72px; }
.tree-academy .node.start .card .name { font-size: 16px; }

/* ============ labels ============ */
#labels .arm-label {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: rgba(253, 230, 138, 0.3);
  pointer-events: none;
  white-space: nowrap;
}

/* ============ detail panel ============ */
#detail {
  position: fixed;
  right: 16px;
  top: 16px;
  bottom: 16px;
  width: 400px;
  max-width: 94vw;
  background: linear-gradient(to bottom right, #1c1917, #0c0b09);
  border: 1px solid rgba(180, 83, 9, 0.45);
  border-radius: 12px;
  z-index: 60;
  overflow-y: auto;
  padding: 22px;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.75);
}
#detail.hidden { display: none; }
#closeDetail {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  color: rgba(231, 229, 228, 0.6);
  font-size: 26px;
  cursor: pointer;
  line-height: 1;
}
#closeDetail:hover { color: #fff; }

#detailBody h2 {
  margin: 0 0 2px;
  font-size: 20px;
  color: #fef3c7;
  padding-right: 28px;
}
#detailBody .tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 3px 9px;
  border-radius: 999px;
  margin: 8px 6px 12px 0;
  color: #fff;
}
#detailBody .tag.inf { background: #5b8cff; }
#detailBody .tag.cav { background: #36c98f; }
#detailBody .tag.arch { background: #ff6b6b; }
#detailBody .tag.adv { background: #e0b94f; }
#detailBody .tag.start { background: linear-gradient(to bottom right, #f59e0b, #ea580c); color: #1c1917; }
#detailBody .tag.merge { background: #c9a227; color: #1c1917; }

#detailBody .desc {
  color: rgba(231, 229, 228, 0.75);
  font-size: 13px;
  line-height: 1.55;
  margin: 0 0 14px;
}
#detailBody .prereq {
  background: rgba(69, 26, 3, 0.4);
  border: 1px solid rgba(180, 83, 9, 0.35);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 12px;
  color: rgba(231, 229, 228, 0.7);
  margin-bottom: 14px;
}
#detailBody .prereq b { color: #fde68a; }

.levels { display: flex; flex-direction: column; gap: 10px; }
.level {
  background: rgba(41, 37, 36, 0.7);
  border: 1px solid rgba(120, 53, 15, 0.4);
  border-radius: 10px;
  padding: 12px;
}
.level h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: #fbbf24;
}
.level .row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin: 3px 0;
  color: rgba(231, 229, 228, 0.6);
}
.level .row b { color: #e7e5e4; font-weight: 600; }
.level .row .muted { color: rgba(253, 230, 138, 0.75); font-weight: 500; font-size: 11px; }
.cost-list { margin-top: 6px; }
.cost-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  margin: 3px 0;
  color: #e7e5e4;
}
.cost-item .dot {
  width: 15px;
  height: 15px;
  border-radius: 4px;
  background: rgba(69, 26, 3, 0.7);
  border: 1px solid rgba(251, 191, 36, 0.5);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  color: #fbbf24;
}
.cost-item .qty { margin-left: auto; font-weight: 600; color: #fde68a; }

/* ============ mobile ============ */
@media (hover: none) {
  .node:hover .card { transform: none; border-color: #44403c; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4); opacity: 0.9; }
  .controls button:hover { background: rgba(28, 25, 23, 0.7); }
  .tree-toggle button:hover { color: rgba(231, 229, 228, 0.6); }
}

@media (max-width: 640px) {
  html, body { height: 100%; overscroll-behavior: none; }
  header { flex-wrap: wrap; row-gap: 0.4rem; padding: 0.5rem 0.75rem; }
  header h1 { font-size: 1rem; }
  .legend { display: none; }
  .tree-toggle button { padding: 8px 13px; font-size: 12px; }
  .controls button { width: 38px; height: 38px; font-size: 17px; border-radius: 9px; }
  #hint {
    bottom: 6px;
    font-size: 10px;
    white-space: nowrap;
  }
  #detail {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    max-height: 82dvh;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    padding: 20px 18px;
    -webkit-overflow-scrolling: touch;
  }
  #detailBody h2 { font-size: 18px; }
}
