:root {
  --realm-ink: #152f34;
  --realm-night: #102c34;
  --realm-teal: #244f51;
  --realm-copper: #ac7d4c;
  --realm-gilt: #e6bd7f;
  --realm-ivory: #f7efdc;
  --realm-paper: #eee4cf;
}

/* A common finish across entry points, with a quieter silhouette for utility actions. */
body[data-page="prepare"] #app .launch-button.command-button,
#app #enter-continent:not(:disabled),
#app .ranked-card [data-action="ranked-trial"]:not(:disabled),
#app .shop-screen .r19-primary:not(:disabled),
#net-dialog [data-net="guest"]:not(:disabled),
#net-dialog [data-net-form="name"] button:not(:disabled) {
  position: relative;
  isolation: isolate;
  min-height: 48px;
  border: 1px solid var(--realm-copper);
  border-radius: 5px 5px 10px 5px;
  background: linear-gradient(140deg, #326263, #183d44 56%, #102c34);
  box-shadow: inset 0 2px #eed5a44a, 0 2px #6e502d, 0 5px 10px #08272c33;
  text-shadow: 0 1px #102c34;
  color: #fff3d7;
  font-weight: 700;
}
body[data-page="prepare"] #app .launch-button.command-button::after,
#app #enter-continent:not(:disabled)::after,
#app .ranked-card [data-action="ranked-trial"]:not(:disabled)::after,
#app .shop-screen .r19-primary:not(:disabled)::after {
  position: absolute;
  inset: 4px;
  border: 1px solid #cfaa7366;
  border-radius: inherit;
  pointer-events: none;
  content: "";
}
body[data-page="prepare"] #app .launch-button .command-seal,
#app #enter-continent .command-seal {
  background: #f1d3a922;
  color: var(--realm-gilt);
  border-color: #ceb48690;
}
#app :is(.r8-nav,.commander-change,.r19-back),
#net-dialog :is([data-net="friend-request"],[data-net="friend-accept"],[data-net="invite"],[data-net="profile-showcase"]),
#net-party [data-net="friends"],
.shop-tabs button {
  min-height: 44px;
  border: 1px solid #a67c5088;
  border-radius: 5px;
  background: linear-gradient(180deg,#fbf4e4,#e9dcc0);
  box-shadow: inset 0 1px #ffffffe3, 0 2px 4px #182c3020;
  color: #233e3e;
  font-weight: 650;
}
#app .r8-lobby-header nav .r8-nav {
  background: linear-gradient(180deg,#244850,#162f37);
  color: #f6e6c6;
  box-shadow: inset 0 1px #b9916255;
}
#app #lobby-screen .lobby-entry:is(.casual,.ranked) {
  border-color: #c9a379a6;
  border-radius: 7px 7px 16px 7px;
  box-shadow: inset 0 0 0 3px #133138,0 9px 26px #0a20384a;
}
#app #lobby-screen .lobby-entry .entry-go {
  padding: 5px 8px;
  border-left: 2px solid var(--realm-gilt);
  background: linear-gradient(90deg,#efd09924,transparent);
  color: #ffe4a2;
}
#app #lobby-screen .lobby-entry .entry-icon { color: #edd298; }
#app :is(.lobby-entry,.command-button,.r19-primary,.r8-nav,.r19-back):not(:disabled):active,
#net-dialog button:not(:disabled):active {
  transform: translateY(1px);
  box-shadow: inset 0 2px 5px #142e364d;
}
#app :is(.lobby-entry,.command-button,.r19-primary,.r8-nav,.r19-back,.capital-tile):focus-visible,
#net-dialog :is(button,summary,textarea):focus-visible,
#net-commander button:focus-visible {
  outline: 2px solid #bc761e;
  outline-offset: 2px;
}
#app button[aria-pressed="true"].capital-tile,
.shop-tabs button[aria-pressed="true"],
#net-dialog [data-net="profile-like"][aria-pressed="true"] {
  border-color: #bd8b49;
  background: #254b4b;
  color: #fff1d5;
  box-shadow: inset 0 0 0 2px #d8b87562;
}
#net-dialog button[aria-busy="true"] { cursor: progress; }
#net-dialog button[aria-busy="true"]::after {
  content: "";
  width: .75em;
  height: .75em;
  border: 1px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  display: inline-block;
  vertical-align: middle;
  margin-inline-start: .35em;
  animation: realm-wait .8s linear infinite;
}
@keyframes realm-wait { to { rotate: 360deg; } }
@media (prefers-reduced-motion: reduce) {
  #net-dialog button[aria-busy="true"]::after { animation: none; }
}
#net-dialog button:disabled {
  color: #516665;
  background: #e2dece;
  border-color: #a9b4a9;
  opacity: 1;
  cursor: default;
  text-shadow: none;
  box-shadow: none;
}

