:root {
  --ink: #18352d;
  --paper: #f7f5ed;
  --muted: #728277;
  --line: #d9dfd2;
  --accent: #ec7546;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: #152e29;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang TC', sans-serif;
}
button,
input {
  font: inherit;
}
button,
a,
input,
summary {
  -webkit-tap-highlight-color: transparent;
}
button,
summary {
  cursor: pointer;
}
button:disabled {
  opacity: 0.5;
  cursor: wait;
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
a {
  color: inherit;
  text-decoration: none;
}
[hidden] {
  display: none !important;
}
#game {
  position: fixed;
  inset: 0;
}
#game canvas {
  display: block;
  touch-action: none;
}
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow: auto;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  background: var(--paper);
}
.welcome-art {
  background: #193b30;
  color: var(--paper);
  padding: 40px 8%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 36px;
  min-height: 100vh;
}
.brand {
  font-size: 20px;
  font-weight: 750;
}
.brand span {
  color: #f3be64;
}
.welcome-art h1 {
  font-size: clamp(38px, 4vw, 62px);
  letter-spacing: -2px;
  line-height: 1.35;
  margin: 20px 0;
}
.welcome-art p:not(.eyebrow) {
  font-size: 14px;
  color: #ccd6c8;
}
.welcome-art img {
  width: 100%;
  border-radius: 8px;
  transform: rotate(-2deg);
  margin: 24px 0;
  box-shadow: 8px 8px 0 #ffffff12;
}
.welcome-art > a:last-child {
  font-size: 12px;
  color: #c6d3c5;
}
.eyebrow {
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 2px;
}
.edition {
  display: block;
  font-size: 9px;
  letter-spacing: 2px;
  color: #bdd0c0;
}
.welcome-form {
  max-width: 530px;
  align-self: center;
  width: 100%;
  padding: 42px 50px;
  margin: auto;
}
.welcome-form h2 {
  font-size: 31px;
  margin: 15px 0;
}
.muted {
  font-size: 14px;
  line-height: 1.9;
  color: var(--muted);
}
fieldset {
  border: 0;
  padding: 0;
  margin: 30px 0 22px;
  display: flex;
  gap: 8px;
}
legend {
  font-size: 12px;
  margin-bottom: 12px;
}
fieldset button {
  border: 1px solid var(--line);
  background: #eeeee3;
  border-radius: 9px;
  flex: 1;
  min-width: 0;
  padding: 8px 3px;
  font-size: 10px;
  color: var(--ink);
}
fieldset button[aria-pressed='true'] {
  border: 2px solid var(--ink);
  background: #dfe7d0;
}
fieldset img {
  display: block;
  width: 100%;
  height: 65px;
  object-fit: contain;
}
.primary {
  border: 0;
  border-radius: 6px;
  padding: 16px 20px;
  background: var(--ink);
  color: white;
  width: 100%;
  text-align: left;
  font-size: 14px;
}
.primary span {
  float: right;
}
.small {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.8;
}
.scope {
  border-top: 1px solid var(--line);
  padding-top: 15px;
  margin-top: 23px;
}
details {
  border-top: 1px solid var(--line);
  padding-top: 20px;
  margin-top: 25px;
}
summary {
  font-size: 13px;
}
form > label {
  display: block;
  font-size: 12px;
  margin-top: 13px;
}
form > label > input {
  display: block;
  width: 100%;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 5px;
  margin-top: 7px;
  background: #fff;
}
form .primary {
  margin-top: 18px;
}
.mode-options {
  display: flex;
  gap: 20px;
  margin-top: 20px;
  font-size: 12px;
}
#login-status {
  font-size: 12px;
  line-height: 1.7;
  color: #986238;
}
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
}
.topbar {
  display: flex;
  gap: 18px;
  align-items: center;
  padding: 18px 24px;
  background: linear-gradient(#122c29b5, transparent);
  color: white;
  pointer-events: auto;
}
.wordmark {
  font-size: 34px;
  font-weight: 900;
  line-height: 1;
}
.wordmark span {
  font-size: 15px;
  color: #f2c56b;
  vertical-align: top;
}
.player-info strong {
  font-size: 13px;
}
.hp-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 7px;
}
.hp-row progress {
  appearance: none;
  width: 130px;
  height: 6px;
  border: 0;
  border-radius: 5px;
  overflow: hidden;
  background: #ffffff40;
}
.hp-row progress::-webkit-progress-bar {
  background: #ffffff40;
}
.hp-row progress::-webkit-progress-value {
  background: #c7e896;
}
.hp-row span {
  font-size: 10px;
}
.place {
  margin-left: auto;
  text-align: right;
}
.place strong {
  display: block;
  font-size: 14px;
}
.place small {
  font-size: 10px;
  color: #c7dacb;
}
.icon-button {
  background: #14382dd9;
  color: white;
  border: 1px solid #ffffff35;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 18px;
}
.world-badge {
  position: absolute;
  top: 100px;
  left: 24px;
  background: #f7f5edea;
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 11px;
  padding: 10px 15px;
  border-radius: 30px;
  box-shadow: 0 3px 15px #0001;
}
.live-dot {
  width: 6px;
  height: 6px;
  background: #648b56;
  border-radius: 50%;
}
.bottom-bar {
  position: absolute;
  bottom: 22px;
  left: 24px;
  right: 24px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.bottom-bar button {
  pointer-events: auto;
  background: #16382eec;
  color: #eef3dd;
  border: 1px solid #ffffff2a;
  padding: 11px 15px;
  border-radius: 6px;
  font-size: 12px;
}
kbd {
  font: 9px monospace;
  color: #b8ccba;
  margin-left: 12px;
}
#position {
  margin-left: auto;
  font-size: 10px;
  color: white;
  text-shadow: 0 1px 3px #000;
}
.keyboard-hint {
  position: absolute;
  bottom: 73px;
  left: 24px;
  font-size: 10px;
  color: white;
  text-shadow: 0 1px 3px #000;
}
#toast {
  position: absolute;
  top: 145px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(500px, 90vw);
  background: #16382ef0;
  color: white;
  padding: 13px 20px;
  border-radius: 8px;
  font-size: 13px;
  text-align: center;
  line-height: 1.6;
}
dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink);
  width: min(650px, 92vw);
  padding: 26px;
  max-height: 85dvh;
  box-shadow: 0 20px 100px #0005;
}
dialog::backdrop {
  background: #0b211d80;
  backdrop-filter: blur(4px);
}
.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.panel-heading h2 {
  font-size: 23px;
  margin: 0;
}
@media (hover: hover) and (pointer: fine) {
  #panel .panel-heading { cursor: grab; user-select: none; }
  #panel[data-dragging="true"] .panel-heading { cursor: grabbing; }
  #panel .panel-heading button { cursor: pointer; }
  #panel[open][data-drag-positioned="true"] {
    position: fixed;
    inset: auto;
    left: var(--panel-drag-left);
    top: var(--panel-drag-top);
    margin: 0;
    transform: none;
  }
}
.panel-heading button,
.chat-heading button {
  border: 0;
  background: none;
  color: inherit;
  font-size: 26px;
}
.world-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.world-option {
  background: #e6ecde;
  border: 1px solid #cbd6c0;
  color: var(--ink);
  border-radius: 8px;
  padding: 20px;
  text-align: left;
}
.world-option strong {
  display: block;
  font-size: 18px;
  margin-bottom: 9px;
}
.world-option small {
  font-size: 10px;
  color: var(--muted);
}
.world-option.current {
  border: 2px solid #254b36;
}
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.list-row small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  margin-top: 5px;
}
.list-row button,
.panel-action {
  background: var(--ink);
  color: white;
  border: 0;
  border-radius: 4px;
  padding: 10px 14px;
  font-size: 12px;
}
.panel-action {
  margin: 8px 8px 0 0;
}
.empty {
  padding: 30px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 2;
}
.stats {
  display: flex;
  gap: 22px;
  font-size: 13px;
  padding: 15px 0;
}
.danger {
  background: #8b493b;
}
.notice {
  background: #e8eddf;
  font-size: 12px;
  padding: 14px;
  border-radius: 6px;
  line-height: 1.8;
}
#chat-panel {
  position: fixed;
  bottom: 85px;
  left: 24px;
  z-index: 5;
  background: #f7f5edf5;
  border: 1px solid var(--line);
  border-radius: 10px;
  width: min(360px, calc(100vw - 48px));
  padding: 16px;
  box-shadow: 0 8px 30px #0002;
}
.chat-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}
#chat-messages {
  height: 180px;
  overflow: auto;
  overflow-wrap: anywhere;
  font-size: 12px;
  line-height: 1.8;
}
#chat-messages p {
  margin: 8px 0;
}
#chat-form {
  display: flex;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  gap: 8px;
}
#chat-input {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  padding: 10px;
  border-radius: 5px;
}
#chat-form button {
  border: 0;
  background: var(--ink);
  color: white;
  border-radius: 5px;
  white-space: nowrap;
}
#touch-controls {
  display: none;
  position: absolute;
  bottom: max(82px, env(safe-area-inset-bottom));
  left: 20px;
  right: 20px;
  justify-content: space-between;
  align-items: end;
}
.move-controls,
.action-controls {
  display: flex;
  gap: 10px;
}
.action-controls {
  max-width: 190px;
  flex-wrap: wrap;
  justify-content: end;
}
#touch-controls button {
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  border: 1px solid #fff8;
  background: #14372c9e;
  color: white;
  border-radius: 50%;
  width: 54px;
  height: 54px;
  font-size: 13px;
  box-shadow: 0 3px 8px #0002;
}
#touch-controls button.held {
  background: #d3e8a5;
  color: var(--ink);
}
#loading {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #16382ef5;
  color: var(--paper);
  display: grid;
  place-items: center;
  text-align: center;
}
#loading h2 {
  font-size: 24px;
}
#progress {
  width: 250px;
  height: 5px;
  accent-color: #d7e5a2;
}
#fatal {
  position: fixed;
  inset: 25%;
  z-index: 30;
  background: var(--paper);
  border-radius: 12px;
  padding: 30px;
  line-height: 1.8;
}
@media (pointer: coarse) {
  #touch-controls {
    display: flex;
  }
  .keyboard-hint,
  kbd {
    display: none;
  }
  .bottom-bar {
    bottom: 16px;
  }
}
@media (max-width: 700px) {
  .overlay {
    grid-template-columns: 1fr;
  }
  .welcome-art {
    min-height: 0;
    padding: 25px;
    gap: 15px;
  }
  .welcome-art > div {
    display: none;
  }
  .welcome-art > a:last-child {
    display: none;
  }
  .welcome-form {
    padding: 28px;
  }
  .topbar {
    gap: 10px;
    padding: 15px;
  }
  .hp-row progress {
    width: 75px;
  }
  .hp-row span {
    font-size: 8px;
  }
  .place strong {
    font-size: 12px;
  }
  .icon-button {
    width: 33px;
    height: 33px;
  }
  .world-badge {
    top: 88px;
    left: 15px;
    font-size: 10px;
  }
  .bottom-bar {
    left: 15px;
    right: 15px;
    gap: 5px;
  }
  .bottom-bar button {
    font-size: 10px;
    padding: 10px;
  }
  #position {
    font-size: 8px;
  }
  .keyboard-hint {
    left: 15px;
    font-size: 9px;
  }
  #touch-controls {
    left: 15px;
    right: 15px;
  }
  .action-controls {
    gap: 8px;
    max-width: 130px;
  }
  #touch-controls button {
    width: 49px;
    height: 49px;
  }
  .world-grid {
    gap: 8px;
  }
  .world-option {
    padding: 15px;
  }
  dialog {
    padding: 20px;
  }
  .hp-row {
    gap: 5px;
  }
}
@media (max-height: 500px) and (pointer: coarse) {
  #touch-controls {
    bottom: 65px;
  }
  .action-controls {
    max-width: none;
  }
  .world-badge {
    top: 75px;
  }
  .topbar {
    padding: 10px 18px;
  }
  .keyboard-hint {
    display: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto;
  }
}

