body {
  padding: 0;
  margin: 0;
  background-color: #000;
}

.canvas {
  image-rendering: pixelated;
  font-smooth: never;
  -webkit-font-smoothing: none;
}

#canvas {
  background-color: #000;
  image-rendering: pixelated;
  position: absolute;
  top: 0;
  left: 0;
}

#chat-input {
  position: absolute;
  bottom: 0;
  left: 20px;
  width: 50%;
  height: 40px;
  background: transparent;
  border: none;
  color: white;
}

.loot-window {
  position: absolute;
  z-index: 20;
  margin: 20px;
  width: 200px;
  background: #2b2b2b;
  border: 2px solid #b79460;
  border-radius: 8px;
  padding: 10px;
  color: #ffffff;
  font-family: Arial, sans-serif;
  box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.5);
}

.item-tooltip {
  position: relative;
  /* left: 0; */
  /* top: 0; */
  z-index: 10;
}

.loot-title {
  margin: 0;
  font-size: 1.2em;
  color: #f8c555;
  text-align: center;
  border-bottom: 1px solid #b79460;
  padding-bottom: 5px;
}

.loot-list {
  list-style: none;
  padding: 0;
  margin: 10px 0;
}

.loot-item {
  display: flex;
  align-items: center;
  font-size: 1em;
  padding: 4px 0;
}

.loot-icon {
  margin-right: 8px;
}

.close-button {
  width: 100%;
  padding: 5px 0;
  border: none;
  background: #b79460;
  color: #2b2b2b;
  border-radius: 4px;
  cursor: pointer;
}

.close-button:hover {
  background: #f8c555;
}

.tooltip {
  position: absolute;
  right: 0px;
  top: 0px;
  background: rgba(43, 43, 43, 0.8);
  color: #ffffff;
  border: 1px solid #b79460;
  padding: 10px;
  border-radius: 4px;
  box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  z-index: 10;
}

.tooltip-name {
  font-size: 1em;
  font-weight: bold;
  margin: 0 0 4px;
}

.tooltip-line {
  display: flex;
  justify-content: space-between;
}

.tooltip-description {
  font-size: 0.9em;
  margin: 0;
}

.inventory {
  display: grid;
  grid-template-columns: repeat(4, 40px); /* Adjust 40px for slot size */
  grid-template-rows: repeat(4, 40px);
  gap: 2px;
  background-color: rgba(64, 64, 64, 0.5);
  padding: 5px;
  position: absolute;
  bottom: 10px; /* Distance from bottom edge */
  right: 10px; /* Distance from right edge */
  border: 2px solid #222; /* Optional border */
  border-radius: 8px; /* Rounded corners for styling */
}

.slot {
  width: 40px;
  height: 40px;
  background-color: rgba(128, 128, 128, 0.5);
  border: 1px solid #222;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  cursor: pointer;
}

.chat-log {
  position: absolute;
  bottom: 44px;
  left: 20px;
  width: 40%;
  max-height: 160px;
  overflow-y: auto;
  font-family: "Pixelify Sans", sans-serif;
  font-size: 14px;
  text-shadow: 1px 1px 0 #000;
  pointer-events: none;
}

.status-panel {
  position: absolute;
  top: 10px;
  right: 10px;
  font-family: "Pixelify Sans", sans-serif;
  font-size: 14px;
  color: #fff;
  text-align: right;
  text-shadow: 1px 1px 0 #000;
  pointer-events: none;
}

.logout-button {
  margin: 4px 0 2px auto;
  display: block;
  padding: 2px 10px;
  border: 1px solid #000;
  border-radius: 4px;
  background: #b79460;
  color: #2b2b2b;
  font-family: "Pixelify Sans", sans-serif;
  font-size: 12px;
  cursor: pointer;
  pointer-events: auto;
}

.logout-button:hover {
  background: #f8c555;
}

.combat-badge {
  color: #f80;
  font-weight: bold;
}

.quest-line {
  color: #ff0;
}

.quest-window {
  top: 20%;
  left: calc(50% - 130px);
  width: 240px;
}

