:root{
  --bg: #171511;
  --surface: #211e19;
  --surface2: #2a271f;
  --border: #3c372c;
  --text: #f1ece2;
  --muted: #a49a86;
  --muted2: #726a59;

  /* 7 video-game-style rarity tiers, common -> unheard of */
  --common: #9a958a;
  --uncommon: #6fb56f;
  --rare: #5b93d6;
  --epic: #a172a0;
  --mythic: #d1905f;
  --legendary: #d1ab5f;
  --unheard: #ff5fc4;
  --tier: var(--common);

  --male: #5b93d6;
  --female: #dd6fa0;

  --glow-color: rgba(241,236,226,0.06);
  --blob-opacity: 0.35;
  --blob-blend: screen;
}

/* ---------------- LIGHT THEME ---------------- */
:root[data-theme="light"]{
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface2: #f1eee5;
  --border: #e1dcd0;
  --text: #201d18;
  --muted: #6b6355;
  --muted2: #93897a;

  --glow-color: rgba(23,21,17,0.045);
  --blob-opacity: 0.16;
  --blob-blend: multiply;
}

*{ box-sizing:border-box; }
html,body{ margin:0; padding:0; }
html{ color-scheme: dark; }
html[data-theme="light"]{ color-scheme: light; }
body{
  background: var(--bg);
  color:var(--text);
  font-family:'Inter', sans-serif;
  min-height:100vh;
  padding:36px 20px 90px;
  transition: background-color .25s ease, color .25s ease;
}
.wrap{ max-width:1080px; margin:0 auto; position:relative; z-index:1; }

/* ---------------- AMBIENT BACKGROUND ---------------- */
.bg-ambient{
  position:fixed; inset:0; z-index:0; overflow:hidden; pointer-events:none;
}
.bg-ambient .blob{
  position:absolute; border-radius:50%; filter:blur(70px);
  opacity: var(--blob-opacity);
  mix-blend-mode: var(--blob-blend);
  will-change:transform;
  transition: opacity .25s ease;
}
.bg-ambient .blob-1{
  width:420px; height:420px; background:var(--rare); top:-10%; left:-8%;
  animation: drift1 26s ease-in-out infinite;
}
.bg-ambient .blob-2{
  width:380px; height:380px; background:var(--mythic); bottom:-12%; right:-6%;
  animation: drift2 32s ease-in-out infinite;
}
.bg-ambient .blob-3{
  width:300px; height:300px; background:var(--legendary); top:40%; left:55%;
  animation: drift3 22s ease-in-out infinite;
}
@keyframes drift1{
  0%,100%{ transform:translate(0,0) scale(1); }
  50%{ transform:translate(60px,80px) scale(1.15); }
}
@keyframes drift2{
  0%,100%{ transform:translate(0,0) scale(1); }
  50%{ transform:translate(-70px,-50px) scale(1.1); }
}
@keyframes drift3{
  0%,100%{ transform:translate(0,0) scale(1); }
  50%{ transform:translate(-40px,60px) scale(0.9); }
}
@media (prefers-reduced-motion: reduce){
  .bg-ambient .blob{ animation:none; }
}

.cursor-glow{
  position:fixed; z-index:0; top:0; left:0; width:520px; height:520px;
  border-radius:50%; pointer-events:none;
  background: radial-gradient(circle, var(--glow-color) 0%, rgba(0,0,0,0) 70%);
  transform:translate(-50%,-50%);
  transition: opacity .3s ease;
  opacity:0;
}
.cursor-glow.visible{ opacity:1; }

/* ---------------- TOPBAR ---------------- */
.topbar{
  display:flex; justify-content:space-between; align-items:flex-start;
  margin-bottom:18px; position:relative;
  gap:10px;
}
.topbar-right{
  display:flex; align-items:center; gap:10px;
}
.icon-btn{
  font-family:'Inter', sans-serif; font-weight:600; font-size:13px;
  background:var(--surface); color:var(--text); border:1px solid var(--border);
  border-radius:100px; padding:8px 14px; cursor:pointer; display:inline-flex; align-items:center; gap:6px;
  transition: background-color .25s ease, border-color .25s ease, color .25s ease;
}
.icon-btn:hover{ border-color:var(--muted); }
.theme-toggle{
  padding:8px 12px; font-size:15px; line-height:1; min-width:38px; justify-content:center;
}

