/* Touch-only operation surface. Existing paper / sage / rust remain the palette. */
html:not([data-controls="touch"]) #touch-menu-toggle {
  display: none;
}
html[data-controls="touch"] [hidden] {
  display: none !important;
}
html[data-controls="touch"] #world {
  touch-action: none;
}
html[data-controls="touch"] #touch-controls {
  position: fixed;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}
html[data-controls="touch"] #touch-stick {
  position: absolute;
  left: calc(16px + env(safe-area-inset-left, 0px));
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  width: 144px;
  height: 144px;
  border-radius: 50%;
  border: 1px solid #f6f1e4b0;
  background: #273c354d;
  box-shadow: inset 0 0 0 10px #f6f1e414;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
html[data-controls="touch"] #touch-knob {
  position: absolute;
  left: calc(50% - 26px);
  top: calc(50% - 26px);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #f6f1e4e8;
  border: 2px solid #6b8066;
  box-shadow: 0 3px 8px #14271b40;
  transform: translate(0px, 0px);
  pointer-events: none;
}
html[data-controls="touch"] .touch-stick-caption {
  position: absolute;
  left: 0;
  right: 0;
  top: -23px;
  text-align: center;
  font-size: 11px;
  color: #fff9e9;
  text-shadow: 0 1px 3px #273c35;
  pointer-events: none;
}
html[data-controls="touch"] .touch-actions {
  position: absolute;
  right: calc(16px + env(safe-area-inset-right, 0px));
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  display: grid;
  grid-template-columns: 56px 64px;
  grid-template-rows: 56px 64px;
  gap: 10px;
  align-items: center;
  pointer-events: auto;
}
html[data-controls="touch"] .touch-actions button {
  min-width: 48px;
  min-height: 48px;
  width: 100%;
  height: 100%;
  padding: 0;
  border-radius: 50%;
  border: 1px solid #f6f1e4c0;
  background: #f6f1e4e8;
  font-size: 13px;
  font-weight: 600;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
html[data-controls="touch"] #touch-jump {
  grid-column: 1;
  grid-row: 1;
}
html[data-controls="touch"] #touch-interact {
  grid-column: 1;
  grid-row: 2;
  height: 56px;
}
html[data-controls="touch"] #touch-attack {
  grid-column: 2;
  grid-row: 2;
  color: var(--paper);
  background: #914b35ed;
  border-color: #e4bea0;
}
html[data-controls="touch"] .touch-actions button:active,
html[data-controls="touch"] .touch-actions button.is-pressed {
  box-shadow: inset 0 0 0 3px #273c3580;
  filter: brightness(.9);
}
html[data-controls="touch"] #touch-look-hint {
  position: absolute;
  bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 24px);
  font-size: 10px;
  color: #fff9e9;
  text-shadow: 0 1px 3px #273c35;
  text-align: center;
}