.quest-option {
  cursor: pointer;
  color: #f8c555;
}

.quest-title {
  font-weight: bold;
  margin: 8px 0 4px;
}

.quest-text {
  font-size: 0.9em;
  margin: 0 0 10px;
}

.quest-button {
  margin-top: 4px;
}

.xp-bar {
  width: 160px;
  height: 8px;
  margin: 2px 0 2px auto;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid #000;
}

.xp-fill {
  height: 100%;
  background: #a6f;
}

.xp-text {
  font-size: 11px;
  color: #c8f;
}

.frames-top {
  position: absolute;
  top: 10px;
  left: 140px;
  display: flex;
  gap: 8px;
}

.party-frames {
  position: absolute;
  top: 70px;
  left: 140px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.unit-frame {
  width: 160px;
  padding: 4px 6px;
  background: rgba(20, 20, 20, 0.8);
  border: 2px solid #555;
  border-radius: 4px;
  font-family: "Pixelify Sans", sans-serif;
  font-size: 13px;
  color: #fff;
  cursor: pointer;
  user-select: none;
}

.unit-frame.selected {
  border-color: #f8c555;
}

.unit-header {
  display: flex;
  justify-content: space-between;
}

.unit-level {
  color: #f8c555;
}

.unit-hp {
  position: relative;
  height: 12px;
  margin-top: 3px;
  background: #300;
  border: 1px solid #000;
}

.unit-hp-fill {
  height: 100%;
  background: #2c2;
}

.unit-hp.grey {
  border-color: #aaa;
}

.unit-hp.grey .unit-hp-fill {
  background: #999;
}

.unit-hp-text {
  position: absolute;
  top: -2px;
  width: 100%;
  text-align: center;
  font-size: 11px;
  text-shadow: 1px 1px 0 #000;
}

.invite-dialog {
  top: 30%;
  left: calc(50% - 120px);
  width: 220px;
}

/* Login */

.login-screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #1c1a2e 0%, #050507 80%);
  font-family: "Pixelify Sans", sans-serif;
  color: #fff;
}

.login-panel {
  width: 560px;
  padding: 24px 28px;
  background: rgba(20, 20, 24, 0.92);
  border: 2px solid #b79460;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.7);
}

.login-title {
  margin: 0 0 16px;
  text-align: center;
  color: #f8c555;
  font-size: 28px;
  letter-spacing: 1px;
}

.login-label {
  display: block;
  margin-bottom: 10px;
  font-size: 14px;
  color: #ccc;
}

.login-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-top: 4px;
  padding: 8px;
  background: #0d0d10;
  border: 1px solid #555;
  border-radius: 4px;
  color: #fff;
  font-family: inherit;
  font-size: 16px;
}

.login-input:focus {
  outline: none;
  border-color: #f8c555;
}

.class-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 14px 0;
}

.class-card {
  padding: 10px 12px;
  background: #15151a;
  border: 2px solid #444;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
}

.class-card:hover {
  border-color: #888;
}

.class-card.selected {
  border-color: var(--class-color);
  background: #1e1e26;
  box-shadow: 0 0 10px color-mix(in srgb, var(--class-color) 45%, transparent);
}

.class-name {
  color: var(--class-color);
  font-size: 18px;
  margin-bottom: 4px;
}

.class-role {
  font-size: 12px;
  color: #bbb;
  line-height: 1.3;
}

.login-error {
  color: #f66;
  margin-bottom: 8px;
  font-size: 13px;
}

.login-button {
  font-family: inherit;
  font-size: 16px;
  padding: 8px 0;
}

.login-hint {
  margin-top: 8px;
  text-align: center;
  font-size: 11px;
  color: #777;
}

/* Action bar */

.action-bar-wrap {
  position: absolute;
  bottom: 56px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-family: "Pixelify Sans", sans-serif;
}

.action-bar {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(20, 20, 20, 0.8);
  border: 2px solid #555;
  border-radius: 6px;
}