.lang-switch{ display:inline-flex; background:var(--surface); border:1px solid var(--border); border-radius:100px; padding:3px; transition: background-color .25s ease, border-color .25s ease; }
.lang-switch button{
  font-family:'Inter', sans-serif; font-weight:600; font-size:12.5px;
  background:none; border:none; color:var(--muted); padding:7px 13px; border-radius:100px; cursor:pointer;
}
.lang-switch button.active{ background:var(--text); color:var(--bg); }

.popover{
  position:absolute; top:calc(100% + 8px); left:0; z-index:20;
  background:var(--surface); border:1px solid var(--border); border-radius:12px;
  padding:18px 20px; width:260px; max-width:calc(100vw - 40px); box-shadow:0 10px 30px rgba(0,0,0,0.45);
  font-size:13.5px; line-height:1.6; white-space:pre-line; display:none;
}
.popover.open{ display:block; }
.popover a{ color:var(--text); }

/* ---------------- HEADER ---------------- */
header{ margin-bottom:26px; max-width:640px; }
h1{
  font-family:'Fraunces', serif;
  font-size:clamp(30px, 4.6vw, 46px);
  font-weight:600;
  margin:0 0 12px;
  letter-spacing:-0.01em;
  line-height:1.08;
  color:var(--text);
}
.sub{
  color:var(--muted);
  font-size:15.5px;
  line-height:1.6;
  margin-bottom:14px;
}
details.disclaimer{ font-size:13px; color:var(--muted); line-height:1.6; }
details.disclaimer summary{
  cursor:pointer; font-weight:600; color:var(--text);
  list-style:none; display:inline-flex; align-items:center; gap:6px;
}
details.disclaimer summary::-webkit-details-marker{ display:none; }
details.disclaimer summary .toggle-word{ font-weight:500; color:var(--muted); }
details.disclaimer .content{ margin-top:10px; padding-left:2px; }
details.disclaimer .content p{ margin:0 0 8px; }
details.disclaimer .content ul{ margin:6px 0 12px; padding-left:18px; }
details.disclaimer .content li{ margin-bottom:5px; }
details.disclaimer a{ color:var(--muted); }

/* ---------------- TABS ---------------- */
.tabs{ display:flex; gap:26px; margin:30px 0 24px; border-bottom:1px solid var(--border); }
.tab{
  font-family:'Inter', sans-serif; font-weight:600; font-size:14.5px;
  color:var(--muted); background:none; border:none; padding:10px 2px; cursor:pointer; position:relative;
}
.tab.active{ color:var(--text); }
.tab.active::after{ content:''; position:absolute; left:0; right:0; bottom:-1px; height:2px; background:var(--text); }

.view{ display:none; }
.view.active{ display:block; }

.grid{ display:grid; grid-template-columns: 1.05fr 0.95fr; gap:22px; align-items:start; }
@media (max-width:860px){ .grid{ grid-template-columns:1fr; } }

.panel{ background:var(--surface); border:1px solid var(--border); border-radius:14px; padding:22px; transition: background-color .25s ease, border-color .25s ease; }
.panel-title{ font-family:'Inter', sans-serif; font-weight:600; font-size:13px; color:var(--muted); margin-bottom:4px; }
.panel-hint{ font-size:12.5px; color:var(--muted2); margin-bottom:16px; }

.field{ padding:14px 0; border-bottom:1px solid var(--surface2); }
.field:last-of-type{ border-bottom:none; }
.field label.title{ display:block; font-size:13.5px; font-weight:600; color:var(--text); margin-bottom:8px; }
.field .optional-tag{ font-weight:400; color:var(--muted2); font-size:12px; }