.place {
  min-width: 0;
  max-width: 240px;
}
.place small {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-info {
  flex-shrink: 0;
}
.topbar > .icon-button {
  flex-shrink: 0;
}
@media (max-width: 420px) {
  .wordmark {
    display: none;
  }
  .place {
    max-width: 105px;
  }
  .topbar {
    gap: 8px;
  }
  .hp-row span {
    white-space: nowrap;
  }
  .bottom-bar kbd {
    display: none;
  }
  #touch-controls {
    display: flex;
  }
  .keyboard-hint {
    display: none;
  }
  .action-controls {
    max-width: 115px;
  }
}

.form-field {
  display: block;
  margin: 12px 0;
  font-size: 13px;
}
.form-field input,
.form-field select {
  display: block;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  margin-top: 6px;
  background: white;
  color: var(--ink);
}
.message-history {
  max-height: 35dvh;
  overflow: auto;
}
.message {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
}
.message p {
  white-space: pre-wrap;
}
.message small {
  color: var(--muted);
}
.portrait {
  width: 40px;
  height: 48px;
  object-fit: contain;
}
.table-scroll {
  overflow: auto;
}
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12px;
}
th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 10px;
  white-space: nowrap;
}
.recovery-code {
  font-size: 24px;
  overflow-wrap: anywhere;
  user-select: all;
}
.skill-bar {
  position: absolute;
  right: 24px;
  bottom: 80px;
  display: flex;
  gap: 6px;
  align-items: center;
  pointer-events: auto;
}
.skill-bar button {
  color: white;
  background: #193a30e8;
  border: 1px solid #ffffff60;
  border-radius: 8px;
  min-width: 52px;
  padding: 10px 8px;
  font-size: 12px;
}
.skill-bar small {
  display: block;
  font-size: 10px;
  color: #dcecb8;
  margin-top: 5px;
}
#quick-consumable {
  position: absolute;
  right: 100px;
  bottom: calc(100% + 10px);
  max-width: 140px;
}
.skill-bar > span {
  font-size: 10px;
  color: white;
}
.skill-bar button:disabled {
  cursor: default;
  opacity: 0.65;
}
@media (max-width: 700px), (pointer: coarse) {
  .skill-bar {
    bottom: 210px;
    right: 15px;
    gap: 4px;
  }
  .skill-bar button {
    padding: 8px 6px;
    min-width: 43px;
    font-size: 11px;
  }
  .skill-bar > span {
    position: absolute;
    top: -20px;
    right: 0;
  }
  .list-row {
    flex-wrap: wrap;
  }
}
@media (max-height: 500px) {
  .skill-bar {
    bottom: 132px;
    right: 15px;
  }
  .skill-bar > span {
    display: none;
  }
}