.action-slot {
  position: relative;
  width: 44px;
  height: 44px;
  background: #222;
  border: 1px solid #666;
  border-radius: 4px;
  overflow: visible;
  color: #fff;
  font-size: 12px;
}

.action-slot.dim {
  filter: grayscale(0.8) brightness(0.55);
}

.action-slot.far .slot-key {
  color: #f55;
}

.slot-icon {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  border-radius: 3px;
}

.slot-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #3a3a4a, #1a1a22);
  color: #f8c555;
  font-size: 14px;
  letter-spacing: 1px;
}

.slot-key {
  position: absolute;
  top: 1px;
  left: 3px;
  font-size: 11px;
  color: #ddd;
  text-shadow: 1px 1px 0 #000;
}

.slot-sweep {
  position: absolute;
  inset: 0;
  border-radius: 3px;
  pointer-events: none;
}

.slot-timer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
  pointer-events: none;
}

.slot-tooltip {
  display: none;
  position: absolute;
  bottom: 52px;
  left: 50%;
  transform: translateX(-50%);
  width: 200px;
  padding: 8px;
  background: rgba(20, 20, 20, 0.95);
  border: 1px solid #b79460;
  border-radius: 4px;
  font-size: 12px;
  z-index: 10;
  text-align: left;
}

.slot-tooltip .tooltip-line {
  color: #aaa;
  font-size: 11px;
}

.action-slot:hover .slot-tooltip {
  display: block;
}

/* Cast bars and auras */

.cast-bar {
  position: relative;
  height: 10px;
  margin-top: 3px;
  background: #222;
  border: 1px solid #000;
}

.self-cast {
  width: 240px;
  height: 16px;
}

.cast-fill {
  height: 100%;
  background: #f8c555;
}

.cast-text {
  position: absolute;
  top: -2px;
  width: 100%;
  text-align: center;
  font-size: 11px;
  text-shadow: 1px 1px 0 #000;
  color: #fff;
}

.self-cast .cast-text {
  top: 1px;
  font-size: 12px;
}

.aura-row {
  display: flex;
  gap: 2px;
  margin-top: 3px;
  flex-wrap: wrap;
}

.aura {
  position: relative;
  width: 24px;
  height: 24px;
  border: 1px solid #4c4;
  background: #111;
  font-size: 9px;
}

.aura.harmful {
  border-color: #c33;
}

.aura-icon {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.aura-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: #f8c555;
}

.aura-time {
  position: absolute;
  bottom: -1px;
  right: 0;
  font-size: 9px;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
}

#instance-banner {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  font-family: "Pixelify Sans", sans-serif;
  font-size: 48px;
  color: #f8c555;
  text-shadow: 0 0 12px rgba(0, 0, 0, 0.9), 2px 2px 0 #000;
  letter-spacing: 2px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
}

#instance-banner.show {
  animation: instance-banner 3s ease-out forwards;
}

@keyframes instance-banner {
  0% {
    opacity: 0;
    transform: translateX(-50%) scale(0.9);
  }
  12% {
    opacity: 1;
    transform: translateX(-50%) scale(1);
  }
  65% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

#lobby-help {
  position: absolute;
  top: 120px;
  right: 20px;
  width: 280px;
  padding: 10px 14px;
  background: rgba(43, 43, 43, 0.9);
  border: 2px solid #b79460;
  border-radius: 8px;
  color: #fff;
  font-family: "Pixelify Sans", sans-serif;
  font-size: 14px;
  box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.5);
}

#lobby-help[hidden] {
  display: none;
}

#lobby-help h3 {
  margin: 0 0 6px;
  color: #f8c555;
  font-weight: normal;
}

#lobby-help ul {
  margin: 0;
  padding-left: 18px;
}

#lobby-help li {
  margin: 4px 0;
}

#lobby-help .guardian {
  color: #c79c6e;
}

#lobby-help .ranger {
  color: #abd473;
}

#lobby-help .rogue {
  color: #fff569;
}

.lobby-help-close {
  position: absolute;
  top: 4px;
  right: 6px;
  border: none;
  background: none;
  color: #b79460;
  font-size: 20px;
  cursor: pointer;
}

