.rank-page {
  --rank-blue: #2f709c;
  --rank-blue-dark: #1d4d70;
  --rank-gold: #a85c18;
  --rank-gold-dark: #71330e;
}

.rank-page [hidden] {
  display: none !important;
}

.rank-shell {
  width: min(1120px, calc(100% - 30px));
  margin: 26px auto 52px;
}

.rank-header {
  overflow: hidden;
}

.rank-heading {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 22px;
  align-items: center;
  min-height: 142px;
  padding: 22px 28px;
  background:
    linear-gradient(90deg, rgba(255, 245, 212, 0.86), rgba(255, 255, 255, 0.97)),
    repeating-linear-gradient(45deg, transparent 0 12px, rgba(237, 204, 138, 0.18) 12px 14px);
}

.rank-brand {
  display: grid;
  justify-items: center;
  gap: 5px;
  color: #753d1b;
  text-decoration: none;
}

.rank-brand > span {
  display: grid;
  width: 70px;
  height: 70px;
  place-items: center;
  color: #e4612a;
  font-family: Georgia, serif;
  font-size: 2.7rem;
  font-weight: 900;
  background: linear-gradient(145deg, #fff5b8, #ffc857);
  border: 3px solid #76471d;
  border-radius: 50%;
  box-shadow: 0 0 0 3px #f9dc81, 0 4px 0 rgba(68, 42, 20, 0.25);
}

.rank-brand strong {
  font-size: 0.76rem;
}

.rank-heading p {
  margin: 0 0 5px;
  color: #255d87;
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.13em;
}

.rank-heading h1 {
  margin: 0;
  color: #5d3b21;
  font-size: clamp(1.65rem, 4.2vw, 2.8rem);
  line-height: 1.18;
  text-shadow: 2px 2px 0 #fff0b3;
}

.rank-heading div > span {
  display: block;
  margin-top: 9px;
  color: #665743;
  font-size: 0.9rem;
  line-height: 1.55;
}

.rank-mascot {
  display: grid;
  width: 126px;
  height: 100px;
  place-items: center;
  background: radial-gradient(circle, #fff 0 49%, transparent 50%);
}

.rank-mascot img {
  max-width: 112px;
  max-height: 96px;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 5px 0 rgba(78, 53, 26, 0.18));
}

.rank-nav {
  display: flex;
  gap: 5px;
  padding: 6px;
  background: #d1b57a;
  border-top: 2px solid #81623c;
}

.rank-nav a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 15px;
  color: #4b3a25;
  font-size: 0.8rem;
  font-weight: 900;
  text-decoration: none;
  background: linear-gradient(#fff9df, #eed9a5);
  border: 2px solid #8a6b42;
  border-radius: 6px;
  box-shadow: 0 2px 0 #fff inset;
}

.rank-nav a:first-child {
  margin-right: auto;
}

.rank-page main {
  display: block;
  margin-top: 22px;
}

.search-window,
.profile-panel,
.ranking-panel,
.history-panel {
  padding: 14px;
}

.panel-caption {
  min-height: 54px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: -5px -5px 15px;
  padding: 9px 13px;
  color: #fff;
  background: linear-gradient(100deg, #a85c18, #71330e);
  border: 3px solid #612b0b;
  border-radius: 8px;
  box-shadow: 0 3px 0 rgba(59, 43, 28, 0.2), 0 2px 0 rgba(255, 255, 255, 0.25) inset;
}

.panel-caption.blue {
  background: linear-gradient(100deg, #347cae, #255d87);
  border-color: #173f5d;
}

.panel-caption.gold {
  background: linear-gradient(100deg, #a85c18, #71330e);
  border-color: #612b0b;
}

.panel-caption.orange {
  background: linear-gradient(100deg, #a94738, #7f3229);
  border-color: #6e2821;
}

.panel-caption > span:first-child {
  font-size: 1.2rem;
}

.panel-caption h2 {
  margin: 0;
  font-size: 1.12rem;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
}

.panel-caption small,
.panel-caption > span:last-child {
  margin-left: auto;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
}

#rank-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  gap: 14px;
  align-items: end;
  padding: 6px 7px 8px;
}

.ign-field,
.region-field {
  min-width: 0;
}

.ign-field label,
.region-field legend {
  display: block;
  margin-bottom: 7px;
  color: #4d3c28;
  font-size: 0.8rem;
  font-weight: 900;
}

.ign-field input {
  width: 100%;
  min-height: 48px;
  padding: 10px 13px;
  color: #30261a;
  font-size: 1rem;
  font-weight: 800;
  background: #fffefa;
  border: 2px solid #977345;
  border-radius: 7px;
  box-shadow: 0 3px 0 rgba(90, 61, 29, 0.12) inset;
}

.ign-field input:focus {
  outline: 4px solid rgba(32, 83, 150, 0.3);
  border-color: #245e94;
}

.ign-field input:user-invalid {
  border-color: #a93d35;
}

.ign-field > small {
  display: block;
  margin-top: 6px;
  color: #786752;
  font-size: 0.68rem;
}

.region-field {
  display: grid;
  grid-template-columns: repeat(2, 76px);
  gap: 7px;
  margin: 0;
  padding: 0;
  border: 0;
}

.region-field legend {
  grid-column: 1 / -1;
}

.region-field label {
  position: relative;
  min-height: 48px;
  display: grid;
  place-items: center;
  align-content: center;
  cursor: pointer;
}

.region-field input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.region-field label::before {
  position: absolute;
  z-index: 0;
  inset: 0;
  content: "";
  background: linear-gradient(#fffdf2, #ead7aa);
  border: 2px solid #987549;
  border-radius: 7px;
  box-shadow: 0 2px 0 #fff inset, 0 3px 0 rgba(85, 57, 27, 0.13);
}

.region-field label:has(input:checked)::before {
  background: linear-gradient(#ffc969, #e88b2f);
  border-color: #783f18;
}

.region-field label:has(input:focus-visible)::before {
  outline: 4px solid #173f8c;
  outline-offset: 2px;
}

.region-field span,
.region-field small {
  position: relative;
  z-index: 1;
}

.region-field span {
  font-weight: 900;
}

.region-field small {
  color: #6b5a45;
  font-size: 0.62rem;
}

.rank-submit,
.rank-error button,
.search-shortcuts button {
  min-height: 48px;
  padding: 9px 17px;
  color: #fff;
  background: linear-gradient(#4d9b59, #2f713a);
  border: 2px solid #23582e;
  border-radius: 7px;
  box-shadow: 0 2px 0 rgba(255, 255, 255, 0.32) inset, 0 4px 0 rgba(62, 44, 22, 0.2);
  cursor: pointer;
}

.rank-submit {
  display: flex;
  align-items: center;
  gap: 7px;
}

.rank-submit:disabled {
  cursor: wait;
  opacity: 0.68;
}

.rank-submit:hover:not(:disabled),
.rank-error button:hover {
  background: linear-gradient(#5caf68, #377f43);
}

.rank-submit:focus-visible,
.rank-error button:focus-visible,
.search-shortcuts button:focus-visible,
.period-tabs button:focus-visible,
.rank-nav a:focus-visible,
.rank-brand:focus-visible,
.chart-scroll:focus-visible,
.table-scroll:focus-visible {
  outline: 4px solid #173f8c;
  outline-offset: 3px;
}

.search-shortcuts {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 5px 7px 0;
}

.search-shortcuts button {
  min-height: 44px;
  padding: 7px 11px;
  color: #50381f;
  font-size: 0.72rem;
  font-weight: 800;
  background: linear-gradient(#fff5bd, #eacb78);
  border-color: #8a672e;
}

.search-shortcuts > span {
  color: #75634d;
  font-size: 0.7rem;
  line-height: 1.45;
}

.rank-status {
  min-height: 20px;
  margin: 8px 7px 0;
  color: #29633a;
  font-size: 0.78rem;
  font-weight: 800;
}

.rank-status.loading::before {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 7px;
  content: "";
  border: 2px solid #9dc9a5;
  border-top-color: #2f713a;
  border-radius: 50%;
  animation: rank-spin 700ms linear infinite;
}

@keyframes rank-spin { to { transform: rotate(360deg); } }

.rank-error {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 15px;
  align-items: center;
  margin-top: 18px;
  padding: 18px;
  background: #fff4e1;
  border-color: #883c2e;
}

.error-icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: #fff;
  font-size: 1.35rem;
  font-weight: 900;
  background: #b44b3b;
  border: 3px solid #743025;
  border-radius: 50%;
}

.rank-error h2,
.rank-error p {
  margin: 0;
}

.rank-error h2 {
  font-size: 1rem;
}

.rank-error p {
  margin-top: 4px;
  color: #725848;
  font-size: 0.8rem;
  line-height: 1.5;
}

.rank-error button {
  min-height: 42px;
}

.rank-results {
  display: grid;
  gap: 20px;
  margin-top: 20px;
}

.profile-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.93fr) minmax(0, 1.07fr);
  gap: 20px;
}

#ranking-semantics {
  margin-left: auto;
  padding: 4px 8px;
  color: #fff;
  font-size: 0.66rem;
  font-weight: 900;
  background: rgba(24, 37, 28, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 999px;
}

.character-profile {
  display: grid;
  grid-template-columns: 166px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  padding: 6px 5px 16px;
}

.character-avatar-wrap {
  position: relative;
  display: grid;
  width: 162px;
  height: 162px;
  place-items: center;
  background:
    radial-gradient(circle, #fff 0 52%, transparent 53%),
    linear-gradient(180deg, transparent 68%, rgba(94, 153, 67, 0.3) 69% 78%, transparent 79%);
  border: 2px solid #b69560;
  border-radius: 50%;
  box-shadow: 0 4px 0 rgba(79, 55, 29, 0.13);
}

.character-avatar-wrap img {
  max-width: 148px;
  max-height: 148px;
  width: auto;
  height: auto;
  object-fit: contain;
  image-rendering: pixelated;
}

#account-type {
  position: absolute;
  right: 5px;
  bottom: 4px;
  padding: 4px 8px;
  color: #fff;
  font-size: 0.66rem;
  font-weight: 900;
  background: #3d7546;
  border: 2px solid #285433;
  border-radius: 999px;
}

.region-world {
  display: flex;
  gap: 7px;
  margin: 0;
}

.region-world span {
  padding: 3px 7px;
  color: #385a72;
  font-size: 0.66rem;
  font-weight: 900;
  background: #e4f0f7;
  border: 1px solid #89a9bd;
  border-radius: 999px;
}

.character-copy h3 {
  margin: 8px 0 2px;
  font-size: clamp(1.4rem, 4vw, 2.1rem);
  overflow-wrap: anywhere;
}

.character-job {
  display: flex;
  gap: 9px;
  align-items: baseline;
  margin: 0 0 14px;
  color: #685947;
}

.character-job strong {
  color: #b44f24;
}

.exp-progress {
  display: block;
  width: 100%;
  height: 13px;
  overflow: hidden;
  background: #d9cab0;
  border: 2px solid #80613d;
  border-radius: 999px;
  box-shadow: 0 2px 0 rgba(71, 48, 24, 0.15) inset;
  appearance: none;
}

.exp-progress::-webkit-progress-bar {
  background: #d9cab0;
}

.exp-progress::-webkit-progress-value {
  background: linear-gradient(90deg, #f2a23a, #ffd96a);
  border-radius: inherit;
  transition: width 300ms ease;
}

.exp-progress::-moz-progress-bar {
  background: linear-gradient(90deg, #f2a23a, #ffd96a);
  border-radius: inherit;
  transition: width 300ms ease;
}

.exp-caption {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 6px 0 0;
  color: #75634e;
  font-size: 0.67rem;
}

.exp-caption strong {
  color: #8a4d1f;
}

.profile-meta {
  display: grid;
  gap: 1px;
  margin: 0;
  overflow: hidden;
  background: #b99a67;
  border: 1px solid #b99a67;
  border-radius: 7px;
}

.profile-meta div {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr);
  gap: 9px;
  padding: 7px 9px;
  background: #fffaf0;
}

.profile-meta dt,
.profile-meta dd {
  margin: 0;
  font-size: 0.7rem;
  line-height: 1.45;
}

.profile-meta dt {
  color: #78664f;
}

.profile-meta dd {
  min-width: 0;
  text-align: right;
  overflow-wrap: anywhere;
}

.profile-meta a {
  color: #225e8b;
  font-weight: 800;
  text-underline-offset: 2px;
}

.ranking-groups {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.ranking-groups article {
  overflow: hidden;
  background: #fffaf0;
  border: 2px solid #aa8856;
  border-radius: 8px;
  box-shadow: 0 3px 0 rgba(91, 63, 31, 0.12);
}

.ranking-groups article.legion-card {
  grid-column: 1 / -1;
}

.ranking-groups h3 {
  margin: 0;
  padding: 7px 10px;
  color: #fff;
  font-size: 0.78rem;
  background: #7b6040;
}

.ranking-groups dl {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0;
}

.ranking-groups dl div {
  min-width: 0;
  padding: 12px 7px;
  text-align: center;
  border-right: 1px solid #dfcda9;
}

.ranking-groups dl div:last-child {
  border-right: 0;
}

.ranking-groups dt {
  color: #786750;
  font-size: 0.62rem;
}

.ranking-groups dd {
  margin: 6px 0 0;
  color: #3d2c1c;
  font-size: 0.9rem;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.history-panel {
  min-width: 0;
}

.panel-caption.orange > div:nth-child(2) {
  display: grid;
  gap: 2px;
}

.panel-caption.orange > div:nth-child(2) small {
  margin: 0;
  color: #fff;
  font-size: 0.64rem;
}

.period-tabs {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.period-tabs button {
  min-width: 54px;
  min-height: 44px;
  padding: 5px 8px;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 900;
  background: rgba(40, 20, 15, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 5px;
  cursor: pointer;
}

.period-tabs button.active {
  color: #5b2e13;
  background: #ffe28a;
  border-color: #fff4c7;
}

.history-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
  margin-bottom: 15px;
}

.history-metrics article {
  min-width: 0;
  display: grid;
  gap: 5px;
  padding: 12px;
  background: linear-gradient(#fffdf5, #f2e2bc);
  border: 2px solid #a98551;
  border-radius: 8px;
  box-shadow: 0 3px 0 rgba(91, 63, 31, 0.12);
}

.history-metrics span,
.history-metrics small {
  color: #77654e;
  font-size: 0.65rem;
  line-height: 1.35;
}

.history-metrics strong {
  color: #5a361e;
  font-size: 1.17rem;
  overflow-wrap: anywhere;
}

.chart-scroll {
  max-width: 100%;
  overflow-x: auto;
  background: #fffdf6;
  border: 2px solid #a98551;
  border-radius: 8px;
  box-shadow: 0 3px 0 rgba(91, 63, 31, 0.1) inset;
}

#exp-chart {
  display: block;
  width: 100%;
  min-width: 760px;
  height: auto;
  color: #73624d;
}

#exp-chart .grid-line {
  stroke: #ded0b5;
  stroke-width: 1;
}

#exp-chart .axis-text {
  fill: #796953;
  font: 11px "Trebuchet MS", sans-serif;
}

#exp-chart .exp-bar {
  fill: #e98631;
}

#exp-chart .exp-bar.zero {
  fill: #9d927d;
}

#exp-chart .level-marker {
  fill: #347cae;
  stroke: #173f5d;
  stroke-width: 1.5;
}

#exp-chart .missing-marker {
  stroke: #a3473a;
  stroke-width: 1.5;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin: 10px 1px 14px;
  color: #71604a;
  font-size: 0.68rem;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chart-legend i {
  display: inline-block;
  width: 13px;
  height: 9px;
  background: #e98631;
  border-radius: 2px;
}

.chart-legend .legend-level {
  width: 9px;
  height: 9px;
  background: #347cae;
  border: 1px solid #173f5d;
  border-radius: 50%;
}

.chart-legend .legend-missing {
  height: 2px;
  background: #a3473a;
  transform: rotate(-25deg);
}

.history-table-wrap {
  background: #f7e8c8;
  border: 2px solid #9f7b49;
  border-radius: 7px;
}

.history-table-wrap summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 9px 12px;
  color: #503a24;
  font-size: 0.78rem;
  font-weight: 900;
  cursor: pointer;
}

.table-scroll {
  max-height: 420px;
  overflow: auto;
  background: #fffdf7;
  border-top: 1px solid #b99a68;
}

.table-scroll table {
  width: 100%;
  min-width: 600px;
  border-collapse: collapse;
}

.table-scroll caption {
  padding: 10px;
  color: #75644e;
  font-size: 0.7rem;
  text-align: left;
}

.table-scroll th,
.table-scroll td {
  padding: 8px 11px;
  font-size: 0.72rem;
  text-align: right;
  border-bottom: 1px solid #e8dcc5;
}

.table-scroll th:first-child,
.table-scroll td:first-child {
  text-align: left;
}

.table-scroll th {
  position: sticky;
  z-index: 1;
  top: 0;
  color: #fff;
  background: #765d3e;
}

.table-scroll tbody tr:nth-child(even) {
  background: #fff9e9;
}

.history-unavailable {
  display: grid;
  justify-items: center;
  padding: 35px 18px;
  color: #6e5d48;
  text-align: center;
}

.history-unavailable > span {
  font-size: 2.5rem;
}

.history-unavailable h3 {
  margin: 8px 0 5px;
  color: #5b4128;
}

.history-unavailable p {
  max-width: 600px;
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.6;
}

.rank-footer {
  grid-template-columns: minmax(170px, 1fr) auto;
  margin-top: 22px;
}

.rank-footer a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

@media (max-width: 850px) {
  #rank-form {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .rank-submit {
    grid-column: 1 / -1;
    justify-content: center;
  }

  .profile-layout {
    grid-template-columns: 1fr;
  }

  .history-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .rank-shell {
    width: min(100% - 14px, 560px);
    margin-top: 8px;
    margin-bottom: 28px;
  }

  .rank-heading {
    grid-template-columns: 55px minmax(0, 1fr);
    gap: 13px;
    padding: 18px 13px;
  }

  .rank-brand > span {
    width: 51px;
    height: 51px;
    font-size: 2rem;
  }

  .rank-brand strong {
    display: none;
  }

  .rank-heading p {
    font-size: 0.56rem;
    letter-spacing: 0.06em;
  }

  .rank-heading h1 {
    font-size: clamp(1.42rem, 7.5vw, 2rem);
  }

  .rank-heading div > span {
    font-size: 0.76rem;
  }

  .rank-mascot {
    display: none;
  }

  .rank-nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .rank-nav a:first-child {
    grid-column: 1 / -1;
    margin: 0;
  }

  .search-window,
  .profile-panel,
  .ranking-panel,
  .history-panel {
    padding: 10px;
    border-width: 2px;
  }

  #rank-form {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .region-field {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .rank-submit {
    grid-column: auto;
    justify-content: center;
  }

  .search-shortcuts {
    align-items: flex-start;
    flex-direction: column;
  }

  .rank-error {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .rank-error button {
    grid-column: 1 / -1;
  }

  .character-profile {
    grid-template-columns: 115px minmax(0, 1fr);
    gap: 12px;
  }

  .character-avatar-wrap {
    width: 112px;
    height: 112px;
  }

  .character-avatar-wrap img {
    max-width: 104px;
    max-height: 104px;
  }

  .ranking-groups {
    grid-template-columns: 1fr;
  }

  .ranking-groups article.legion-card {
    grid-column: auto;
  }

  .panel-caption.orange {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .period-tabs {
    width: 100%;
    margin: 4px 0 0;
  }

  .period-tabs button {
    min-width: 0;
    min-height: 44px;
    flex: 1;
  }

  .rank-footer a {
    min-height: 44px;
  }

  .history-metrics {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 350px) {
  .rank-shell {
    width: calc(100% - 8px);
  }

  .character-profile {
    grid-template-columns: 92px minmax(0, 1fr);
  }

  .character-avatar-wrap {
    width: 90px;
    height: 90px;
  }

  .character-avatar-wrap img {
    max-width: 84px;
    max-height: 84px;
  }

  .profile-meta div {
    grid-template-columns: 1fr;
  }

  .profile-meta dd {
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rank-status.loading::before {
    animation: none;
  }

  .exp-progress::-webkit-progress-value,
  .exp-progress::-moz-progress-bar {
    transition: none;
  }
}
