:root{
  --bg:#0b1220;
  --panel:rgba(255,255,255,.08);
  --panel2:rgba(255,255,255,.12);
  --text:rgba(255,255,255,.92);
  --muted:rgba(255,255,255,.72);
  --shadow:0 12px 30px rgba(0,0,0,.35);
  --radius:18px;

  --accent: rgba(120, 200, 255, 0.85);
  --accentDim: rgba(120, 200, 255, 0.25);

  --goldA: rgba(255, 208, 80, 0.28);
  --goldB: rgba(255, 208, 80, 0.12);
  --silverA: rgba(210, 220, 235, 0.26);
  --silverB: rgba(210, 220, 235, 0.12);
  --bronzeA: rgba(214, 150, 100, 0.26);
  --bronzeB: rgba(214, 150, 100, 0.12);

  --topbarH: 140px; /* JS가 실측해서 덮어씀 */
}

*{box-sizing:border-box;}
html,body{height:100%;}
body{
  margin:0;
  font-family:system-ui,-apple-system,"Segoe UI",Roboto,"Noto Sans KR",Arial,sans-serif;
  background:radial-gradient(1200px 800px at 20% 20%,#1b3a6b 0%,var(--bg) 55%);
  color:var(--text);
  overflow:hidden;
}

.app{
  max-width:1100px;
  margin:0 auto;
  padding:18px;
  height:100vh;
  overflow:hidden;
}

/* ===== Topbar ===== */
.topbar{
  display:flex;gap:16px;align-items:center;justify-content:space-between;
  padding:14px 16px;border-radius:var(--radius);
  background:var(--panel);box-shadow:var(--shadow);
}
.title h1{margin:0;font-size:20px;}
.subtitle{margin:4px 0 0;color:var(--muted);font-size:13px;}

.topbarRight{display:flex;align-items:center;gap:12px;flex-wrap:wrap;justify-content:flex-end;}
.scoreboard{display:flex;gap:10px;}
.pill{
  background:var(--panel2);border-radius:999px;padding:10px 12px;
  display:flex;gap:8px;align-items:baseline;
}
.pill__label{color:var(--muted);font-size:12px;}
.pill__value{font-weight:900;font-size:18px;}

.mySchoolBar{display:flex;gap:8px;align-items:center;}
.miniPill{
  background:rgba(255,255,255,.08);
  border:1px solid rgba(255,255,255,.12);
  border-radius:999px;padding:8px 10px;
  display:inline-flex;gap:8px;align-items:baseline;max-width:260px;
}
.miniPill__label{color:rgba(255,255,255,.70);font-size:12px;}
.miniPill__value{
  font-weight:900;font-size:13px;color:rgba(255,255,255,.95);
  max-width:180px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
}

/* ===== Account (PC dropdown) ===== */
.accountWrap{position:relative;}
.accountBtn{
  border:1px solid rgba(255,255,255,.16);
  background:rgba(255,255,255,.08);
  color:var(--text);
  border-radius:999px;
  padding:10px 12px;
  cursor:pointer;
  display:inline-flex;
  align-items:center;
  gap:8px;
  font-weight:900;
}
.accountBtn:hover{background:rgba(255,255,255,.12);}
.accountName{font-size:13px;color:rgba(255,255,255,.88);max-width:120px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}

.accountMenu{
  position:absolute;right:0;top:calc(100% + 10px);width:260px;
  background:rgba(20,28,45,.95);
  border:1px solid rgba(255,255,255,.12);
  box-shadow:0 20px 60px rgba(0,0,0,.55);
  border-radius:16px;padding:12px;z-index:999;
}
.accountMenu__header{
  padding:8px 8px 10px;border-radius:14px;background:rgba(255,255,255,.06);
  margin-bottom:10px;display:flex;align-items:flex-start;justify-content:space-between;gap:10px;
}
.accountMenu__title{font-weight:900;font-size:14px;}
.accountMenu__sub{margin-top:4px;font-size:12px;color:rgba(255,255,255,.75);word-break:break-all;}
.accountMenu__actions{display:grid;gap:8px;}
.menuBtn{border:none;background:rgba(255,255,255,.12);color:var(--text);padding:10px 12px;border-radius:14px;cursor:pointer;font-weight:900;}
.menuBtn:hover{background:rgba(255,255,255,.16);}
.menuBtn--ghost{background:transparent;border:1px solid rgba(255,255,255,.18);}
.menuBtn--ghost:hover{background:rgba(255,255,255,.06);}
.accountMenu__hint{margin:10px 4px 2px;font-size:11px;color:rgba(255,255,255,.62);}

.xBtn{
  border:1px solid rgba(255,255,255,.18);
  background:rgba(255,255,255,.06);
  color:rgba(255,255,255,.92);
  width:34px;height:34px;border-radius:12px;
  cursor:pointer;font-weight:1000;
  display:grid;place-items:center;
}
.xBtn:hover{background:rgba(255,255,255,.10);}

/* ===== Layout (PC grid) ===== */
.main{
  margin-top:16px;
  display:grid;
  grid-template-columns: 1.15fr .85fr;
  grid-template-rows: 1fr 1fr;
  grid-template-areas:
    "gift items"
    "gift rank";
  gap:16px;
  height: calc(100vh - 18px - 18px - 72px);
  overflow:hidden;
}
#tabGift{grid-area:gift;}
#tabItems{grid-area:items;}
#tabRank{grid-area:rank;}

.card,.factory{
  background:var(--panel);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:16px;
  overflow:hidden;
  min-height:0;
}

/* ===== Factory ===== */
.factory{
  display:grid;
  gap:14px;
  justify-items:center;
  align-content:start;
}

.feverWrap{
  width:min(520px,100%);
  border-radius:16px;
  background:rgba(255,255,255,.06);
  border:1px solid rgba(255,255,255,.10);
  padding:12px;
}
.feverTop{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px;}
.feverLabel{font-weight:900;}
.feverText{color:rgba(255,255,255,.86);font-weight:900;}
.feverBar{
  width:100%;height:14px;border-radius:999px;
  background:rgba(0,0,0,.18);
  overflow:hidden;border:1px solid rgba(255,255,255,.10);
}
.feverFill{
  height:100%;
  width:100%;
  background:linear-gradient(90deg, var(--accentDim), var(--accent));
  transform-origin:right center;
  transform:scaleX(0);
}
.feverHint{margin-top:8px;font-size:12px;color:rgba(255,255,255,.70);}

.giftStageArea{width:min(520px,100%);display:flex;align-items:center;justify-content:center;}
.box{
  width:min(520px,100%);
  height:280px;
  border:none;
  border-radius:22px;
  background:rgba(255,255,255,.10);
  color:var(--text);
  cursor:pointer;
  box-shadow:0 18px 40px rgba(0,0,0,.35);
  display:grid;
  place-content:center;
  gap:8px;
  transition:transform .06s ease,background .15s ease;
}
.box:active{transform:scale(.985);}
.box:focus-visible{outline:3px solid rgba(255,255,255,.35);outline-offset:4px;}
.box__emoji{font-size:78px;line-height:1;}
.box__hint{color:rgba(255,255,255,.82);font-size:14px;font-weight:900;}
.box__subhint{color:rgba(255,255,255,.70);font-size:12px;max-width:420px;text-align:center;}

.meta{
  width:min(520px,100%);
  display:grid;
  gap:10px;
  padding:12px 14px;
  border-radius:16px;
  background:rgba(255,255,255,.07);
}
.meta__row{display:flex;justify-content:space-between;gap:10px;}
.meta__label{color:var(--muted);font-size:13px;}
.meta__value{font-weight:900;white-space:nowrap;}

/* ===== Items (PC) ===== */
.card h2{margin:0 0 6px;font-size:16px;}
.card__desc{margin:0 0 12px;color:var(--muted);font-size:13px;}
.inventory{display:grid;grid-template-columns:1fr 1fr;gap:10px;}

.invBtn{
  border:1px solid rgba(255,255,255,.16);
  background:rgba(255,255,255,.08);
  color:var(--text);
  border-radius:14px;
  padding:10px 10px 12px;
  cursor:pointer;
  text-align:left;
  display:grid;
  grid-template-columns:auto auto 1fr;
  gap:10px;
  align-items:center;
}
.invBtn:hover{background:rgba(255,255,255,.12);}
.invBtn:disabled{opacity:.55;cursor:not-allowed;background:rgba(0,0,0,.18);}
.invEmoji{font-size:18px;}
.invCount{font-weight:900;font-size:16px;}
.invDesc{font-size:12px;color:rgba(255,255,255,.78);justify-self:end;font-weight:900;}
.invTimer{
  grid-column:1 / -1;
  height:10px;border-radius:999px;
  background:rgba(0,0,0,.18);
  border:1px solid rgba(255,255,255,.10);
  overflow:hidden;margin-top:8px;
}
.invTimerFill{
  height:100%;
  width:100%;
  background:linear-gradient(90deg, var(--accentDim), var(--accent));
  transform-origin:right center;
  transform:scaleX(0);
}

/* ===== Inputs ===== */
.small{margin:10px 0 0;font-size:12px;color:var(--muted);}
.label{display:block;margin:10px 0 6px;color:var(--muted);font-size:13px;}
.input{
  width:100%;
  padding:11px 12px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.18);
  background:rgba(0,0,0,.18);
  color:rgba(255,255,255,.95);
}
.select{
  width:100%;
  padding:10px 12px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.22);
  background:rgba(10, 18, 34, 0.95);
  color:rgba(255,255,255,.96);
  font-weight:900;
  appearance:auto;
}
.select:focus-visible{outline:3px solid rgba(120,200,255,.35);outline-offset:2px;}
select option{background:#101a2f;color:rgba(255,255,255,.96);}

.hidden{display:none!important;}

/* ===== Ranking (PC) ===== */
.rankCard{padding-bottom:12px; min-height:0;}
.rankScroll{
  height: 100%;
  overflow:auto;
  padding-right:6px;
  padding-top:8px;
  padding-bottom:220px; /* ✅ 개인 기여도 영역이 가려지지 않게 */
}
.rank h3{margin:0 0 8px;font-size:14px;color:var(--muted);}
.rankList{margin:0;padding-left:0; list-style:none;}
.rankList li{margin:10px 0;}

.rankBtn{
  width:100%;
  text-align:left;
  border:1px solid rgba(255,255,255,.14);
  background:rgba(255,255,255,.07);
  color:var(--text);
  border-radius:14px;
  padding:12px 12px;
  cursor:pointer;
  font-weight:900;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}
.rankBtn:hover{background:rgba(255,255,255,.11);}
.rankLeft{display:flex;align-items:center;gap:10px;min-width:0;}
.rankBadge{
  width:34px;height:34px;border-radius:12px;
  display:grid;place-items:center;
  font-weight:1000;
  border:1px solid rgba(255,255,255,.18);
  background:rgba(0,0,0,.18);
  flex:0 0 auto;
}
.rankName{font-weight:1000;color:rgba(255,255,255,.95);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:260px;}
.rankScore{font-weight:1000;color:rgba(255,255,255,.92);flex:0 0 auto;}

.rankBtn.rank--gold{background:linear-gradient(90deg,var(--goldA),var(--goldB));border-color:rgba(255,208,80,.35);}
.rankBtn.rank--silver{background:linear-gradient(90deg,var(--silverA),var(--silverB));border-color:rgba(210,220,235,.35);}
.rankBtn.rank--bronze{background:linear-gradient(90deg,var(--bronzeA),var(--bronzeB));border-color:rgba(214,150,100,.35);}
.rankBadge.badge--gold{background:rgba(255,208,80,.25);border-color:rgba(255,208,80,.35);}
.rankBadge.badge--silver{background:rgba(210,220,235,.22);border-color:rgba(210,220,235,.35);}
.rankBadge.badge--bronze{background:rgba(214,150,100,.22);border-color:rgba(214,150,100,.35);}

.rankSearchResults{margin-top:10px;display:grid;gap:8px;}
.rankItem{
  border:1px solid rgba(255,255,255,.14);
  background:rgba(255,255,255,.07);
  color:var(--text);
  border-radius:12px;
  padding:10px 10px;
  cursor:pointer;
  text-align:left;
}
.rankItem:hover{background:rgba(255,255,255,.11);}
.rankItem__name{font-weight:900;color:rgba(255,255,255,.95);}
.rankItem__meta{margin-top:4px;font-size:12px;color:rgba(255,255,255,.75);}

.schoolDetail{
  margin-top:14px;
  padding:12px;
  border-radius:16px;
  background:rgba(255,255,255,.06);
  border:1px solid rgba(255,255,255,.10);
}
.detailHeader{display:flex;justify-content:space-between;align-items:center;gap:10px;margin-bottom:10px;}
.detailTitle{margin:0;font-size:14px;color:rgba(255,255,255,.92);}
.miniBtn{
  border:1px solid rgba(255,255,255,.18);
  background:transparent;color:var(--text);
  border-radius:12px;padding:8px 10px;cursor:pointer;font-weight:900;
}
.miniBtn:hover{background:rgba(255,255,255,.06);}
.contribList{margin:0;padding-left:18px;}
.contribList li{margin:7px 0;color:rgba(255,255,255,.92);font-weight:900;}
.contribEmpty{color:rgba(255,255,255,.70);font-size:13px;}

/* ===== Toast ===== */
.toast{
  position:fixed;top:14px;left:50%;transform:translateX(-50%);
  z-index:10000;
  background:rgba(20,28,45,.92);
  border:1px solid rgba(255,255,255,.14);
  box-shadow:0 18px 50px rgba(0,0,0,.55);
  color:rgba(255,255,255,.92);
  border-radius:999px;
  padding:10px 14px;
  font-weight:900;
  font-size:13px;
  max-width:min(760px,92vw);
  overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
  pointer-events:none;
}

/* ===== Overlay modal ===== */
.overlay{
  position:fixed;inset:0;background:rgba(0,0,0,.62);
  display:grid;place-items:center;padding:18px;z-index:9999;
}
.modal{
  width:min(520px,100%);
  border-radius:22px;
  background:rgba(20,28,45,.92);
  border:1px solid rgba(255,255,255,.12);
  box-shadow:0 20px 60px rgba(0,0,0,.55);
  padding:18px;
  backdrop-filter:blur(8px);
}
.modal--wide{width:min(860px,100%);}
.modal__title{margin:0;font-size:18px;}
.modal__desc{margin:6px 0 12px;color:var(--muted);font-size:13px;}
.modal__tabs{display:flex;gap:10px;margin-bottom:12px;}
.tab{
  flex:1;border:1px solid rgba(255,255,255,.18);
  background:rgba(255,255,255,.06);
  color:var(--text);
  border-radius:14px;padding:10px 12px;
  cursor:pointer;font-weight:900;
}
.tab--active{background:rgba(255,255,255,.14);border-color:rgba(255,255,255,.28);}
.form{display:grid;gap:8px;}
.btn{border:none;background:rgba(255,255,255,.12);color:var(--text);padding:10px 12px;border-radius:14px;cursor:pointer;font-weight:900;}
.btn:hover{background:rgba(255,255,255,.16);}
.btn--primary{background:rgba(255,255,255,.18);}
.btn--primary:hover{background:rgba(255,255,255,.22);}
.error{display:inline-block;min-height:18px;color:rgba(255,150,150,.95);font-size:13px;}
.warn{color:rgba(255,255,255,.62);}
.modalTop{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:2px;}

/* ===== School select ===== */
.schoolFilters{display:grid;grid-template-columns:1.2fr 1fr 1fr;gap:10px;margin-bottom:12px;}
.schoolListWrap{border-radius:16px;border:1px solid rgba(255,255,255,.12);background:rgba(255,255,255,.05);padding:12px;}
.schoolListHeader{display:flex;justify-content:space-between;align-items:center;gap:10px;margin-bottom:10px;}
.schoolList{display:grid;grid-template-columns:1fr 1fr;gap:10px;max-height:360px;overflow:auto;padding-right:6px;}
@media(max-width:760px){.schoolFilters{grid-template-columns:1fr}.schoolList{grid-template-columns:1fr}}
.schoolCard{
  border:1px solid rgba(255,255,255,.16);
  background:rgba(0,0,0,.18);
  border-radius:14px;
  padding:12px 12px;
  cursor:pointer;
  text-align:left;
}
.schoolCard:hover{background:rgba(255,255,255,.08);border-color:rgba(255,255,255,.22);}
.schoolCard__name{
  font-weight:1000;
  color:rgba(255,255,255,.98);
  font-size:15px;
}
.schoolCard__meta{
  margin-top:6px;
  font-size:12px;
  color:rgba(255,255,255,.86);
}

.mobOnly{display:none;}

/* ===== Mobile ===== */
.mobTabBar,.mobRail,.mobOverlay{display:none;}

@media (max-width: 999px) {
  .app{
    padding: 14px 14px 74px;
    height:100vh;
  }

  /* ✅ 모바일에서는 PC용 Items/Rank 카드 자체를 숨김 (겹침 해결) */
  #tabItems, #tabRank { display:none !important; }

  .topbar{
    flex-direction:column;
    align-items:stretch;
    gap:10px;
  }
  .topbarRight{width:100%;justify-content:space-between;align-items:stretch;}
  .scoreboard{width:100%;justify-content:space-between;}
  .mySchoolBar{width:100%;justify-content:space-between;}
  .accountWrap{width:100%;}
  .accountBtn{width:100%;justify-content:space-between;}
  .accountMenu{display:none !important;}

  .main{display:block;height:auto;overflow:visible;}

  .mobOnly{
    display:block;
    margin-top:6px;
    font-size:11px;
    color:rgba(255,255,255,.78);
  }

  .mobOnly{
    text-align:center;
  }

  /* ✅ 선물 탭 카드: 헤더와 간격 조금 더 */
  #tabGift{
    position:fixed;
    inset: calc(var(--topbarH) + 18px) 12px 70px 12px; /* ✅ 간격 증가 */
    border-radius:18px;
    overflow:auto;
    -webkit-overflow-scrolling:touch;
    z-index:9994;
    padding:14px;
  }
  .box{height:240px;}
  .box__emoji{font-size:72px;}

  /* ✅ 모바일: 랭킹/내계정 탭은 “화면 맨 위부터” */
  .mobOverlay{
    display:block;
    position:fixed;
    inset: 12px 12px 70px 12px; /* ✅ 맨 위까지 */
    border-radius:18px;
    overflow:hidden;
    z-index:9996;
    background: rgba(10,18,34,.96);
    border:1px solid rgba(255,255,255,.12);
    box-shadow: 0 18px 60px rgba(0,0,0,.55);
  }
  .mobOverlayInner{
    height:100%;
    overflow:auto;
    padding:12px;
  }

  /* ✅ 모바일에서 랭킹/내계정 탭은 헤더/선물 클릭창 숨겨서 겹침 제거 */
  body.mob-tab-rank .topbar,
  body.mob-tab-account .topbar{
    display:none;
  }
  body.mob-tab-rank #tabGift,
  body.mob-tab-account #tabGift{
    display:none !important;
  }

  /* 탭바 */
  .mobTabBar{
    display:flex;
    position:fixed;left:0;right:0;bottom:0;
    height:56px;
    padding:8px 10px calc(8px + env(safe-area-inset-bottom));
    background:rgba(10,18,34,.94);
    border-top:1px solid rgba(255,255,255,.14);
    gap:10px;
    z-index:9998;
  }
  .mobTab{
    flex:1;
    border-radius:14px;
    border:1px solid rgba(255,255,255,.14);
    background:rgba(255,255,255,.06);
    color:rgba(255,255,255,.88);
    font-weight:1000;
    cursor:pointer;
  }
  .mobTab--active{
    background:rgba(255,255,255,.16);
    border-color: rgba(120,200,255,.35);
    color:rgba(255,255,255,.95);
  }

  /* 오른쪽 장식 레일(선물 탭에서만) */
  .mobRail{
    display:flex;
    flex-direction:column;
    gap:10px;
    position:fixed;
    right: max(12px, env(safe-area-inset-right));
    top: 50%;
    transform: translateY(-50%);
    z-index:9997;
  }
  .mobOrb{
    width:56px;height:56px;border-radius:999px;
    border:1px solid rgba(255,255,255,.18);
    background:rgba(10,18,34,.55);
    position:relative;display:grid;place-items:center;
    padding:0;cursor:pointer;
  }
  .mobOrb:disabled{ opacity:.65; cursor:not-allowed; }
  .mobOrbInner{
    width:46px;height:46px;border-radius:999px;
    background:rgba(255,255,255,.08);
    display:grid;place-items:center;position:relative;
  }
  .mobEmoji{ font-size:18px; line-height:1; }
  .mobCnt{
    position:absolute;bottom:-8px;right:-6px;
    min-width:22px;height:18px;padding:0 6px;border-radius:999px;
    background:rgba(20,28,45,.95);
    border:1px solid rgba(255,255,255,.14);
    font-size:11px;font-weight:1000;
    display:grid;place-items:center;color:rgba(255,255,255,.92);
  }
  .orbRing{ position:absolute; inset:0; transform: rotate(-90deg); pointer-events:none; }
  .orbRingBg{ fill:none; stroke: rgba(255,255,255,.10); stroke-width:4; }
  .orbRingFg{
    fill:none;
    stroke: var(--accent);
    stroke-width:4;
    stroke-linecap:round;
    stroke-dasharray: 113.097;
    stroke-dashoffset: 113.097;
    transition: stroke-dashoffset .12s linear;
  }

  /* 선물 탭이면 overlay 숨김 */
  body.mob-tab-gift .mobOverlay{display:none;}
  body.mob-tab-gift .mobRail{display:flex;}
  body.mob-tab-rank .mobRail,
  body.mob-tab-account .mobRail{display:none;}
}

/* 모바일 레이어 안의 랭킹/계정 UI */
.mobSectionTitle{
  margin:0 0 6px;
  font-size:16px;
  font-weight:1000;
}
.mobSectionDesc{
  margin:0 0 12px;
  color:rgba(255,255,255,.75);
  font-size:13px;
}
.mobCard{
  border:1px solid rgba(255,255,255,.12);
  background:rgba(255,255,255,.06);
  border-radius:16px;
  padding:12px;
  margin-bottom:12px;
}
.mobRow{display:flex;justify-content:space-between;gap:10px;align-items:center;}
.mobValue{font-weight:1000;color:rgba(255,255,255,.95);}
.mobMuted{color:rgba(255,255,255,.72);font-size:13px;}