.lobby-help-close:hover {
  color: #f8c555;
}

/* Items: icons, tooltips, bag and character sheet */

.item-slot {
  position: relative;
  padding: 0;
  overflow: visible;
}

.item-slot.filled {
  cursor: grab;
}

.item-icon {
  image-rendering: pixelated;
  border: 1px solid #888;
  border-radius: 3px;
  box-sizing: border-box;
  display: block;
  pointer-events: none;
}

.item-tooltip-anchor {
  display: none;
  position: absolute;
  z-index: 20;
  pointer-events: none;
}

.item-slot:hover .item-tooltip-anchor {
  display: block;
}

.bag-slot .item-tooltip-anchor {
  right: 46px;
  bottom: 0;
}

.gear-slot .item-tooltip-anchor {
  left: 50px;
  top: 0;
}

.item-tooltip-box {
  pointer-events: none;
  width: 190px;
  padding: 8px;
  background: rgba(20, 20, 20, 0.95);
  border: 1px solid #b79460;
  border-radius: 4px;
  color: #fff;
  font-family: "Pixelify Sans", sans-serif;
  font-size: 13px;
  text-align: left;
  white-space: nowrap;
}

.item-tooltip-box .tooltip-line {
  color: #aaa;
  font-size: 12px;
}

.tooltip-stat {
  font-size: 12px;
}

.tooltip-bonus {
  color: #1eff00;
}

.tooltip-classes {
  margin-top: 4px;
  font-size: 11px;
  color: #ccc;
}

.tooltip-classes.unusable {
  color: #f55;
}

.tooltip-level {
  font-size: 11px;
  color: #ff0;
}

.slot-label {
  font-family: "Pixelify Sans", sans-serif;
  font-size: 9px;
  color: #777;
  text-align: center;
  line-height: 1;
}

.loot-icon .item-icon {
  display: inline-block;
}

.loot-tooltip {
  position: absolute;
  right: 100%;
  top: 0;
  margin-right: 8px;
  pointer-events: none;
}

.loot-empty {
  color: #888;
  font-size: 0.9em;
}

.character-sheet {
  position: absolute;
  top: 70px;
  left: 20px;
  width: 320px;
  background: rgba(24, 22, 26, 0.96);
  border: 2px solid #b79460;
  border-radius: 8px;
  padding: 10px;
  color: #fff;
  font-family: "Pixelify Sans", sans-serif;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
  z-index: 15;
}

.character-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  border-bottom: 1px solid #b79460;
  padding-bottom: 6px;
  margin-bottom: 8px;
}

.character-name {
  font-size: 18px;
  font-weight: bold;
}

.character-sub {
  color: #aaa;
  font-size: 12px;
  flex: 1;
}

.sheet-close {
  background: none;
  border: none;
  color: #b79460;
  font-size: 18px;
  cursor: pointer;
}