/* iOS action pad: ranged / ultimate / super, attack / jump / defense. */
.skill-bar {
  display: grid;
  grid-template-columns: repeat(3, var(--control-size));
  gap: 10px;
  bottom: max(84px, env(safe-area-inset-bottom));
  right: max(18px, env(safe-area-inset-right));
  z-index: 30;
  touch-action: none;
  user-select: none;
}
.skill-bar > button:not(#quick-consumable) {
  width: var(--control-size); height: var(--control-size); min-width: 0; padding: 5px;
  font-size: 15px;
  border-radius: 50%; touch-action: none;
}
/* I O P / J K L order with the original staggered action pad. */
.skill-bar > [data-skill="ranged"] { grid-area: 1 / 1; }
.skill-bar > [data-skill="ultimate"] { grid-area: 1 / 2; }
.skill-bar > [data-skill="super"] { grid-area: 1 / 3; }
.skill-bar > [data-control="attack"] { grid-area: 2 / 1; }
.skill-bar > [data-control="jump"] { grid-area: 2 / 2; }
.skill-bar > [data-skill="defense"] { grid-area: 2 / 3; }
.skill-bar > [data-skill="ultimate"], .skill-bar > [data-control="jump"] { transform: translateY(-7px); }
.skill-bar > [data-skill="super"], .skill-bar > [data-skill="defense"] { transform: translateY(-14px); }
.skill-bar > span { position: absolute; top: -36px; left: 0; right: auto; }
#quick-consumable { right: 0; bottom: calc(100% + 28px); }
#touch-controls { z-index: 30; right: auto; gap: 12px; pointer-events: none; }
#touch-controls > [data-control="interact"] { position: absolute; bottom: calc(var(--control-size) + 14px); left: 0; }
@media (max-width: 700px) {
  .skill-bar { gap: 7px; right: max(8px, env(safe-area-inset-right)); }
  #touch-controls { left: max(8px, env(safe-area-inset-left)); }
  .move-controls { gap: 6px; }
}

/* Fixed inset is recalculated by the browser on every orientation change.
   Never retain portrait/landscape pixel dimensions on the parent or canvas. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
#hud, #game {
  position: fixed;
  inset: 0;
  width: auto;
  height: auto;
  min-width: 0;
  min-height: 0;
}
#game { z-index: 0; overflow: hidden; }
#game canvas { width: 100% !important; height: 100% !important; margin: 0 !important; }
#hud { z-index: 1; }
html:fullscreen, html:-webkit-full-screen { overflow: hidden; }
#fullscreen-button { flex-shrink: 0; }
@media (max-height: 500px) and (orientation: landscape) {
  .skill-bar { bottom: max(68px, calc(env(safe-area-inset-bottom) + 60px)); }
  #touch-controls { display: flex; bottom: max(68px, calc(env(safe-area-inset-bottom) + 60px)); }
  .topbar { padding-top: max(8px, env(safe-area-inset-top)); gap: 8px; }
  .world-badge, .keyboard-hint { display: none; }
}

/* Larger visible controls and hit areas share the same responsive dimensions. */
#hud { --control-size: clamp(56px, 16vw, 72px); }
#touch-controls button {
  width: var(--control-size);
  height: var(--control-size);
  flex-shrink: 0;
  font-size: 17px;
}
#quick-consumable {
  min-width: var(--control-size);
  min-height: var(--control-size);
  font-size: 14px;
}
#hud .icon-button { width: 44px; height: 44px; font-size: 21px; }
.bottom-bar { bottom: max(8px, env(safe-area-inset-bottom)); }
.bottom-bar button { min-height: 44px; font-size: 13px; }
@media (max-height: 500px) and (min-width: 600px) and (orientation: landscape) {
  #quick-consumable { right: calc(100% + 14px); bottom: 0; }
}
@media (max-width: 420px) {
  .topbar { gap: 5px; padding-left: 8px; padding-right: 8px; }
  .topbar .place { display: none; }
  .bottom-bar { left: 8px; right: 8px; }
  #position { display: none; }
}

.item-icon {
  display: inline-flex; flex: 0 0 48px; width: 48px; height: 48px;
  align-items: center; justify-content: center; vertical-align: middle;
  border-radius: 8px; background: #e7ecdf; color: #526953; font-size: 25px;
}
.item-icon img { width: 100%; height: 100%; object-fit: contain; padding: 4px; }
.item-shop-button { display: inline-flex; align-items: center; gap: 10px; margin: 4px; }

#touch-controls > [data-control="interact"] small {
  display: block;
  margin-top: 5px;
  font-size: 10px;
  color: #dcecb8;
}

/* iOS Safari needs the prefixed rule on both controls and their child labels. */
#hud button,
#hud button *,
#touch-controls,
#touch-controls *,
.skill-bar,
.skill-bar * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#hud button {
  touch-action: none;
}

