:root {
  --bg: #110d09;
  --panel: rgba(24, 18, 13, 0.92);
  --panel-border: rgba(212, 169, 90, 0.34);
  --gold: #e5b762;
  --gold-strong: #f6cf7f;
  --crimson: #b9382c;
  --text: #f3eadc;
  --muted: #b6a692;
  --ok: #5cd084;
  --warn: #e5b762;
  --err: #ef6c5d;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#app-shell,
#unity-container,
#unity-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#unity-canvas {
  background: radial-gradient(circle at center, #211811 0%, #0e0a07 100%);
  outline: none;
}

.hidden {
  display: none !important;
}

/* Floating top bar */
#top-bar {
  position: fixed;
  top: calc(8px + var(--safe-top));
  left: calc(10px + var(--safe-left));
  right: calc(10px + var(--safe-right));
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-pill {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 7px 12px;
  min-height: 36px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(18, 14, 10, 0.84);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
}

.hud-pill svg {
  flex-shrink: 0;
  display: block;
}

.hud-pill:hover {
  border-color: var(--gold);
  background: rgba(28, 21, 15, 0.94);
}

.hud-pill:active {
  transform: scale(0.96);
}

.hud-pill[aria-pressed="true"] {
  border-color: var(--gold-strong);
  background: rgba(92, 69, 34, 0.88);
}

.icon-pill {
  padding: 7px 10px;
}

.pill-sub {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px currentColor;
}

.sync-dot.syncing {
  background: var(--warn);
  animation: pulseDot 1s infinite ease-in-out;
}

.sync-dot.offline {
  background: var(--err);
}

@keyframes pulseDot {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

/* Portrait advice */
.orientation-hint {
  position: fixed;
  bottom: calc(74px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 24;
  width: min(92vw, 420px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(26, 19, 13, 0.92);
  border: 1px solid var(--panel-border);
  font-size: 12px;
  color: var(--text);
}

.orientation-hint button {
  flex-shrink: 0;
  background: var(--gold);
  color: #16100a;
  border: none;
  border-radius: 8px;
  padding: 4px 10px;
  font-weight: 700;
  cursor: pointer;
}

/* Touch HUD Overlay */
.touch-hud {
  position: fixed;
  inset: 0;
  z-index: 15;
  pointer-events: none;
}

.stick-zone {
  position: fixed;
  left: var(--safe-left);
  bottom: var(--safe-bottom);
  width: min(44vw, 290px);
  height: min(56dvh, 290px);
  pointer-events: auto;
  touch-action: none;
}

.stick-base {
  position: absolute;
  left: 26px;
  bottom: 24px;
  width: 118px;
  height: 118px;
  border-radius: 50%;
  border: 2px solid rgba(229, 183, 98, 0.45);
  background: radial-gradient(circle, rgba(229, 183, 98, 0.14) 0%, rgba(17, 13, 9, 0.35) 70%);
  box-shadow: inset 0 0 16px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.72;
  transition: opacity 0.12s ease;
}

.stick-base.active {
  opacity: 1;
  border-color: var(--gold-strong);
}

.stick-knob {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f9dea0, #bd8a3b);
  border: 2px solid rgba(255, 245, 215, 0.75);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.55);
  transform: translate(0px, 0px);
  will-change: transform;
}

.touch-btn {
  pointer-events: auto;
  touch-action: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1.5px solid rgba(229, 183, 98, 0.52);
  background: rgba(20, 15, 11, 0.76);
  color: var(--text);
  font-weight: 700;
  line-height: 1.05;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  transition: transform 0.08s ease, background 0.1s ease, border-color 0.1s ease;
}

.touch-btn.pressed {
  transform: scale(0.91);
  background: rgba(229, 183, 98, 0.35);
  border-color: var(--gold-strong);
}

.touch-btn .btn-main {
  font-size: 13px;
}

.touch-btn .btn-sub {
  font-size: 11px;
  color: #f3eadc;
}

.touch-top-right {
  position: fixed;
  top: calc(52px + var(--safe-top));
  right: calc(12px + var(--safe-right));
  display: flex;
  gap: 8px;
}

.touch-btn.mini {
  width: 48px;
  height: 40px;
  border-radius: 12px;
  font-size: 12px;
}

.touch-btn.mini.is-on {
  border-color: var(--gold-strong);
  background: rgba(229, 183, 98, 0.3);
}

.touch-menu-bar {
  position: fixed;
  bottom: calc(14px + var(--safe-bottom));
  right: calc(14px + var(--safe-right));
  display: flex;
  gap: 8px;
}

.touch-btn.chip {
  height: 44px;
  min-width: 68px;
  padding: 0 12px;
  border-radius: 14px;
  font-size: 12px;
}

.touch-btn.chip.accent {
  background: rgba(212, 169, 90, 0.25);
  border-color: var(--gold);
}

.touch-btn.chip.danger {
  border-color: rgba(239, 108, 93, 0.55);
}

.touch-action-cluster {
  position: fixed;
  right: calc(16px + var(--safe-right));
  bottom: calc(16px + var(--safe-bottom));
  width: 214px;
  height: 214px;
  pointer-events: none;
}

.arc-primary {
  position: absolute;
  right: 2px;
  bottom: 4px;
  width: 78px;
  height: 78px;
  background: radial-gradient(circle at 35% 30%, rgba(235, 188, 102, 0.42), rgba(32, 23, 14, 0.85));
  border-width: 2px;
  border-color: var(--gold);
}

.arc-primary .btn-main {
  font-size: 16px;
}

.arc-sprint {
  position: absolute;
  right: 90px;
  bottom: 4px;
  width: 58px;
  height: 58px;
}

.arc-command {
  position: absolute;
  right: 84px;
  bottom: 74px;
  width: 62px;
  height: 62px;
}

.arc-army {
  position: absolute;
  right: 152px;
  bottom: 62px;
  width: 48px;
  height: 48px;
}

.arc-secondary {
  position: absolute;
  right: 6px;
  bottom: 94px;
  width: 54px;
  height: 54px;
}

.arc-call-night {
  position: absolute;
  right: 72px;
  bottom: 148px;
  width: 64px;
  height: 64px;
  border-color: rgba(235, 114, 72, 0.85);
  background: radial-gradient(circle, rgba(185, 56, 44, 0.55), rgba(35, 14, 11, 0.88));
  animation: nightPulse 1.8s infinite ease-in-out;
}

@keyframes nightPulse {
  0%, 100% { box-shadow: 0 0 8px rgba(235, 114, 72, 0.4); }
  50% { box-shadow: 0 0 18px rgba(245, 178, 92, 0.8); }
}

/* Loading Overlay */
#loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 35%, #2a1f15 0%, #110d09 75%);
  transition: opacity 0.35s ease;
}

#loading-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loading-card {
  width: min(92vw, 420px);
  padding: 28px 24px;
  border-radius: 18px;
  background: rgba(22, 16, 11, 0.92);
  border: 1px solid var(--panel-border);
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.65);
  text-align: center;
}