.paper-doll {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.doll-column {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.gear-slot {
  width: 44px;
  height: 44px;
  background: rgba(60, 56, 64, 0.8);
  border: 1px solid #555;
  border-radius: 4px;
}

.gear-slot.filled {
  border-color: #888;
}

.doll-portrait {
  width: 156px;
  height: 156px;
  background-repeat: no-repeat;
  background-size: 624px 312px;
  background-position: 0 0;
  image-rendering: pixelated;
}

.stats-panel {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #555;
  font-size: 13px;
}

.stats-column {
  flex: 1;
}

.stat-line {
  display: flex;
  justify-content: space-between;
  padding: 1px 0;
}

.stat-name {
  color: #aaa;
}

.stat-value {
  color: #fff;
}

.sheet-hint {
  margin-top: 8px;
  font-size: 10px;
  color: #777;
}

.sheet-button {
  margin-top: 4px;
}

/* Touch: phones get thumb controls (touch.js) and a compact HUD. Every rule below is scoped to
   html.touch, which main.js sets, so the desktop layout never sees them. */

html.touch {
  --edge-top: max(env(safe-area-inset-top), 6px);
  --edge-right: max(env(safe-area-inset-right), 8px);
  --edge-bottom: max(env(safe-area-inset-bottom), 8px);
  --edge-left: max(env(safe-area-inset-left), 8px);
  --button: 50px;
  --gap: 6px;
  --controls-height: calc(2 * var(--button) + var(--gap));
  height: 100%;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

html.touch body {
  position: fixed;
  inset: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

html.touch input {
  -webkit-user-select: text;
  user-select: text;
}

.touch-button {
  min-width: 44px;
  height: 40px;
  padding: 0 8px;
  background: rgba(20, 20, 20, 0.7);
  border: 1px solid #b79460;
  border-radius: 8px;
  color: #f8c555;
  font-family: "Pixelify Sans", sans-serif;
  font-size: 13px;
  line-height: 1.1;
  touch-action: manipulation;
}

.touch-button:active {
  background: rgba(183, 148, 96, 0.6);
}

.touch-button.dim {
  opacity: 0.5;
}

/* Login fits a phone with the keyboard up: the screen scrolls instead of clipping the panel. */

html.touch .login-screen {
  position: fixed;
  overflow-y: auto;
  touch-action: pan-y;
  align-items: flex-start;
  padding: var(--edge-top) var(--edge-right) var(--edge-bottom) var(--edge-left);
  box-sizing: border-box;
}

html.touch .login-panel {
  width: 100%;
  max-width: 560px;
  margin: auto;
  padding: 14px 16px;
  box-sizing: border-box;
}

html.touch .login-title {
  font-size: 22px;
  margin-bottom: 10px;
}

html.touch .class-cards {
  margin: 8px 0 12px;
}

html.touch .class-card {
  padding: 8px;
}

html.touch .class-role {
  font-size: 11px;
}

@media (orientation: landscape) {
  html.touch .login-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 12px;
    max-width: 680px;
  }

  html.touch .login-panel > :not(.login-label) {
    grid-column: 1 / -1;
  }

  html.touch .class-cards {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Unit frames stack down the left edge: player and target, then the party. */

html.touch #frames {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  width: max-content;
  padding: var(--edge-top) 0 0 var(--edge-left);
  pointer-events: none;
}

html.touch .frames-top,
html.touch .party-frames {
  position: static;
  gap: 3px;
}

html.touch .invite-dialog {
  position: fixed;
  pointer-events: auto;
}

html.touch .unit-frame {
  width: 112px;
  padding: 2px 4px;
  border-width: 1px;
  font-size: 11px;
  pointer-events: auto;
}

html.touch .party-frames .unit-frame {
  width: 100px;
}

html.touch .party-frames .unit-level {
  display: none;
}

html.touch .unit-header {
  white-space: nowrap;
  overflow: hidden;
}

html.touch .unit-hp {
  height: 9px;
  margin-top: 2px;
}

html.touch .unit-hp-text {
  top: -2px;
  font-size: 9px;
}

html.touch .unit-frame .cast-bar {
  height: 7px;
}

html.touch .unit-frame .cast-text {
  top: -3px;
  font-size: 9px;
}

html.touch .aura {
  width: 16px;
  height: 16px;
}

html.touch .aura-time {
  font-size: 8px;
}

/* Top right: the menu buttons, then level, XP and quests. */

html.touch .touch-menu {
  position: absolute;
  top: var(--edge-top);
  right: var(--edge-right);
  display: flex;
  gap: 4px;
}

html.touch .touch-menu-list {
  position: absolute;
  top: 46px;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  z-index: 30;
}

html.touch .touch-menu-list .touch-button {
  background: rgba(20, 20, 20, 0.95);
}

html.touch .status-panel {
  top: calc(var(--edge-top) + 46px);
  right: var(--edge-right);
  max-width: 200px;
  font-size: 11px;
}

html.touch .status-panel .logout-button {
  display: none;
}

html.touch .xp-bar {
  width: 120px;
  height: 5px;
}

html.touch .xp-text {
  font-size: 9px;
}

/* Chat: a short log at the bottom, and the input at the top where the keyboard never covers it. */

html.touch .chat-log {
  left: 50%;
  bottom: var(--edge-bottom);
  transform: translateX(-50%);
  width: min(300px, 36vw);
  max-height: 58px;
  font-size: 11px;
}

html.touch.chat-hidden .chat-log {
  display: none;
}

html.touch #chat-input {
  top: var(--edge-top);
  bottom: auto;
  left: 50%;
  transform: translateX(-50%);
  width: min(480px, 70vw);
  height: 40px;
  padding: 0 10px;
  box-sizing: border-box;
  background: rgba(10, 10, 12, 0.92);
  border: 1px solid #b79460;
  border-radius: 6px;
  font-family: "Pixelify Sans", sans-serif;
  font-size: 16px;
  z-index: 50;
}

html.touch #chat-input:not(:focus) {
  opacity: 0;
  pointer-events: none;
}

/* Bottom right: the six abilities in two rows, then Next target and Attack beside them. */

html.touch .action-bar-wrap {
  display: contents;
}

html.touch .action-bar {
  position: absolute;
  right: calc(var(--edge-right) + var(--button) + var(--gap));
  bottom: var(--edge-bottom);
  display: grid;
  grid-template-columns: repeat(3, var(--button));
  gap: var(--gap);
  padding: 0;
  background: none;
  border: none;
}

html.touch .action-slot {
  width: var(--button);
  height: var(--button);
  border-radius: 10px;
  overflow: hidden;
  opacity: 0.9;
  touch-action: none;
}

html.touch .action-slot.far {
  border-color: #f55;
}

html.touch .action-slot .slot-key,
html.touch .action-slot .slot-tooltip,
html.touch .action-slot:hover .slot-tooltip {
  display: none;
}

html.touch .self-cast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--edge-bottom) + 66px);
  transform: translateX(-50%);
  width: 200px;
}