.appearance-stage { display:flex; justify-content:center; background:radial-gradient(ellipse at bottom,#59605a,#252c35 70%); border-radius:14px; margin-bottom:12px; }
.appearance-stage canvas { width:174px; height:240px; object-fit:contain; }
.appearance-picker { display:grid; grid-template-columns:88px 44px minmax(0,1fr) 44px; align-items:center; gap:8px; margin:12px 0 8px; }
.appearance-picker button { font-size:26px; min-height:44px; padding:0; }
.appearance-picker select { width:100%; min-width:0; }
@media (max-height:700px) { .appearance-stage canvas { width:116px; height:160px; } }

.appearance-controls { min-width:0; }
.appearance-picker button { margin:0; }
@media (max-height:740px) {
  #panel[data-feature-view="appearance"] { padding:16px; max-height:94dvh; }
  #panel[data-feature-view="appearance"] .panel-heading { margin-bottom:10px; }
  .appearance-layout { display:grid; grid-template-columns:minmax(72px, 1fr) minmax(172px, 2fr); gap:14px; align-items:center; }
  .appearance-stage { margin:0; align-self:stretch; align-items:center; min-width:0; }
  .appearance-stage canvas { width:100%; max-width:174px; height:auto; max-height:240px; }
  .appearance-controls > .small { margin:0 0 8px; }
  .appearance-picker { grid-template-columns:36px minmax(0,1fr) 36px; gap:4px; margin:8px 0; }
  .appearance-picker > span { grid-column:1 / -1; font-size:12px; }
  .appearance-picker select { padding:8px 4px; }
}
@media (max-height:450px) and (min-width:540px) {
  .appearance-picker { grid-template-columns:36px 40px minmax(0,1fr) 40px; }
  .appearance-picker > span { grid-column:auto; }
  .appearance-stage canvas { max-height:190px; width:auto; max-width:100%; }
}

.friend-identity { display:flex; align-items:center; gap:10px; min-width:0; flex:1; }
.friend-identity > span { overflow-wrap:anywhere; }
.friend-portrait { width:44px; height:44px; flex:0 0 44px; border-radius:50%; background:#e6ecde; border:1px solid var(--line); }
.friend-row > button { flex-shrink:0; }
@media (max-width: 600px) {
  .topbar .player-info { flex:1 1 auto; min-width:0; }
  .topbar .player-info strong { display:block; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  .topbar .hp-row { flex-wrap:wrap; gap:2px; }
  .topbar .hp-row progress { width:100%; min-width:0; }
  .topbar .place { display:none; }
}

@media (max-width:600px) {
  .topbar { display:grid; grid-template-columns:repeat(6,minmax(0,1fr)); gap:5px; padding:8px; }
  .topbar .wordmark, .topbar .place { display:none; }
  .topbar .player-info { grid-column:1 / -1; display:flex; align-items:center; gap:12px; }
  .topbar .player-info strong { flex:1; }
  .topbar .hp-row { flex-wrap:nowrap; width:150px; }
  .topbar .hp-row progress { width:80px; }
  .topbar .hp-row span { white-space:nowrap; }
  .topbar > .icon-button { justify-self:end; }
}

/* Bottom HUD row removed: keep both control pads near the safe bottom edge. */
.skill-bar, #touch-controls { bottom:calc(env(safe-area-inset-bottom, 0px) + 12px); }

#quick-consumable .quick-key-hint {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 1px solid #ffffff80;
  border-radius: 5px;
  background: #16352e;
  color: #fff;
  font: 700 12px/1 sans-serif;
  pointer-events: none;
}

.inventory-preview { margin-bottom:18px; }
.inventory-preview .appearance-stage { min-height:160px; }
.inventory-preview .appearance-stage canvas { width:145px; height:200px; }
.inventory-preview .appearance-picker { margin:8px 0; }
.inventory-preview .small { text-align:center; }

.inventory-tabs { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:6px; margin-bottom:16px; }
.inventory-tabs .inventory-tab { margin:0; padding:10px 4px; min-height:44px; font-size:13px; border:1px solid #b6c7bf; border-radius:10px; background:#edf3ef; color:#264437; }
.inventory-tabs .inventory-tab[aria-current="page"] { background:#235d48; color:white; border-color:#235d48; font-weight:700; }
.inventory-tabs .inventory-tab:focus-visible { outline:3px solid #d69232; outline-offset:2px; }

.inventory-categories { grid-template-columns:repeat(5,minmax(0,1fr)); margin-top:12px; }

/* Keep invitation decisions side by side on phones and desktop. */
.invitation-actions { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:12px; width:100%; }
.invitation-actions > .panel-action { width:100%; min-width:0; min-height:48px; margin:0; }

#social-button { position:relative; overflow:visible; }
.private-unread-badge { position:absolute; top:-6px; right:-6px; display:flex; align-items:center; justify-content:center; min-width:20px; height:20px; padding:0 4px; border:2px solid #fff; border-radius:12px; background:#d6001c; color:#fff; font:700 11px/1 sans-serif; pointer-events:none; box-shadow:0 1px 4px #0005; }
.private-unread-badge[hidden] { display:none; }

/* Private messages keep the sender and avatar together on either side. */
.message-history .message { display:flex; align-items:flex-start; gap:8px; border:0; padding:8px 0; }
.message-history .message--outgoing { flex-direction:row-reverse; }
.message-portrait { width:36px; height:36px; flex:0 0 36px; border-radius:50%; background:#e6ecde; border:1px solid var(--line); }
.message-bubble { min-width:0; max-width:78%; padding:10px 12px; border:1px solid var(--line); border-radius:4px 14px 14px; background:var(--paper); }
.message--outgoing .message-bubble { border-radius:14px 4px 14px 14px; background:rgba(62,166,109,.14); }
.message-bubble p { margin:6px 0; }
.message-history .message-bubble button { min-height:28px; padding:3px 8px; margin-top:4px; font-size:12px; }
.friend-status { width:10px; height:10px; flex:0 0 10px; box-sizing:border-box; border:2px solid #87918d; border-radius:50%; }
.friend-status.is-online { border-color:#22c55e; background:#22c55e; box-shadow:0 0 6px rgba(34,197,94,.5); }

#universe-button{font:inherit;font-size:12px;color:inherit;background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.25);border-radius:7px;padding:3px 8px;cursor:pointer;white-space:nowrap}

.topbar .place { display:flex; flex-direction:column; align-items:flex-end; min-width:0; max-width:320px; }
.place-heading { display:flex; align-items:center; gap:8px; min-width:0; max-width:100%; }
.place-heading strong { min-width:0; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.place-heading #universe-button { flex-shrink:0; }
@media(max-width:940px) {
  .topbar { display:grid; grid-template-columns:repeat(6,minmax(0,1fr)); gap:5px; padding:8px; }
  .topbar .wordmark { display:none; }
  .topbar > .icon-button { justify-self:end; }
  .place-heading { gap:6px; }
  .topbar .player-info { grid-column:1 / 3; display:flex; flex-direction:column; align-items:stretch; min-width:0; gap:3px; }
  .topbar .player-info strong { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  .topbar .player-info .hp-row { width:100%; }
  .topbar .player-info .hp-row progress { flex:1; min-width:0; width:auto; }
  .topbar .place { grid-column:3 / -1; grid-row:1; max-width:none; }
  #universe-button { font-size:11px; padding:5px 4px; }
}

/* A generous touch target with the site's red, white and black controls. */
#panel .camera-distance-slider { display:block; width:100%; height:36px; margin:4px 0 0; padding:0; border:0; background:transparent; accent-color:#e60012; cursor:pointer; }
.camera-distance-ends { display:flex; justify-content:space-between; font-size:12px; }
#panel .camera-distance-slider:focus-visible { outline:2px solid #e60012; outline-offset:3px; }

/* Fixed touch joystick: retain independent jump/attack fingers and safe-area placement. */
#move-joystick { width:112px; height:112px; position:relative; pointer-events:auto;
 touch-action:none; user-select:none; -webkit-user-select:none; border-radius:50%;
 background:radial-gradient(circle,#32323888,#19191f66); border:1px solid #ffffff70;
 box-shadow:inset 0 1px 8px #0003,0 2px 8px #0002; }
.joystick-thumb { position:absolute; width:48px; height:48px; left:calc(50% - 24px); top:calc(50% - 24px);
 border-radius:50%; background:linear-gradient(145deg,#fffffff0,#b8bbc5df); border:1px solid #fff;
 box-shadow:0 3px 9px #0005; pointer-events:none; }
#move-joystick.held .joystick-thumb { background:linear-gradient(145deg,#ff6577,#ce0022); }
.joystick-directions { position:absolute; inset:0; display:flex; align-items:center; justify-content:center;
 color:#fffc; font-size:18px; pointer-events:none; white-space:pre; }
#touch-controls > [data-control="interact"] { bottom:124px; }
@media(max-height:450px) { #move-joystick {width:96px;height:96px;} #touch-controls > [data-control="interact"] {bottom:108px;} }

.joystick-down { position:absolute; bottom:1px; left:0; width:100%; text-align:center; color:#fffc; font-size:21px; pointer-events:none; }

#move-joystick.down-holding::after { content:'按住 1 秒下降'; position:absolute; left:50%; bottom:calc(100% + 7px); transform:translateX(-50%); white-space:nowrap; background:#24242be8; color:white; border-radius:5px; padding:4px 7px; font-size:11px; pointer-events:none; }
#move-joystick.down-holding .joystick-down { color:#ff7081; }
#move-joystick.down-holding .joystick-thumb { animation:joystick-down-hold 1s linear forwards; }
@keyframes joystick-down-hold { from {box-shadow:0 0 0 0 #ff465d90;} to {box-shadow:0 0 0 12px #ff465d90;} }

/* Shop categories stay directly accessible on desktop and narrow phones. */
.shop-category-tabs { display:flex; flex-wrap:wrap; gap:8px; margin:12px 0 16px; }
.shop-category-tab { flex:1 1 64px; min-height:44px; padding:10px 12px; border:1px solid #555; border-radius:8px; background:#fff; color:#171717; font-weight:700; cursor:pointer; }
.shop-category-tab[aria-pressed="true"] { background:#ce1830; border-color:#ce1830; color:#fff; }
.shop-category-tab:focus-visible { outline:3px solid #ce1830; outline-offset:3px; }

.list-row { position:relative; }
.dispose-progress { position:absolute; left:12px; top:12px; width:42px; height:42px; border:3px solid #ce1830; border-right-color:transparent; border-radius:50%; color:transparent; pointer-events:none; }

.inventory-disposal-row,.inventory-disposal-row * { -webkit-touch-callout:none; -webkit-user-select:none; user-select:none; }
.inventory-disposal-row img { -webkit-user-drag:none; }
.inventory-item-more { min-width:44px; min-height:44px; flex-shrink:0; font-size:22px; }

/* Light hinoki wood, scoped to the prayer wall only. */
#panel[data-feature-view="ema"] {
 color:#493522; border:2px solid #b59062; border-radius:18px;
 background-color:#eddbb8;
 background-image:repeating-linear-gradient(2deg,transparent 0 5px,#a77b3912 6px,transparent 7px 15px),repeating-linear-gradient(178deg,transparent 0 34px,#fff5dd70 35px,transparent 37px 63px),radial-gradient(ellipse at 10% 30%,#fff7e370,transparent 70%);
 box-shadow:inset 0 0 0 5px #fff2d544,0 16px 60px #0008;
}
#panel[data-feature-view="ema"] h2,#panel[data-feature-view="ema"] h3 {color:#493522;}
#panel[data-feature-view="ema"] .ema-reader {padding:24px 18px;border:1px solid #bd9a6a;border-radius:8px;background:#fff6df80;box-shadow:0 3px 8px #62411b15;overflow-wrap:anywhere;}
#panel[data-feature-view="ema"] .ema-reader>p {font-size:20px;line-height:1.8;white-space:pre-wrap;color:#493522;}
#panel[data-feature-view="ema"] small,#panel[data-feature-view="ema"] .notice {color:#715838;}
#panel[data-feature-view="ema"] button {background:#d6b784;color:#493522;border:1px solid #a47a48;border-radius:6px;min-height:44px;box-shadow:inset 0 1px #fff3d9;}
#panel[data-feature-view="ema"] button:disabled {background:#e6d6ba;color:#9c8c77;opacity:.65;}
#panel[data-feature-view="ema"] input {background:#fff8e9;color:#493522;border:1px solid #b59062;}

#panel[data-feature-view="ema"] .ema-reader p { white-space: pre-wrap; overflow-wrap: anywhere; }
#panel[data-feature-view="ema"] textarea { box-sizing: border-box; width: 100%; min-height: 110px; padding: 12px; font: inherit; color: #493522; background: #fffaf0; border: 1px solid #b2956c; border-radius: 8px; resize: vertical; }

#panel[data-feature-view="ema"] .ema-reader > button:first-child { font-weight: 700; }

/* Collection book uses the shared red, white and black visual language. */
#panel[data-feature-view="collection"] { background:#fff; color:#171717; border-top:4px solid #cf0028; }
#panel[data-feature-view="collection"] button { background:#cf0028; color:#fff; border:0; border-radius:5px; padding:9px 12px; margin:3px 2px; }
#panel[data-feature-view="collection"] button:disabled { background:#eee; color:#666; }
#panel[data-feature-view="collection"] input { background:#fff; color:#171717; border:1px solid #aaa; }
#panel[data-feature-view="collection"] progress { width:100%; accent-color:#cf0028; }

/* Chat stays within reach; its former header slot opens agent settings. */
#chat-button { position:absolute; left:max(12px,env(safe-area-inset-left)); bottom:calc(48px + env(safe-area-inset-bottom,0px)); z-index:35; width:44px; height:44px; pointer-events:auto; touch-action:manipulation; }
#ai-agent-button { font-size:16px; font-weight:800; letter-spacing:.03em; }
@media (pointer:coarse), (max-width:760px) {
  #chat-button { left:calc(max(12px,env(safe-area-inset-left)) + var(--control-size) + 16px); bottom:calc(164px + env(safe-area-inset-bottom,0px)); }
}

.inventory-categories{display:flex;flex-wrap:nowrap;overflow-x:auto;gap:6px;-webkit-overflow-scrolling:touch}.inventory-categories .inventory-tab{flex:1 0 auto;white-space:nowrap;padding:10px 12px}

@media(pointer:coarse),(max-width:760px){
 #chat-button{left:calc(max(20px,env(safe-area-inset-left)) + (var(--control-size) - 44px)/2);bottom:calc(env(safe-area-inset-bottom,0px) + 148px + var(--control-size));}
}
@media(max-width:700px){#chat-button{left:calc(max(8px,env(safe-area-inset-left)) + (var(--control-size) - 44px)/2);}}
@media(max-height:450px) and (pointer:coarse){#chat-button{bottom:calc(env(safe-area-inset-bottom,0px) + 132px + var(--control-size));}}

/* Landscape phones: player | six actions | map/universe, all on one row. */
@media (orientation:landscape) and (max-height:500px) {
  .topbar {display:flex;flex-wrap:nowrap;align-items:center;gap:4px;padding:6px max(8px,env(safe-area-inset-right)) 6px max(8px,env(safe-area-inset-left));}
  .topbar .wordmark {display:none;}
  .topbar .player-info {order:0;flex:1 1 0;min-width:0;display:flex;flex-direction:column;align-items:stretch;gap:3px;}
  .topbar .player-info strong {font-size:12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
  .topbar .player-info .hp-row {width:100%;flex-wrap:nowrap;gap:4px;font-size:10px;}
  .topbar .player-info .hp-row progress {flex:1;min-width:0;width:0;}
  .topbar > .icon-button {order:1;flex:0 0 44px;width:44px;height:44px;min-width:44px;margin:0;padding:6px;}
  .topbar .place {order:2;display:flex;flex:1 1 0;min-width:0;max-width:none;margin:0;}
  .topbar .place-heading {width:100%;justify-content:flex-end;gap:3px;font-size:11px;}
  .topbar #universe-button {font-size:10px;padding:4px 2px;}
  .topbar #connection-state {font-size:10px;}
}

@media (orientation:landscape) and (max-height:500px) {
  .topbar {gap:clamp(8px,1.5vw,16px);}
  .topbar > .icon-button {flex:0 0 44px;}
}

/* Keep location beside health; reserve the right edge for the six actions. */
.topbar .place{margin-left:0;margin-right:auto;align-items:flex-start;}
@media (orientation:landscape) and (max-height:500px){
 .topbar .player-info{order:0;flex:.8 1 0;}
 .topbar .place{order:1;flex:1.2 1 0;margin-left:0;margin-right:0;align-items:flex-start;}
 .topbar .place-heading{justify-content:flex-start;}
 .topbar > .icon-button{order:2;}
}

/* Location/universe remains available through menus, without a header readout. */
#hud .topbar .place{display:none;}
@media (orientation:landscape) and (max-height:500px){
 .topbar .player-info{flex:1 1 0;}
}
@media(max-width:940px) and (orientation:portrait){
 #hud .topbar .player-info{grid-column:1 / -1;}
}

/* Keep health compact even when the player column absorbs spare header space. */
#hud .topbar .player-info .hp-row{width:160px;max-width:100%;flex-wrap:nowrap;}
#hud .topbar .player-info .hp-row progress{width:100px;flex:0 1 100px;min-width:0;}
#hud .topbar .player-info .hp-row span{white-space:nowrap;flex-shrink:0;}

/* Portrait phones: actions first, compact player information below on the left. */
@media(max-width:940px) and (orientation:portrait){
 #hud .topbar > .icon-button{grid-row:1;order:0;}
 #hud .topbar .player-info{grid-row:2;grid-column:1 / -1;order:1;justify-self:start;align-items:flex-start;margin-top:5px;}
}
@media(max-width:940px) and (orientation:portrait){
 #hud .topbar .player-info{justify-self:end;align-items:flex-end;text-align:right;}
}

@media(max-width:940px) and (orientation:portrait){
 #hud .topbar .world-badge{position:static;grid-column:1 / 4;grid-row:2;align-self:center;justify-self:start;order:1;margin-top:5px;padding:8px;gap:5px;max-width:100%;box-sizing:border-box;}
 #hud .topbar .world-badge .live-dot{flex-shrink:0;}
 #hud .topbar .player-info{grid-column:4 / -1;align-self:center;max-width:100%;}
}

#quick-chat-button{position:absolute;z-index:35;width:44px;height:44px;padding:3px;font-size:12px;font-weight:700;pointer-events:auto;touch-action:manipulation;}
.quick-chat-options{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px;}
.quick-chat-options button{min-height:48px;margin:0;}
@media(orientation:landscape) and (max-height:350px) and (pointer:coarse){
 #touch-controls > [data-control="interact"]{width:60px;height:60px;}
 #chat-button{width:36px;height:36px;bottom:calc(env(safe-area-inset-bottom,0px) + 184px);}
 #quick-chat-button{width:36px;height:36px;}
}

/* Jiangnan's synchronized survival clock sits below the main HUD. */
#jiangnan-clock {position:absolute;top:calc(env(safe-area-inset-top,0px) + 108px);left:50%;transform:translateX(-50%);padding:7px 14px;border-radius:9px;background:rgba(15,18,22,.7);color:#fff;font-size:14px;font-weight:600;font-variant-numeric:tabular-nums;pointer-events:none;white-space:nowrap;}
@media (orientation:portrait) and (max-width:700px){#jiangnan-clock{top:calc(env(safe-area-inset-top,0px) + 144px);}}

/* Keep settlement progress and acknowledgment above the long journey diary. */
#panel[data-feature-view="aiReport"] .agent-report-top {position:sticky;top:0;z-index:2;display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:center;gap:10px 12px;padding:12px;margin-bottom:16px;background:#202024;border:1px solid #ffffff30;border-radius:4px;box-shadow:0 4px 12px #0003;}
#panel[data-feature-view="aiReport"] .agent-report-top strong {font-size:16px;font-variant-numeric:tabular-nums;}
#panel[data-feature-view="aiReport"] .agent-report-top .panel-action {min-width:100px;max-width:170px;min-height:44px;margin:0;padding:10px 14px;line-height:1.4;}
#panel[data-feature-view="aiReport"] .agent-report-remaining {grid-column:1 / -1;margin:0;font-size:13px;line-height:1.5;color:#dedee5;}

/* Private cat conversation: fixed composer, quiet expandable spending controls. */
.agent-chat{display:flex;flex-direction:column;gap:10px;max-width:660px;margin:auto}
.agent-chat p{margin:0}.agent-chat-intro{font-weight:700;font-size:18px}
.agent-chat-meta{font-size:12px;line-height:1.6;color:#bfc0c6}
.agent-chat-log{display:flex;flex-direction:column;gap:12px;overflow:auto;min-height:170px;height:32vh;max-height:340px;padding:14px;background:#17181d;border:1px solid #41424b;border-radius:8px;overscroll-behavior:contain}
.agent-chat-message{max-width:88%;padding:10px 13px;border-radius:12px;line-height:1.65;white-space:pre-wrap;overflow-wrap:anywhere}
.agent-chat-message small{display:block;color:#c7c7cc;font-size:11px;margin-bottom:3px}
.agent-chat-message.from-cat{align-self:flex-start;background:#303139;color:#fff;border-bottom-left-radius:3px}
.agent-chat-message.from-player{align-self:flex-end;background:#a71f32;color:#fff;border-bottom-right-radius:3px}
.agent-chat-choices,.agent-chat-footer{display:flex;gap:8px;flex-wrap:wrap}
.agent-chat-choices button{padding:8px 12px;min-height:40px;width:auto;flex:none}
.agent-chat-status{font-size:12px;color:#ccc;min-height:18px}
.agent-chat-composer{display:flex;gap:8px;position:sticky;bottom:0;background:#202128;padding:6px 0;z-index:2}
.agent-chat-composer input{min-width:0;flex:1;font-size:16px;margin:0!important}.agent-chat-composer button{flex:none;width:auto;min-height:44px}
.agent-chat-confirm{background:#c92038!important;color:white!important;width:100%}
.agent-chat-confirm[hidden]{display:none!important}
.agent-chat details{border-top:1px solid #464650;padding-top:12px;font-size:13px}
.agent-chat summary{cursor:pointer;min-height:36px}.agent-chat details p{color:#bbb;margin:8px 0}
.agent-chat-footer button{flex:1}
@media(max-height:500px){.agent-chat-log{height:150px;min-height:130px}.agent-chat-meta{font-size:11px}}

.agent-chat-turn{display:flex;gap:8px;align-items:flex-start;max-width:100%}
.agent-chat-turn.from-player{justify-content:flex-end}
.agent-chat-avatar{width:40px;height:40px;flex:0 0 40px;image-rendering:pixelated;border-radius:50%;background:#44464e;border:1px solid #656773}
.agent-chat-turn .agent-chat-message{max-width:calc(100% - 48px);background:#303139;color:#fff;border-bottom-left-radius:3px}
.agent-chat-turn.from-player .agent-chat-message{background:#a71f32;border-bottom-left-radius:12px;border-bottom-right-radius:3px}
.agent-chat-remembered{font-size:12px;color:#b7d9bf;line-height:1.6}
.agent-chat-remembered:empty{display:none}
.agent-memory-card{padding:14px;margin:12px 0;border:1px solid #50515a;border-radius:8px;background:#25262c}
.agent-time-hint{display:block;margin:10px 0;line-height:1.6;font-size:12px;}
.agent-memory-save{display:block;width:100%;margin:14px 0 22px;}
.agent-memory-card details{font-size:12px;color:#ccc;margin-top:8px}
.agent-chat-footer button{min-width:100px}

/* Fit the actual visible viewport: mobile keyboards do not always resize dvh. */
#panel[data-keyboard-aware="true"],#panel[data-feature-view="aiAgent"]{
  position:fixed;inset:auto;margin:0;
  top:calc(var(--chat-viewport-top,0px) + 8px);
  left:calc(var(--chat-viewport-left,0px) + var(--chat-viewport-width,100vw) / 2);
  transform:translateX(-50%);
  width:min(700px,calc(var(--chat-viewport-width,100vw) - 16px));
  max-height:calc(var(--chat-viewport-height,100dvh) - 16px);
  padding:16px;
}
#panel[data-feature-view="aiAgent"][open]{
  display:flex;flex-direction:column;overflow:hidden;
  height:min(760px,calc(var(--chat-viewport-height,100dvh) - 16px));
}
#panel[data-feature-view="aiAgent"] .panel-heading{flex:none;margin-bottom:10px;padding-bottom:10px;}
#panel[data-feature-view="aiAgent"] #panel-content{flex:1;min-height:0;}
#panel[data-feature-view="aiAgent"] .agent-chat{height:100%;min-height:0;gap:8px;}
.agent-chat-scroll{flex:1;min-height:0;overflow:auto;overscroll-behavior:contain;display:flex;flex-direction:column;gap:10px;padding:0 2px 8px;}
.agent-chat-scroll>*{flex-shrink:0;}
.agent-chat-composer{position:relative;bottom:auto;flex:none;margin:0;padding:8px 0 0;border-top:1px solid #ffffff29;}
.agent-chat-composer button{margin:0;}
#chat-panel[data-keyboard-aware="true"]{
  top:calc(var(--chat-viewport-top,0px) + 8px);bottom:auto;
  left:calc(var(--chat-viewport-left,0px) + 8px);
  width:min(360px,calc(var(--chat-viewport-width,100vw) - 16px));
  height:min(320px,calc(var(--chat-viewport-height,100dvh) - 16px));
  max-height:calc(var(--chat-viewport-height,100dvh) - 16px);
  padding:12px;display:flex;flex-direction:column;
}
#chat-panel[data-keyboard-aware="true"][hidden]{display:none;}
#chat-panel[data-keyboard-aware="true"] .chat-heading,#chat-panel[data-keyboard-aware="true"] #chat-form{flex:none;}
#chat-panel[data-keyboard-aware="true"] #chat-messages{flex:1;min-height:0;}
/* Companion chat: quiet chrome, one conversation scroller, optional tools. */
#panel[data-feature-view="aiAgent"]{background:#f7f7f5;color:#202124;border:1px solid #dcdcd8;border-radius:16px;padding:20px;box-shadow:0 24px 90px #0007;width:min(820px,calc(var(--chat-viewport-width,100vw) - 16px));}
#panel[data-feature-view="aiAgent"] .panel-heading{border-color:#deded9;margin:0 0 4px;padding-bottom:12px;}
#panel[data-feature-view="aiAgent"] #panel-title{color:#191919;font-size:22px;letter-spacing:.02em;}
#panel[data-feature-view="aiAgent"] .panel-heading button{background:transparent;color:#333;border-color:#d8d8d3;}
#panel[data-feature-view="aiAgent"] .agent-chat{max-width:none;position:relative;gap:8px;}
.agent-chat-toolbar{display:flex;align-items:center;justify-content:space-between;gap:12px;flex:none;min-height:44px;}
.agent-chat-privacy{font-size:11px;color:#72736d;letter-spacing:.02em;}
#panel .agent-chat-menu{display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;background:#fff;color:#454541;border:1px solid #dcdcd6;border-radius:10px;font-size:13px;font-weight:600;line-height:1.2;letter-spacing:normal;min-height:44px;width:auto;padding:0 14px;margin:0;white-space:nowrap;box-shadow:none;}
#panel .agent-chat-menu:hover{background:#eeeee9;border-color:#bcbcb4;}
#panel .agent-chat-menu:focus-visible{outline:2px solid #bb1831;outline-offset:3px;}
#panel .agent-chat-menu[aria-expanded="true"]{background:#fbecef;color:#9d1630;border-color:#dcb4bd;}
#panel .agent-chat-scroll{padding:0;overflow:hidden;flex:1;min-height:0;}
#panel .agent-chat-log{flex:1;min-height:0;height:auto;max-height:none;border:0;background:transparent;padding:16px 4px;gap:18px;scrollbar-width:thin;}
#panel .agent-chat-turn .agent-chat-message{background:#fff;border:1px solid #e5e5e0;color:#252525;max-width:min(82%,560px);padding:12px 16px;box-shadow:0 2px 4px #00000003;border-radius:14px;}
#panel .agent-chat-turn.from-player .agent-chat-message{background:#bb1831;border-color:#bb1831;color:#fff;}
#panel .agent-chat-message small{color:#7c7c78;font-size:10px;margin-bottom:4px;}
#panel .agent-chat-turn.from-player small{color:#ffffffb8;}
#panel .agent-chat-avatar{background:#eaeae5;border:0;width:36px;height:36px;flex-basis:36px;}
#panel .agent-chat-status{color:#777;font-size:11px;min-height:0;flex:none;}
#panel .agent-chat-status:empty,#panel .agent-chat-remembered:empty{display:none;}
#panel .agent-chat-remembered{color:#68716a;font-size:11px;}
#panel .agent-chat-choices{flex:none;flex-wrap:nowrap;overflow-x:auto;padding:2px 0;scrollbar-width:thin;}
#panel .agent-chat-choices button{background:white;color:#444;border:1px solid #deded8;border-radius:18px;font-size:12px;margin:0;min-height:34px;white-space:nowrap;}
#panel .agent-chat-confirm{flex:none;margin:0;border:0;border-radius:10px;min-height:42px;font-size:14px;}
#panel .agent-chat-composer{background:transparent;border-top:1px solid #ddddd7;flex:none;padding-top:12px;}
#panel .agent-chat-composer input{background:white;border:1px solid #d5d5d0;color:#202124;border-radius:12px;padding:12px 14px;}
#panel .agent-chat-composer input::placeholder{color:#8a8a84;}
#panel .agent-chat-composer button{background:#bb1831;border:0;color:white;border-radius:12px;padding:10px 18px;}
#panel .agent-chat-tools{position:absolute;inset:0;z-index:5;background:#f7f7f5;overflow:auto;padding:12px;box-shadow:0 8px 20px #0001;border:1px solid #deded8;border-radius:12px;}
#panel .agent-chat-tools button{background:white;border:1px solid #d9d9d4;color:#292929;border-radius:8px;min-height:44px;}
#panel .agent-chat-tools details{border-color:#deded8;margin-top:12px;}
#panel .agent-chat-tools details p{color:#686861;font-size:12px;line-height:1.6;}
#panel .agent-chat-tools input,#panel .agent-chat-tools select{background:white;color:#222;border-color:#d9d9d4;}
#panel .agent-chat-tools .agent-chat-footer{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin:16px 0;}
#panel .agent-chat [hidden]{display:none!important;}
@media(max-width:600px),(max-height:500px){
 #panel[data-feature-view="aiAgent"]{padding:12px;border-radius:12px;}
 #panel[data-feature-view="aiAgent"] #panel-title{font-size:18px;}
 #panel .agent-chat-log{padding:8px 0;gap:12px;}
 #panel .agent-chat-turn .agent-chat-message{padding:9px 12px;font-size:14px;}
 #panel .agent-chat-composer{padding-top:8px;}
}
@media(max-height:400px){#panel .agent-chat-toolbar{min-height:24px;}#panel .agent-chat-menu{min-height:44px;}#panel .agent-chat-status{display:none;}#panel[data-feature-view="aiAgent"] .panel-heading{padding-bottom:4px;}}

#panel .agent-chat-actions{display:flex;flex-direction:column;gap:8px;flex:none;}
#panel .agent-chat.has-proposal .agent-chat-actions{flex-direction:row;align-items:center;}
#panel .agent-chat.has-proposal .agent-chat-confirm{width:auto;flex:1;min-width:0;}
#panel .agent-chat.has-proposal .agent-chat-status{display:none;}
#panel .agent-chat.has-proposal .agent-chat-choices button{min-height:42px;border-radius:10px;}

/* Keep the agent settings beside Close, with a consistent vector gear. */
#panel[data-feature-view="aiAgent"] .panel-heading #panel-title{flex:1;min-width:0;}
#panel[data-feature-view="aiAgent"] .panel-heading .agent-chat-menu{flex:0 0 44px;width:44px;height:44px;padding:10px;margin:0 8px 0 12px;border:1px solid #d8d8d3;border-radius:10px;}
#panel .agent-chat-menu svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:1.6;stroke-linejoin:round;}
#panel .agent-chat-toolbar{min-height:0;}
#panel .agent-chat-privacy{display:block;line-height:1.65;overflow-wrap:anywhere;}

#panel .ai-chat-sound-control{display:flex;align-items:center;gap:8px;min-height:44px;flex:none;font-size:13px;color:#444;cursor:pointer;}
#panel .ai-chat-sound-control input{width:18px;height:18px;margin:0;accent-color:#bb1831;flex:none;}
#panel .ai-chat-sound-control small{font-size:11px;color:#777;}

/* Language selection uses native controls and remains usable on narrow screens. */
.language-setting{display:flex;align-items:center;justify-content:space-between;gap:12px;margin:8px 0 16px;flex-wrap:wrap}
.language-setting select{font:inherit;padding:8px 12px;max-width:100%;min-height:44px;border:1px solid #aaa;border-radius:8px;background:#fff;color:#18252c}
html:not([lang="zh-Hant"]) .skill-bar button{font-size:11px;overflow-wrap:anywhere}
html:not([lang="zh-Hant"]) .panel-action{white-space:normal;overflow-wrap:anywhere;height:auto;min-height:44px}

/* Korean copy wraps at word boundaries; long identifiers may still wrap. */
html[lang="ko"] body{word-break:keep-all;overflow-wrap:break-word}