select{
  width:100%; background:var(--surface2); border:1px solid var(--border); color:var(--text);
  border-radius:8px; padding:9px 11px; font-family:'Inter', sans-serif; font-size:13.5px; outline:none;
  /* prevents iOS Safari zooming the page in when focusing a <16px select */
  font-size:16px;
}
@media (min-width:640px){
  select{ font-size:13.5px; }
}
select:focus{ border-color:var(--muted); }

.range-row{ display:flex; align-items:center; gap:14px; }
input[type="range"]{
  flex:1; accent-color: var(--uncommon); height:22px; cursor:pointer;
  touch-action:none; /* we handle drag ourselves for a full-width hit area */
}
.range-val{ font-family:'IBM Plex Mono', monospace; font-size:13.5px; font-weight:600; color:var(--text); min-width:58px; text-align:right; }

/* gender switch — segmented control, no overlapping text/thumb */
.gender-switch{
  position:relative; display:flex; align-items:stretch;
  background:var(--surface2); border:1px solid var(--border); border-radius:100px;
  padding:4px; user-select:none; width:100%; height:44px;
}
.gender-switch .highlight{
  position:absolute; top:4px; left:4px; width:calc(50% - 4px); height:calc(100% - 8px);
  border-radius:100px; background:var(--male);
  transition: transform .25s ease, background .25s ease;
}
.gender-switch.is-female .highlight{
  transform: translateX(100%);
  background: var(--female);
}
.gender-switch .option{
  position:relative; z-index:1; flex:1; border:none; background:none; cursor:pointer;
  font-family:'Inter', sans-serif; font-weight:600; font-size:12.5px; color:var(--muted);
  transition: color .2s ease;
}
.gender-switch .option.active{ color:#fff; }

button.primary{
  width:100%; font-family:'Inter', sans-serif; font-weight:600; font-size:14.5px;
  background: var(--text); color:var(--bg); border:none; border-radius:9px; padding:13px 16px;
  cursor:pointer; margin-top:18px;
}
button.primary:hover{ opacity:0.88; }

.card-wrap{ position:sticky; top:20px; }
.result{ background:var(--surface); border:1px solid var(--border); border-radius:14px; padding:26px; transition: background-color .25s ease, border-color .25s ease; }
.result-empty{ color:var(--muted2); font-size:14px; text-align:center; padding:70px 20px; line-height:1.6; }

.tier-word{ font-size:14px; font-weight:700; margin-bottom:10px; letter-spacing:0.02em; color:var(--tier); }
.tier-word .region-qualifier{ font-weight:500; color:var(--muted); }
.tier-word.is-unheard{
  background: linear-gradient(90deg, #ff5fc4, #7ea6c7, #d1ab5f, #a172a0, #ff5fc4);
  background-size: 300% auto;
  -webkit-background-clip: text; background-clip: text; color:transparent;
  animation: shimmer 3.5s linear infinite;
}
@keyframes shimmer{ to{ background-position: 300% center; } }

.ratio-label{ font-size:13px; color:var(--muted); margin-bottom:4px; }
.ratio{
  font-family:'IBM Plex Mono', monospace; font-weight:600; font-size:clamp(28px, 3.6vw, 38px);
  line-height:1.15; color:var(--text); margin-bottom:16px; word-break:break-word;
}
.scale-wrap{ margin-bottom:22px; }
.scale-track{
  position:relative; height:8px; border-radius:5px;
  background: linear-gradient(90deg, var(--common), var(--uncommon), var(--rare), var(--epic), var(--mythic), var(--legendary), var(--unheard));
}
.scale-dot{
  position:absolute; top:50%; width:14px; height:14px; border-radius:50%;
  background:var(--surface); border:3px solid var(--tier); transform:translate(-50%,-50%);
}
.scale-labels{ display:flex; justify-content:space-between; font-size:10.5px; color:var(--muted2); margin-top:7px; }

.bars{ display:flex; flex-direction:column; gap:10px; margin-bottom:20px; }
.bar-label{ display:flex; justify-content:space-between; font-size:12px; color:var(--muted); margin-bottom:5px; }
.bar-label .val{ font-family:'IBM Plex Mono', monospace; }
.bar-track{ background:var(--surface2); border-radius:5px; height:6px; overflow:hidden; }
.bar-fill{ height:100%; background: var(--tier); border-radius:5px; }

.basis-note{ font-size:12px; color:var(--muted2); margin-bottom:18px; line-height:1.5; }

.actions{ display:flex; gap:10px; }
.actions button{
  flex:1; font-family:'Inter', sans-serif; font-weight:600; font-size:13px;
  background:var(--surface2); color:var(--text); border:1px solid var(--border); border-radius:8px;
  padding:10px; cursor:pointer;
}
.actions button:hover{ border-color:var(--tier); }
.actions .save-btn{ background:var(--text); color:var(--bg); border-color:var(--text); }
.copy-flash{ color: var(--uncommon) !important; border-color: var(--uncommon) !important; }

.lb-list{ display:flex; flex-direction:column; gap:8px; }
.lb-row{
  display:grid; grid-template-columns:28px 1fr auto auto; gap:14px; align-items:center;
  background:var(--surface2); border:1px solid var(--border); border-radius:10px; padding:12px 14px;
}
.lb-rank{ font-family:'IBM Plex Mono', monospace; color:var(--muted2); font-size:12.5px; }
.lb-name{ font-weight:600; font-size:13.5px; min-width:0; }
.lb-name .lb-summary{ display:block; font-weight:400; font-size:11.5px; color:var(--muted); margin-top:2px;}
.lb-tier{ font-size:11.5px; color:var(--muted); white-space:nowrap; font-weight:600; }
.lb-ratio{ font-family:'IBM Plex Mono', monospace; font-weight:600; font-size:13px; }
.lb-empty{ color:var(--muted2); font-size:14px; text-align:center; padding:40px 0; }
.lb-loading{ color:var(--muted2); font-size:13px; text-align:center; padding:20px 0; }

footer{ margin-top:50px; font-size:12px; color:var(--muted2); text-align:center; }

/* ==========================================================================
   MOBILE
   ========================================================================== */
@media (max-width:640px){
  body{ padding:20px 14px 70px; }

  .topbar{ margin-bottom:14px; }
  .icon-btn{ padding:7px 11px; font-size:12.5px; }
  .theme-toggle{ padding:7px 10px; }
  .lang-switch button{ padding:6px 11px; font-size:12px; }
  .topbar-right{ gap:8px; }

  header{ margin-bottom:20px; }
  .sub{ font-size:14px; }
  details.disclaimer{ font-size:12.5px; }

  .tabs{ gap:20px; margin:22px 0 18px; }
  .tab{ font-size:14px; }

  .grid{ gap:16px; }
  .panel{ padding:16px; border-radius:12px; }
  .result{ padding:18px; border-radius:12px; }

  /* sticky result card fights with the keyboard/scroll on small screens */
  .card-wrap{ position:static; }

  .field{ padding:12px 0; }

  .ratio{ font-size:clamp(24px, 8vw, 32px); }

  .actions{ flex-direction:column; }
  .actions button{ width:100%; }

  .lb-row{
    display:flex; flex-wrap:wrap; align-items:center; gap:4px 10px;
  }
  .lb-rank{ font-size:11.5px; flex:0 0 auto; }
  .lb-name{ font-size:13px; flex:1 1 auto; min-width:0; }
  .lb-tier{ order:3; font-size:11px; }
  .lb-ratio{ order:4; margin-left:auto; font-size:12.5px; }

  .popover{ width:calc(100vw - 40px); }

  footer{ margin-top:36px; font-size:11.5px; }
}

@media (max-width:380px){
  h1{ font-size:26px; }
  .topbar-right{ gap:6px; }
  .lang-switch button{ padding:6px 9px; }
}