html.touch .touch-combat {
  position: absolute;
  right: var(--edge-right);
  bottom: var(--edge-bottom);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

html.touch .touch-combat .touch-button {
  width: var(--button);
  height: var(--button);
  padding: 0;
  font-size: 12px;
  touch-action: none;
}

html.touch .attack-button {
  border-color: #f66;
  color: #fbb;
}

/* Windows: centred, scrollable, with finger-sized buttons. */

html.touch .close-button {
  padding: 9px 0;
  font-size: 14px;
}

html.touch #lootWindow .loot-window {
  top: calc(var(--edge-top) + 46px) !important;
  left: 50% !important;
  right: auto !important;
  bottom: auto !important;
  transform: translateX(-50%);
  margin: 0;
}

html.touch .loot-item {
  min-height: 36px;
  cursor: pointer;
}

html.touch .loot-window {
  max-height: 80%;
  overflow-y: auto;
  touch-action: pan-y;
  box-sizing: border-box;
}

html.touch #lobby-help {
  top: calc(var(--edge-top) + 92px);
  right: var(--edge-right);
  width: 250px;
  max-height: calc(100% - var(--edge-top) - var(--edge-bottom) - var(--controls-height) - 100px);
  overflow-y: auto;
  touch-action: pan-y;
  box-sizing: border-box;
  padding: 6px 10px;
  font-size: 11px;
}

html.touch #lobby-help h3 {
  font-size: 14px;
}

html.touch .lobby-help-close {
  top: 0;
  right: 0;
  width: 40px;
  height: 40px;
  font-size: 26px;
}

html.touch #instance-banner {
  font-size: 28px;
}

/* Bag and character sheet open from the menu; items move by tap, see items.js. */

html.touch .inventory {
  display: none;
  top: calc(var(--edge-top) + 46px);
  right: var(--edge-right);
  bottom: auto;
  grid-template-columns: repeat(4, 44px);
  grid-template-rows: repeat(4, 44px);
  background: rgba(24, 22, 26, 0.96);
  border-color: #b79460;
  z-index: 16;
}