/* Native scrolling stays enabled in all forms; only game pads capture gestures. */
html[data-controls="touch"] {
  --touch-left: calc(12px + env(safe-area-inset-left, 0px));
  --touch-right: calc(12px + env(safe-area-inset-right, 0px));
  --touch-top: calc(8px + env(safe-area-inset-top, 0px));
}
html[data-controls="touch"] button {
  min-width: 44px;
  min-height: 44px;
  touch-action: manipulation;
}
html[data-controls="touch"] input,
html[data-controls="touch"] select,
html[data-controls="touch"] textarea,
html[data-controls="touch"] #chat-input {
  font-size: 16px;
  min-height: 44px;
  max-width: 100%;
}
html[data-controls="touch"] .scrim {
  padding: calc(12px + env(safe-area-inset-top, 0px)) var(--touch-right) calc(12px + env(safe-area-inset-bottom, 0px)) var(--touch-left);
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
html[data-controls="touch"] #start {
  justify-items: center;
  align-items: start;
  padding-left: var(--touch-left);
  background: #e9e6d8e8;
}
html[data-controls="touch"] .start-panel,
html[data-controls="touch"] .dialog {
  width: min(510px, 100%);
  min-width: 0;
  max-height: calc(100vh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 20px;
  scroll-padding-block: 16px;
}
html[data-controls="touch"] .edition {
  display: none;
}
html[data-controls="touch"] .start-panel h1 {
  font-size: 52px;
  margin: 10px 0;
}
html[data-controls="touch"] .intro {
  margin: 10px 0 14px;
}
html[data-controls="touch"] .start-controls {
  grid-template-columns: 1fr;
}
html[data-controls="touch"] .skin-card {
  min-height: 48px;
  padding-right: 20px;
}
html[data-controls="touch"] .skin-option input {
  min-height: 0;
}
html[data-controls="touch"] .dialog-head button {
  flex: none;
}
html[data-controls="touch"] .dialog li {
  flex-wrap: wrap;
}
html[data-controls="touch"] #top {
  top: var(--touch-top);
  left: var(--touch-left);
  right: var(--touch-right);
  height: 36px;
  padding-right: 112px;
}
html[data-controls="touch"] .brand {
  gap: 7px;
}
html[data-controls="touch"] .seal {
  width: 28px;
  height: 32px;
  font-size: 23px;
  border-radius: 8px 2px 8px 2px;
}
html[data-controls="touch"] .brand strong {
  font-size: 17px;
  letter-spacing: 2px;
}
html[data-controls="touch"] .brand div > span {
  display: none;
}
html[data-controls="touch"] .session {
  font-size: 10px;
}
html[data-controls="touch"] .session small {
  margin-top: 2px;
  font-size: 9px;
}
html[data-controls="touch"] #compass {
  top: 2px;
  padding: 8px;
  font-size: 10px;
  letter-spacing: 2px;
}
html[data-controls="touch"] #zone-label {
  left: var(--touch-left);
  top: calc(52px + env(safe-area-inset-top, 0px));
  max-width: calc(100% - 120px);
}
html[data-controls="touch"] #zone-label > span {
  display: none;
}
html[data-controls="touch"] #zone-label b {
  margin-top: 0;
  font-size: 13px;
  line-height: 24px;
}
html[data-controls="touch"] #status {
  left: var(--touch-left);
  top: calc(86px + env(safe-area-inset-top, 0px));
  bottom: auto;
  width: 220px;
  max-width: calc(100% - 116px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  padding: 9px 11px;
  pointer-events: none;
}
html[data-controls="touch"] .identity {
  font-size: 12px;
  margin-bottom: 5px;
  gap: 8px;
}
html[data-controls="touch"] #player-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
html[data-controls="touch"] .identity > b {
  font-size: 15px;
  white-space: nowrap;
}
html[data-controls="touch"] .meter {
  margin: 5px 0;
  gap: 6px;
}
html[data-controls="touch"] .meter progress {
  min-width: 0;
  width: 60px;
}
html[data-controls="touch"] #debt {
  margin-top: 6px;
  padding-top: 5px;
}
html[data-controls="touch"] #quest-track,
html[data-controls="touch"] #adventure-track {
  display: none;
}
html[data-controls="touch"] #map-wrap {
  top: calc(62px + env(safe-area-inset-top, 0px));
  right: var(--touch-right);
}
html[data-controls="touch"] #minimap {
  width: 88px;
  height: 88px;
  border-width: 3px;
}
html[data-controls="touch"] #map-wrap > span {
  display: none;
}
html[data-controls="touch"] #touch-menu-toggle,
html[data-controls="touch"] #chat-toggle {
  position: fixed;
  top: var(--touch-top);
  right: var(--touch-right);
  z-index: 8;
  min-width: 48px;
  min-height: 44px;
  padding: 8px;
  margin: 0;
  font-size: 12px;
  background: #f6f1e4ed;
  border: 1px solid #b5bca9;
  pointer-events: auto;
}
html[data-controls="touch"] #chat-toggle {
  right: calc(68px + env(safe-area-inset-right, 0px));
}
html[data-controls="touch"] #tools {
  display: none;
  z-index: 9;
  top: calc(60px + env(safe-area-inset-top, 0px));
  right: var(--touch-right);
  bottom: auto;
  width: min(230px, calc(100% - 24px));
  max-height: calc(100vh - 250px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  max-height: calc(100dvh - 250px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px;
  gap: 5px;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: 0 5px 20px #273c3526;
}
html[data-controls="touch"] #tools.touch-menu-open {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
html[data-controls="touch"] #tools button {
  font-size: 12px;
  padding: 8px 6px;
  text-align: left;
  background: #e8e8d8;
}
html[data-controls="touch"] #tools kbd,
html[data-controls="touch"] #chat-toggle kbd,
html[data-controls="touch"] #hints > span {
  display: none;
}
html[data-controls="touch"] #hints {
  inset: auto;
  width: 0;
  height: 0;
  pointer-events: none;
}
html[data-controls="touch"] #chat {
  right: var(--touch-right);
  top: calc(166px + env(safe-area-inset-top, 0px));
  bottom: auto;
  width: min(300px, calc(100% - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
  max-height: calc(100dvh - 190px);
  z-index: 10;
}
html[data-controls="touch"] #chat-log {
  max-height: 64px;
  overflow-y: auto;
  pointer-events: auto;
  font-size: 10px;
}
html[data-controls="touch"] #chat:has(#chat-form:not([hidden])) {
  top: auto;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--paper);
  padding: 8px;
}
html[data-controls="touch"] #chat-form {
  margin-top: 5px;
}
html[data-controls="touch"] #prompt {
  bottom: calc(190px + env(safe-area-inset-bottom, 0px));
  max-width: calc(100% - 24px);
  white-space: normal;
  padding: 7px 10px;
  gap: 8px;
  font-size: 12px;
}
html[data-controls="touch"] #nearby-action {
  flex: none;
  max-width: 50%;
  padding: 7px 9px;
  font-size: 12px;
}
html[data-controls="touch"] #toast {
  top: calc(210px + env(safe-area-inset-top, 0px));
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  font-size: 12px;
  pointer-events: none;
}
html[data-controls="touch"] #duel-hud {
  top: calc(210px + env(safe-area-inset-top, 0px));
  max-width: calc(100% - 32px);
  padding: 8px 12px;
  font-size: 12px;
  pointer-events: none;
}
html[data-controls="touch"] body:has(#start:not([hidden])) #touch-menu-toggle,
html[data-controls="touch"] body:has(.scrim:not([hidden])) #touch-controls {
  visibility: hidden;
}
@media (max-width: 600px) {
  html[data-controls="touch"] .session,
  html[data-controls="touch"] #compass {
    display: none;
  }
  html[data-controls="touch"] #status {
    width: 204px;
  }
  html[data-controls="touch"] #debt {
    display: none;
  }
  html[data-controls="touch"] .start-panel,
  html[data-controls="touch"] .dialog {
    padding: 16px;
  }
  html[data-controls="touch"] #skin-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-height: 500px) {
  html[data-controls="touch"] #touch-stick {
    width: 112px;
    height: 112px;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }
  html[data-controls="touch"] .touch-actions {
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    grid-template-columns: 48px 56px;
    grid-template-rows: 48px 56px;
    gap: 8px;
  }
  html[data-controls="touch"] #touch-interact {
    height: 48px;
  }
  html[data-controls="touch"] #touch-look-hint,
  html[data-controls="touch"] .touch-stick-caption,
  html[data-controls="touch"] .session,
  html[data-controls="touch"] #compass,
  html[data-controls="touch"] #debt {
    display: none;
  }
  html[data-controls="touch"] #top {
    height: 30px;
  }
  html[data-controls="touch"] #zone-label {
    top: calc(42px + env(safe-area-inset-top, 0px));
  }
  html[data-controls="touch"] #status {
    top: calc(70px + env(safe-area-inset-top, 0px));
    width: 185px;
    padding: 6px 8px;
  }
  html[data-controls="touch"] #map-wrap {
    top: calc(56px + env(safe-area-inset-top, 0px));
  }
  html[data-controls="touch"] #minimap {
    width: 56px;
    height: 56px;
  }
  html[data-controls="touch"] #tools {
    max-height: calc(100vh - 210px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    max-height: calc(100dvh - 210px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }
  html[data-controls="touch"] #prompt {
    top: calc(106px + env(safe-area-inset-top, 0px));
    bottom: auto;
    left: 55%;
    max-width: 220px;
  }
  html[data-controls="touch"] #chat {
    top: calc(126px + env(safe-area-inset-top, 0px));
    width: 220px;
  }
  html[data-controls="touch"] #chat-log {
    max-height: 36px;
  }
  html[data-controls="touch"] #toast,
  html[data-controls="touch"] #duel-hud {
    top: calc(54px + env(safe-area-inset-top, 0px));
    max-width: calc(100% - 250px);
  }
}