#net-commander .net-name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 4px 9px 4px 5px;
  border-radius: 5px;
  border: 1px solid #9f7e5266;
  background: #fff8e8;
  color: #173d41;
}
#net-commander .net-name img {
  flex: none;
  width: 29px;
  height: 33px;
  object-fit: cover;
  object-position: center 19%;
  border-radius: 3px;
}
#net-commander > [data-net="friends"] { min-height: 44px; }
#net-dialog .net-chat-sender {
  min-height: 44px;
  padding: 0 6px;
  border: 0;
  background: transparent;
  color: #215353;
  box-shadow: none;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.net-dialog--match .net-match-clocks { grid-template-columns: 1fr; }
.net-dialog--match .net-match-status > [data-net="cancel"]:not(:disabled) {
  min-height: 44px;
  border-color: #dbb47a;
  background: #14353ef5;
  color: #fff0d0;
  box-shadow: inset 0 0 0 2px #d7b6823a;
}
.net-match-ready { font-weight: 700; color: #214c4e; }
#battle-screen :is(#pause-button,.map-controls button,.net-battle-tools button) {
  border: 1px solid #d6ae748a;
  background: #16363eea;
  color: #fff0d2;
  border-radius: 5px;
}

/* The banner is the public face of the profile. Everything below is regular page flow. */
#net-dialog.net-dialog--profile { padding: max(8px,env(safe-area-inset-top)) max(10px,env(safe-area-inset-right)) max(8px,env(safe-area-inset-bottom)) max(10px,env(safe-area-inset-left)); }
#net-dialog.net-dialog--profile > .net-panel {
  width: min(930px,100%);
  max-height: 100%;
  padding: 12px clamp(12px,2.4vw,26px) 24px;
  background: #f4eddb;
  color: var(--realm-ink);
  border: 1px solid #ac8b5e;
  border-radius: 11px;
  overscroll-behavior: contain;
  scrollbar-color: #ab9770 #ede4d0;
}
.net-dialog--profile .net-panel > header {
  top: -12px;
  min-height: 44px;
  background: #f4eddb;
  border-bottom: 1px solid #b8a17765;
}
.net-dialog--profile #net-panel { display: grid; gap: 12px; }
#net-dialog .profile-back {
  width: max-content;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: #315355;
  box-shadow: none;
  padding: 0 8px;
}
.profile-back::before { content: "‹"; margin-inline-end: .35em; }
.profile-banner {
  display: grid;
  grid-template-columns: minmax(102px, .8fr) minmax(180px,1.45fr) minmax(145px,1fr);
  align-items: center;
  gap: clamp(12px,2.3vw,26px);
  padding: clamp(12px,2vw,21px);
  border: 1px solid #b78953;
  box-shadow: inset 0 0 0 3px #ecd1ab25;
  border-radius: 7px 7px 17px 7px;
  background: linear-gradient(105deg,#12353cf2 40%,#133b43ec 70%,#224a4bdd),
    url("../img/r20-royal-courtyard.webp") center 42%/cover;
  color: #fff1d5;
}
.profile-portrait {
  min-width: 0;
  overflow: hidden;
  border: 1px solid #cead7c;
  border-radius: 48% 48% 6px 6px / 18% 18% 6px 6px;
  box-shadow: 0 7px 13px #0d26388c;
}
.profile-portrait img { display: block; width: 100%; height: auto; aspect-ratio: 5/6; object-fit: cover; object-position: 50% 20%; }
.profile-identity { min-width: 0; }
#net-dialog .profile-identity h3 {
  margin: 7px 0;
  color: #fff1d5;
  font: 700 clamp(24px,3.1vw,42px)/1.06 Georgia,"Songti SC",SimSun,serif;
  overflow-wrap: anywhere;
}
#net-dialog .profile-banner p { margin: 0; color: #eee4d0; }
.profile-rank { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; font-size: 13px; }
.profile-rank svg,.profile-social svg,.profile-collection svg,.profile-wall form svg { flex: none; width: 16px; height: 16px; }
.profile-rank svg { color: #e7c385; }
.profile-rank span { border-left: 1px solid #d6b47872; padding-left: 6px; }
.profile-social { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; margin-top: 13px; }
.profile-social > button,.profile-wall button,.profile-collection button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.profile-social [data-net="profile-like"] { background: #f5e8ce; color: #443c2f; min-height: 44px; }
.profile-like-count { color: #ebc68f; font-size: 12px; }
.profile-capital {
  margin: 0;
  display: grid;
  justify-items: center;
  padding: 7px;
  min-width: 0;
  border-left: 1px solid #d1ab7858;
}
.profile-capital img { width: min(160px,100%); height: clamp(108px,15vw,168px); object-fit: contain; filter: drop-shadow(0 6px 5px #0a232da0); }
.profile-capital figcaption { display: grid; gap: 3px; text-align: center; overflow-wrap: anywhere; }
.profile-capital figcaption span { color: #e7c391; font-size: 12px; }
.profile-capital figcaption b { color: #fff1d5; }
.profile-section { padding: 12px; border: 1px solid #bca57c75; border-radius: 6px; background: #fff8e9; }
.profile-section-title { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 14px; }
#net-dialog .profile-section-title h3 { margin: 0 0 4px; font-size: 17px; }
.profile-section-title > span,.profile-empty { color: #526665; font-size: 13px; }
.profile-history { padding: 0; margin: 8px 0 0; list-style: none; }
.profile-history li { display: grid; grid-template-columns: minmax(3.4em,auto) 1fr auto; align-items: baseline; gap: 10px; padding: 7px 0; border-top: 1px solid #c9b59066; font-size: 13px; }
.profile-history li time,.profile-note time { color: #526665; font-size: 12px; }
.profile-outcome--won { color: #235b49; }
.profile-outcome--lost { color: #793e32; }
.profile-collection { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(118px,100%),1fr)); gap: 8px; margin-top: 10px; }
.profile-collection-item { display: grid; place-items: center; align-content: start; gap: 7px; padding: 7px; text-align: center; min-width: 0; border: 1px solid #cbb79171; background: #f4ead5; border-radius: 4px; }
.profile-collection-item.is-showcase { border-color: #986d39; }
.profile-collection-item img { width: min(106px,100%); height: 84px; object-fit: contain; }
.profile-collection-item b { font-size: 13px; overflow-wrap: anywhere; }
.profile-collection-item button { width: 100%; font-size: 12px; padding: 5px; }
.profile-wall :is(button,summary),.profile-account :is(button,summary) { min-height: 44px; }
.profile-wall form { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: end; gap: 6px 9px; padding: 8px 0; border: 0; }
.profile-wall form label { grid-column: 1/-1; font-size: 13px; }
.profile-wall textarea { width: 100%; min-height: 52px; padding: 8px; border: 1px solid #aa9471; border-radius: 4px; background: #fffcf4; font: inherit; resize: vertical; }
.profile-wall form button { background: #24494c; color: #fff2db; border-color: #a77e4d; }
.profile-note { border-top: 1px solid #c9b59066; padding: 9px 0 4px; }
.profile-note header { display: flex; justify-content: space-between; gap: 10px; }
.profile-note p { white-space: pre-wrap; overflow-wrap: anywhere; margin: 4px 0; }
.profile-note-actions { display: flex; flex-wrap: wrap; gap: 6px; }
#net-dialog .profile-note-actions button { background: transparent; border-color: transparent; color: #355758; box-shadow: none; font-size: 12px; }
.profile-account,.profile-blocked { padding: 0 10px; border: 1px solid #bca57c75; border-radius: 4px; }
.profile-account summary,.profile-blocked summary { cursor: pointer; padding: 12px 0; }
.profile-blocked > div { display: flex; align-items: center; gap: 10px; }
.profile-account p { overflow-wrap: anywhere; }

#app .shop-tabs { display: flex; justify-content: center; gap: 8px; margin: 8px 0 16px; }
.shop-tabs button { min-width: min(132px,42vw); padding: 0 10px; }
.capital-shop-layout { width: min(1150px,100%); margin: 0 auto; display: grid; grid-template-columns: minmax(240px, .88fr) minmax(290px,1.3fr); align-items: start; gap: 14px; padding-bottom: 16px; }
.capital-shop-feature {
  border: 1px solid #a38860; border-radius: 7px; overflow: hidden;
  background: #f9f1df; color: #183d41;
}
.capital-shop-art { display: grid; place-items: center; min-height: 168px; padding: 15px; background: radial-gradient(ellipse at bottom,#698986,#213f4c 84%); }
.capital-shop-art img { width: min(220px,100%); height: clamp(135px,21vw,226px); object-fit: contain; filter: drop-shadow(0 7px 4px #122a35b3); }
.capital-shop-copy { padding: 12px 16px; }
.capital-shop-copy h2 { font: 700 clamp(19px,2.7vw,27px)/1.15 Georgia,"Songti SC",SimSun,serif; margin: 0; color: #183d41; }
.capital-shop-copy p { margin: 6px 0 10px; color: #35595a; }
.capital-shop-copy button+button { margin-top: 7px; }
.capital-shop-feedback:empty { display: none; }
.capital-shop-roster { display: grid; grid-template-columns: repeat(auto-fit,minmax(110px,1fr)); gap: 8px; }
#app .capital-tile {
  display: grid; align-content: start; justify-items: center; gap: 3px;
  min-width: 0; min-height: 44px; padding: 6px;
  border: 1px solid #a8895f87; border-radius: 5px;
  background: #fff7e5; color: #1d4446; text-align: center;
}
.capital-tile img { width: min(100%,94px); height: 74px; object-fit: contain; }
.capital-tile b { font-weight: 650; line-height: 1.16; font-size: 13px; overflow-wrap: anywhere; }
.capital-tile small { font-size: 12px; }
@media (max-width: 690px) {
  .capital-shop-layout { grid-template-columns: minmax(0,1fr); }
}
@media (max-width: 575px) {
  .profile-banner { grid-template-columns: minmax(64px,0.52fr) minmax(0,1.48fr); gap: 9px; }
  .profile-capital { grid-column: 1/-1; grid-template-columns: 78px 1fr; align-items: center; justify-items: start; border-left: 0; border-top: 1px solid #d1ab7860; padding: 5px 5px 0; }
  .profile-capital img { width: 78px; height: 78px; }
  .profile-capital figcaption { text-align: start; }
  .profile-history li { gap: 7px; }
  .profile-section { padding: 10px; }
}
@media (max-width: 350px) {
  #net-dialog .profile-identity h3 { font-size: 21px; }
}
@media (max-width: 580px) and (orientation: portrait) {
  body[data-page="prepare"] #app .selection-screen {
    padding-bottom: calc(82px + env(safe-area-inset-bottom));
  }
  body[data-page="prepare"] #app .selection-launch {
    position: fixed;
    z-index: 20;
    inset: auto 0 0;
    width: auto;
    display: grid;
    grid-template-columns: minmax(70px,1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 8px max(13px,env(safe-area-inset-right)) max(8px,env(safe-area-inset-bottom)) max(13px,env(safe-area-inset-left));
    margin: 0;
    border-top: 1px solid #c6a474;
    background: #0d2933fa;
    box-shadow: 0 -4px 16px #0b212c6b;
  }
  body[data-page="prepare"] #app .launch-note {
    min-width: 0;
    color: #f1e6cc;
    line-height: 1.25;
  }
  body[data-page="prepare"] #app .launch-note b { margin: 0; padding: 0; font-size: 12px; color: #f1e6cc; }
  body[data-page="prepare"] #app .launch-note :is(.launch-icon,small) { display: none; }
  body[data-page="prepare"] #app .launch-button.command-button {
    width: auto;
    min-height: 49px;
    min-width: 0;
    padding: 7px 9px;
    gap: 7px;
    font-size: 15px;
  }
  body[data-page="prepare"] #app .launch-button .command-seal {
    width: 24px;
    height: 26px;
    margin: 0;
    flex: 0 0 24px;
  }
}