html.touch.bag-open .inventory {
  display: grid;
}

html.touch .bag-slot {
  width: 44px;
  height: 44px;
}

html.touch .item-slot.picked {
  outline: 2px solid #f8c555;
  outline-offset: -2px;
}

html.touch .item-slot:hover .item-tooltip-anchor {
  display: none;
}

html.touch .item-slot.picked .item-tooltip-anchor {
  display: block;
  position: fixed;
  top: var(--edge-top);
  left: 50%;
  right: auto;
  bottom: auto;
  transform: translateX(-50%);
  z-index: 40;
}

/* The window holding the picked item goes on top, so its fixed panel clears the other window. */
html.touch .inventory:has(.picked),
html.touch .character-sheet:has(.picked) {
  z-index: 40;
}

.picked-actions {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  pointer-events: auto;
}

.picked-actions .close-button {
  font-family: "Pixelify Sans", sans-serif;
}

html.touch .character-sheet {
  top: var(--edge-top);
  left: var(--edge-left);
  display: grid;
  grid-template-columns: auto 190px;
  column-gap: 10px;
  width: auto;
  max-height: calc(100% - var(--edge-top) - var(--edge-bottom));
  overflow-y: auto;
  touch-action: pan-y;
  box-sizing: border-box;
  padding: 8px;
  z-index: 16;
}

html.touch .character-header,
html.touch .sheet-hint {
  grid-column: 1 / -1;
}

html.touch .sheet-close {
  width: 40px;
  height: 32px;
  font-size: 24px;
}

html.touch .doll-portrait {
  width: 104px;
  height: 104px;
  background-size: 416px 208px;
}

html.touch .stats-panel {
  flex-direction: column;
  gap: 0;
  margin-top: 0;
  padding: 0 0 0 10px;
  border-top: none;
  border-left: 1px solid #555;
  font-size: 11px;
}

.rotate-hint {
  display: none;
}

/* Portrait works too, with the menu folded into two rows and windows stacked. */

@media (orientation: portrait) {
  html.touch .touch-menu {
    display: grid;
    grid-template-columns: repeat(2, auto);
  }

  html.touch .touch-menu-list {
    top: 90px;
  }

  html.touch .status-panel {
    top: calc(var(--edge-top) + 90px);
  }

  html.touch .unit-frame {
    width: 104px;
  }

  html.touch .chat-log {
    left: var(--edge-left);
    bottom: calc(var(--edge-bottom) + var(--controls-height) + 12px);
    transform: none;
    width: 70%;
  }

  html.touch .self-cast {
    bottom: calc(var(--edge-bottom) + var(--controls-height) + 76px);
  }

  html.touch #lobby-help {
    top: auto;
    bottom: calc(var(--edge-bottom) + var(--controls-height) + 74px);
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: calc(100% - 32px);
    max-height: 18%;
  }

  html.touch .inventory {
    top: auto;
    bottom: calc(var(--edge-bottom) + var(--controls-height) + 10px);
  }

  html.touch .character-sheet {
    grid-template-columns: 1fr;
    right: var(--edge-right);
  }

  html.touch .stats-panel {
    flex-direction: row;
    gap: 10px;
    margin-top: 8px;
    padding: 8px 0 0;
    border-top: 1px solid #555;
    border-left: none;
  }

  html.touch:has(.character-sheet) .inventory {
    bottom: var(--edge-bottom);
  }

  html.touch:has(.character-sheet) .action-bar,
  html.touch:has(.character-sheet) .touch-combat {
    display: none;
  }

  html.touch .rotate-hint {
    display: block;
    position: absolute;
    left: 50%;
    bottom: calc(var(--edge-bottom) + var(--controls-height) + 12px);
    transform: translateX(-50%);
    width: 70%;
    padding: 8px 10px;
    background: rgba(20, 20, 20, 0.8);
    border: 1px solid #b79460;
    border-radius: 6px;
    color: #f8c555;
    font-family: "Pixelify Sans", sans-serif;
    font-size: 13px;
    text-align: center;
  }
}