.crest {
  font-size: 38px;
  color: var(--gold);
  margin-bottom: 6px;
}

.loading-card h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0.18em;
  color: var(--gold-strong);
}

.loading-phase {
  margin: 8px 0 18px;
  color: var(--muted);
  font-size: 14px;
}

.progress-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  border: 1px solid rgba(229, 183, 98, 0.2);
}

.progress-fill {
  width: 4%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #b67d2c, #f5cd79);
  transition: width 0.2s ease;
}

.loading-meta {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}

.loading-error {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(185, 56, 44, 0.22);
  border: 1px solid rgba(239, 108, 93, 0.45);
  color: #ffd5cf;
  font-size: 13px;
  text-align: left;
  user-select: text;
  -webkit-user-select: text;
}

/* Vault Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(6, 4, 2, 0.65);
  backdrop-filter: blur(3px);
}

.profile-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 50;
  width: min(92vw, 390px);
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  background: #17110c;
  border-right: 1px solid var(--panel-border);
  box-shadow: 16px 0 42px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  user-select: text;
  -webkit-user-select: text;
  touch-action: pan-y;
}

.drawer-header {
  padding: 16px 18px 12px;
  border-bottom: 1px solid rgba(229, 183, 98, 0.16);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-header h2 {
  margin: 0;
  font-size: 18px;
  color: var(--gold-strong);
}

.drawer-subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.icon-close {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(229, 183, 98, 0.28);
  background: transparent;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
}

.drawer-body {
  padding: 14px 16px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  touch-action: pan-y;
}

.vault-card {
  padding: 14px;
  border-radius: 12px;
  background: rgba(255, 245, 225, 0.04);
  border: 1px solid rgba(229, 183, 98, 0.18);
}

.vault-card h3 {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.field-label {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
  color: var(--muted);
}

.row-gap {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.col-gap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row-gap-tight {
  margin-bottom: 0;
}

.account-box {
  margin-top: 10px;
}

.mode-pills {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 10px;
}

.mode-pill {
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid rgba(229, 183, 98, 0.28);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.mode-pill.is-active {
  background: rgba(229, 183, 98, 0.24);
  border-color: var(--gold-strong);
  color: var(--gold-strong);
}

.vault-card input[type="text"],
.vault-card input[type="password"],
.vault-card select {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(229, 183, 98, 0.28);
  background: rgba(10, 7, 5, 0.85);
  color: var(--text);
  font-size: 14px;
}

.sync-code-box {
  margin: 10px 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(229, 183, 98, 0.08);
  border: 1px dashed rgba(229, 183, 98, 0.36);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sync-code-box code {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--gold-strong);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  font-size: 13px;
}

.setting-row select {
  width: auto;
  max-width: 175px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-head h3 {
  margin: 0;
}

.status-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(92, 208, 132, 0.16);
  color: #9df0ba;
}

.btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn-gold,
.btn-ghost,
.btn-danger-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  text-align: center;
}

.btn-gold {
  background: var(--gold);
  color: #16100a;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(229, 183, 98, 0.28);
  color: var(--text);
}

.btn-danger-outline {
  background: rgba(185, 56, 44, 0.12);
  border-color: rgba(239, 108, 93, 0.42);
  color: #ffb6ac;
}

.subhead {
  margin: 14px 0 8px;
  font-size: 12px;
  color: var(--muted);
}

.backup-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 190px;
  overflow-y: auto;
}

.backup-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
}

.backup-item button {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(229, 183, 98, 0.4);
  background: transparent;
  color: var(--gold-strong);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
}

.muted {
  color: var(--muted);
  font-size: 12px;
  margin: 0;
}

@media (max-width: 540px) {
  .hide-xs {
    display: none;
  }

  .touch-action-cluster {
    transform: scale(0.92);
    transform-origin: bottom right;
  }

  .stick-base {
    width: 104px;
    height: 104px;
    left: 16px;
    bottom: 18px;
  }
}
